Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:10:26+00:00 2026-05-23T09:10:26+00:00

When parsing a freeform language like C, it is easy for the parser to

  • 0

When parsing a freeform language like C, it is easy for the parser to determine when several expressions are related to one another simply by looking at the symbols emitted by the parser. For example, in the code

if (x == 5) {
    a = b;
    c = d;
}

The parser can tell that a = b; and c = d; are part of the same block statement because they’re surrounded by braces. This could easily be encoded as a CFG using something like this:

STMT        ::=  IF_STMT | EXPR; | BLOCK_STMT | STMT STMT
IF_STMT     ::=  if ( EXPR ) STMT
BLOCK_STMT  ::=  { STMT }

In Python and other whitespace-sensitive languages, though, it’s not as easy to do this because the structure of the statements can only be inferred from their absolute position, which I don’t think can easily be encoded into a CFG. For example, the above code in Python would look like this:

if x == 5:
    a = b
    c = d

Try as I might, I can’t see a way to write a CFG that would accept this, because I can’t figure out how to encode “two statements at the same level of nesting” into a CFG.

How do Python parsers group statements as they do? Do they rely on a scanner that automatically inserts extra tokens denoting starts and ends of statements? Do they produce a rough AST for the program, then have an extra pass that assembles statements based on their indentation? Is there a clever CFG for this problem that I’m missing? Or do they use a more powerful parser than a standard LL(1) or LALR(1) parser that’s able to take whitespace level into account?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:10:26+00:00Added an answer on May 23, 2026 at 9:10 am

    The indentations are handled with two “pseudo tokens” – INDENT and DEDENT. There are some details here. For more information, you should look at the source for the python tokeniser and parser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at parsing a delimited string, something on the order of a,b,c But
Hey, folks. I'm looking for some regular expressions to help grab street addresses and
Parsing binary sums / products are easy, but I'm having troubles defining a grammar
what parsing means for web development. Things like parsing html, parsing style sheets etc
When parsing XML like below, does book.xml need to be a static file of
Parsing a text file in vb.net and need to locate the latitude and longitude
For parsing player commands, I've most often used the split method to split a
I`m parsing SQL query with C# Regex. I need also to make my pattern
I'm parsing text from a file and storing it in a string. The problem
I've been parsing through some log files and I've found that some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.