
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_newlinestmt_or_newline ::= stmt endofline
decorator ::= "@" dotted_name decorator_arglist endofline endofline
decorator_arglist ::= SPOFF "(" SPON IN arglist endofline ")" EX
decorators ::=
	decoratordecorated ::= decorators classdef decorators funcdef
funcdef ::= "def" id parameters ":" suite
parameters ::= SPOFF "(" SPON varargslist endofline ")"
varargslist ::= fpdef_test_comma endofline "*" id fpdef_test_comma endofline "*" id endofline "," endofline "**" id fpdef_test_comma endofline "**" id fpdef_test ","
fpdef_test ::= endofline fpdef is_test endofline
fpdef_test_comma ::=
	fpdef_test ","is_test ::= "=" endofline test
fpdef ::= id endofline SPOFF "(" SPON fplist endofline ")" endofline
fplist ::= fpdef ","
stmt ::= simple_stmt endofline compound_stmt
simple_stmt ::= small_stmt semicolon_small_stmt ";" comment
semicolon_small_stmt ::=
	";" small_stmtsmall_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" exprlistpass_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_test comma_test
comma_test ::= endofline "," test
import_stmt ::= import_name import_from
import_name ::=
	"import" dotted_as_namesimport_from ::= "from" "." dotted_name endofline "import" import_items
import_items ::= "*" endofline SPOFF "(" SPON import_as_names endofline ")" endofline import_as_names
import_as_name ::= endofline id as_name
as_name ::=
	"as" iddotted_as_name ::=
	dotted_name as_idas_id ::=
	"as" idimport_as_names ::= import_as_name ","
dotted_as_names ::=
	dotted_as_namedotted_name ::=
	id dot_dotted_namedot_dotted_name ::= endofline "." endofline dotted_name
global_stmt ::= "global" id
exec_stmt ::= "exec" expr in_test comma_test
in_test ::=
	"in" testassert_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 ":" suitewith_stmt ::= "with" test with_var ":" suite
with_var ::=
	"as" exprexcept_clause ::= "except" except_test
except_test ::=
	test as_or_comma_testas_or_comma_test ::= "as" test "," test
suite ::=
	indent endofline stmt_or_newline dedent
	simple_stmt endoflineendofline ::=
	comment newlineindent ::=
	"INDENT" INdedent ::=
	"DEDENT" EXtestplist_safe ::= old_test ","
old_test ::= or_test old_lambdef
old_lambdef ::= "lambda" varargslist ":" old_test
test ::= endofline or_test if_test endofline endofline lambdef endofline
if_test ::= endofline "if" or_test "else" test
or_test ::=
	and_test orop_or_testorop_or_test ::= endofline "or" endofline or_test
and_test ::=
	not_test andop_and_testandop_and_test ::= endofline "and" endofline and_test
not_test ::= "not" endofline comparison
comparison ::=
	expr comp_op_comparisoncomp_op_comparison ::= endofline comp_op endofline comparison
comp_op ::= "<" ">" "==" ">=" "<=" "<>" "!=" "in" "not" "in" "is" "is" "not"
expr ::=
	xor_expr orop_exprorop_expr ::= endofline "|" endofline expr
xor_expr ::=
	and_expr xorop_exprxorop_expr ::= endofline "^" endofline xor_expr
and_expr ::=
	shift_expr andop_and_exprandop_and_expr ::= endofline "&" endofline and_expr
shift_expr ::=
	arith_expr shiftop_shift_exprshiftop_shift_expr ::= endofline shift_op endofline shift_expr
shift_op ::= "<<" ">>"
arith_expr ::=
	term op_arith_exprop_arith_expr ::= endofline arith_op endofline arith_expr
arith_op ::= "+" "-"
term ::=
	factor op_termop_term ::= endofline term_op endofline term
term_op ::= "*" "/" "%" "//"
factor ::=
	unary_op powerunary_op ::= "+" "-" "~"
power ::= atom trailer exp_factor
exp_factor ::=
	"**" factoratom ::= 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 test endofline plist_for endofline endofline test "," "," endofline
testplist_gexp ::= test endofline "," test endofline gen_for
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 ::= dict_entry "," endofline "," endofline
dict_entry ::= endofline test ":" endofline test
classdef ::= "class" id ":" suite "class" id SPOFF "(" SPON testlist endofline ")" ":" suite
arglist ::= star_test argument "," comma_opt_star_test
star_test ::= endofline "*" test endofline "**" test
comma_opt_star_test ::= "," star_test comma_opt_star_test
argument ::= endofline test argument_value endofline
argument_value ::= endofline gen_for "=" endofline test
plist_iter ::= endofline plist_for endofline plist_if
plist_for ::= "for" endofline exprlist "in" testplist_safe plist_iter
plist_if ::= "if" old_test plist_iter
gen_iter ::= endofline gen_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" testlistliteral ::=
	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 long imag
integer ::= integernumber hexinteger octinteger
long ::= SPOFF "l" SPON SPOFF "L" SPON
floatliteral ::= number imag pointfloat imag
imag ::= SPOFF "j" SPON SPOFF "J" SPON