Python on Parrot Python on Parrot #51

Parsing Python's indent rules

So... what about parsing Python's "indented blocks"?

From the Language Reference Manual, here's some rules for "if" statements:

if_stmt   ::= "if" expression ":" suite
              ( "elif" expression ":" suite )*
              [ "else" ":" suite ]

statement ::= stmt_list NEWLINE
                | compound stmt

stmt_list ::= simple_stmt (";" simple_stmt)* [";"]

suite     ::= stmt_list NEWLINE
                | NEWLINE INDENT statement+ DEDENT
Copyright © 2007 Patrick Michaud