Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: python/v2.x/sorochan-cordy/extracted
Source used for this grammar: Mykhaylo Sorochan, James R. Cordy, TXL Basis Grammar for Python, Version 1.4, July 2010
program
, file_input
, stmt_or_newline
, decorator
, decorator_arglist
, decorators
, decorated
, funcdef
, parameters
, varargslist
, fpdef_test
, fpdef_test_comma
, is_test
, fpdef
, fplist
, stmt
, simple_stmt
, semicolon_small_stmt
, small_stmt
, expr_stmt
, is_expr
, augassign
, assign_value
, print_stmt
, del_stmt
, pass_stmt
, flow_stmt
, break_stmt
, continue_stmt
, return_stmt
, yield_stmt
, raise_stmt
, test_list
, comma_test
, import_stmt
, import_name
, import_from
, import_items
, import_as_name
, as_name
, dotted_as_name
, as_id
, import_as_names
, dotted_as_names
, dotted_name
, dot_dotted_name
, global_stmt
, exec_stmt
, in_test
, assert_stmt
, compound_stmt
, if_stmt
, elif_clause
, else_clause
, while_stmt
, for_stmt
, try_stmt
, finally_clause
, except_clause_suite
, with_stmt
, with_var
, except_clause
, except_test
, as_or_comma_test
, suite
, endofline
, indent
, dedent
, testplist_safe
, old_test
, old_lambdef
, test
, if_test
, or_test
, orop_or_test
, and_test
, andop_and_test
, not_test
, comparison
, comp_op_comparison
, comp_op
, expr
, orop_expr
, xor_expr
, xorop_expr
, and_expr
, andop_and_expr
, shift_expr
, shiftop_shift_expr
, shift_op
, arith_expr
, op_arith_expr
, arith_op
, term
, op_term
, term_op
, factor
, unary_op
, power
, exp_factor
, atom
, listmaker
, testplist_gexp
, lambdef
, trailer
, subscriptlist
, subscript
, sliceop
, exprlist
, testlist
, dictmaker
, dict_entry
, classdef
, arglist
, star_test
, comma_opt_star_test
, argument
, argument_value
, plist_iter
, plist_for
, plist_if
, gen_iter
, gen_for
, gen_if
, testlist1
, encoding_decl
, yield_expr
, literal
, more_stringliteral
, stringliteral
, stringprefix
, string
, integerliteral
, integer
, long
, floatliteral
, imag
), 1 root (program
), 1 top (encoding_decl
), 16 bottom (comment
2, octinteger
, SPON
11, id
16, newline
, EX
8, SPOFF
11, pointfloat
, longstringlit
, number
, integernumber
, stringlit
, longcharlit
, IN
8, hexinteger
, charlit
).program ::= file_input
file_input ::=
stmt_or_newline
stmt_or_newline ::= stmt endofline
decorator ::= "@" dotted_name decorator_arglist endofline endofline
decorator_arglist ::= SPOFF "(" SPON IN arglist endofline ")" EX
decorators ::=
decorator
decorated ::= decorators classdef decorators funcdef
funcdef ::= "def" id parameters ":" suite
parameters ::= SPOFF "(" SPON varargslist endofline ")"
varargslist ::= fpdef_test_comma"*" id fpdef_test_comma endofline "*" id endofline "," endofline "**" id fpdef_test_comma endofline "**" id fpdef_test ","endofline
fpdef_test ::= endoflinefpdef is_test endofline
fpdef_test_comma ::=
fpdef_test ","
is_test ::= "=" endofline test
fpdef ::= id endofline"(" SPON fplist endofline ")" endoflineSPOFF
fplist ::= fpdef","
stmt ::= simple_stmt endofline compound_stmt
simple_stmt ::= small_stmt semicolon_small_stmt";" comment
semicolon_small_stmt ::=
";" small_stmt
small_stmt ::= expr_stmt print_stmt del_stmt pass_stmt flow_stmt import_stmt global_stmt exec_stmt assert_stmt
expr_stmt ::=
testlist is_expr
testlist augassign assign_valueis_expr ::= "=" endofline assign_value
augassign ::= "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "**=" "//="
assign_value ::= yield_expr testlist
print_stmt ::= "print" ">>" test "," ","
del_stmt ::=
"del" exprlist
pass_stmt ::=
"pass"
flow_stmt ::= break_stmt continue_stmt return_stmt raise_stmt yield_stmt
break_stmt ::=
"break"
continue_stmt ::=
"continue"
return_stmt ::= "return" testlist
yield_stmt ::= yield_expr
raise_stmt ::= "raise" test_list
test_list ::= test comma_testcomma_test
comma_test ::= endofline"," test
import_stmt ::= import_name import_from
import_name ::=
"import" dotted_as_names
import_from ::= "from" "." dotted_name endofline "import" import_items
import_items ::= "*" endofline SPOFF "(" SPON import_as_names endofline ")" endofline import_as_names
import_as_name ::= endoflineid as_name
as_name ::=
"as" id
dotted_as_name ::=
dotted_name as_id
as_id ::=
"as" id
import_as_names ::= import_as_name","
dotted_as_names ::=
dotted_as_name
dotted_name ::=
id dot_dotted_name
dot_dotted_name ::= endofline"." endofline dotted_name
global_stmt ::= "global" id
exec_stmt ::= "exec" expr in_test comma_test
in_test ::=
"in" test
assert_stmt ::= "assert" test comma_test
compound_stmt ::= if_stmt while_stmt for_stmt try_stmt with_stmt funcdef classdef decorated
if_stmt ::= "if" test ":" suite elif_clause else_clause
elif_clause ::= "elif" test ":" suite
else_clause ::= "else" ":" suite
while_stmt ::= "while" test ":" suite else_clause
for_stmt ::= "for" exprlist "in" testlist ":" suite else_clause
try_stmt ::= "try" ":" suite except_clause_suite else_clause finally_clause
finally_clause ::= "finally" ":" suite
except_clause_suite ::=
except_clause ":" suite
with_stmt ::= "with" test with_var ":" suite
with_var ::=
"as" expr
except_clause ::= "except" except_test
except_test ::=
test as_or_comma_test
as_or_comma_test ::= "as" test "," test
suite ::=
indent endofline stmt_or_newline
dedent
simple_stmt endoflineendofline ::=
comment
newlineindent ::=
"INDENT" IN
dedent ::=
"DEDENT" EX
testplist_safe ::= old_test","
old_test ::= or_test old_lambdef
old_lambdef ::= "lambda" varargslist ":" old_test
test ::= endoflineor_test if_test endofline endofline lambdef endofline
if_test ::= endofline"if" or_test "else" test
or_test ::=
and_test orop_or_test
orop_or_test ::= endofline"or" endofline or_test
and_test ::=
not_test andop_and_test
andop_and_test ::= endofline"and" endofline and_test
not_test ::= "not" endofline comparison
comparison ::=
expr comp_op_comparison
comp_op_comparison ::= endoflinecomp_op endofline comparison
comp_op ::= "<" ">" "==" ">=" "<=" "<>" "!=" "in" "not" "in" "is" "is" "not"
expr ::=
xor_expr orop_expr
orop_expr ::= endofline"|" endofline expr
xor_expr ::=
and_expr xorop_expr
xorop_expr ::= endofline"^" endofline xor_expr
and_expr ::=
shift_expr andop_and_expr
andop_and_expr ::= endofline"&" endofline and_expr
shift_expr ::=
arith_expr shiftop_shift_expr
shiftop_shift_expr ::= endoflineshift_op endofline shift_expr
shift_op ::= "<<" ">>"
arith_expr ::=
term op_arith_expr
op_arith_expr ::= endoflinearith_op endofline arith_expr
arith_op ::= "+" "-"
term ::=
factor op_term
op_term ::= endoflineterm_op endofline term
term_op ::= "*" "/" "%" "//"
factor ::=
unary_op
powerunary_op ::= "+" "-" "~"
power ::= atom trailerexp_factor
exp_factor ::=
"**" factor
atom ::= id literal "(" IN endofline yield_expr endofline ")" EX "(" IN endofline testplist_gexp endofline ")" EX "[" IN endofline listmaker "]" EX "{" IN endofline dictmaker endofline "}" EX "`" testlist1 "`"
listmaker ::= endofline"," "," endoflinetest endofline plist_for endofline endofline test
testplist_gexp ::= test"," test endofline gen_forendofline
lambdef ::= "lambda" varargslist ":" test
trailer ::= SPOFF "(" SPON IN arglist endofline ")" EX "[" IN subscriptlist "]" EX endofline "." endofline id
subscriptlist ::= subscript"," endofline
subscript ::= endofline"." "." "." endofline endofline test endofline endofline test ":" test sliceop endofline
sliceop ::= ":" test
exprlist ::= expr","endofline
testlist ::= test","endofline
dictmaker ::= "," endofline "," endoflinedict_entry
dict_entry ::= endofline":" endofline testtest
classdef ::= "class" id ":" suite "class" id SPOFF "(" SPON testlist endofline ")" ":" suite
arglist ::= star_test"," comma_opt_star_testargument
star_test ::= endofline"*" test endofline "**" test
comma_opt_star_test ::= "," star_test comma_opt_star_test
argument ::= endoflinetest argument_value endofline
argument_value ::= endofline"=" endofline testgen_for
plist_iter ::= endoflineplist_for endofline plist_if
plist_for ::= "for" endofline exprlist "in" testplist_safe plist_iter
plist_if ::= "if" old_test plist_iter
gen_iter ::= endoflinegen_for endofline gen_if
gen_for ::= "for" exprlist "in" or_test gen_iter
gen_if ::= "if" old_test gen_iter
testlist1 ::= ","test
encoding_decl ::= id
yield_expr ::=
"yield" testlist
literal ::=
stringliteral more_stringliteral
integerliteral
floatliteralmore_stringliteral ::=
endofline
stringliteralstringliteral ::= stringprefix SPOFF string SPON string
stringprefix ::= "r" "u" "ur" "R" "U" "UR" "Ur" "uR" "b"
string ::= stringlit charlit longstringlit longcharlit
integerliteral ::= integer longimag
integer ::= integernumber hexinteger octinteger
long ::= SPOFF "l" SPON SPOFF "L" SPON
floatliteral ::= number imagpointfloat imag
imag ::= SPOFF "j" SPON SPOFF "J" SPON