Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: python/indentation/cordy/extracted
Source used for this grammar: James R. Cordy, Program to explicate standard Python INDENT/DEDENT symbols, November 2008
program
, line
, endofline
, indent
, dedent
, tab_space
, linetoken
, nonblank_token
, compound
, compoundtoken
, compoundtokensquare
, compoundtokenround
), 1 root (program
), 0 top (—), 6 bottom (newline
4, space
, comment
4, SP
2, token
, tab
).program ::=
line
line ::= tab_spacelinetoken indent endofline dedent
endofline ::= tab_spacecomment newline
indent ::=
SP "INDENT"
dedent ::=
"DEDENT" SP
tab_space ::= tab space
linetoken ::= tab_space nonblank_token
nonblank_token ::= compound token
compound ::= "{" compoundtoken "}" "[" compoundtokensquare "]" "(" compoundtokenround ")"
compoundtoken ::= linetoken newline comment
compoundtokensquare ::= linetoken newline comment
compoundtokenround ::= linetoken newline comment