+++ /dev/null
-# Grammar for Python\r
-\r
-# Note: Changing the grammar specified in this file will most likely\r
-# require corresponding changes in the parser module\r
-# (../Modules/parsermodule.c). If you can't make the changes to\r
-# that module yourself, please co-ordinate the required changes\r
-# with someone who can; ask around on python-dev for help. Fred\r
-# Drake <fdrake@acm.org> will probably be listening there.\r
-\r
-# NOTE WELL: You should also follow all the steps listed in PEP 306,\r
-# "How to Change Python's Grammar"\r
-\r
-# Commands for Kees Blom's railroad program\r
-#diagram:token NAME\r
-#diagram:token NUMBER\r
-#diagram:token STRING\r
-#diagram:token NEWLINE\r
-#diagram:token ENDMARKER\r
-#diagram:token INDENT\r
-#diagram:output\input python.bla\r
-#diagram:token DEDENT\r
-#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm\r
-#diagram:rules\r
-\r
-# Start symbols for the grammar:\r
-# file_input is a module or sequence of commands read from an input file;\r
-# single_input is a single interactive statement;\r
-# eval_input is the input for the eval() and input() functions.\r
-# NB: compound_stmt in single_input is followed by extra NEWLINE!\r
-file_input: (NEWLINE | stmt)* ENDMARKER\r
-single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE\r
-eval_input: testlist NEWLINE* ENDMARKER\r
-\r
-decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE\r
-decorators: decorator+\r
-decorated: decorators (classdef | funcdef)\r
-funcdef: 'def' NAME parameters ['->' test] ':' suite\r
-parameters: '(' [typedargslist] ')'\r
-typedargslist: ((tfpdef ['=' test] ',')*\r
- ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname)\r
- | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])\r
-tname: NAME [':' test]\r
-tfpdef: tname | '(' tfplist ')'\r
-tfplist: tfpdef (',' tfpdef)* [',']\r
-varargslist: ((vfpdef ['=' test] ',')*\r
- ('*' [vname] (',' vname ['=' test])* [',' '**' vname] | '**' vname)\r
- | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])\r
-vname: NAME\r
-vfpdef: vname | '(' vfplist ')'\r
-vfplist: vfpdef (',' vfpdef)* [',']\r
-\r
-stmt: simple_stmt | compound_stmt\r
-simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE\r
-small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |\r
- import_stmt | global_stmt | exec_stmt | assert_stmt)\r
-expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |\r
- ('=' (yield_expr|testlist_star_expr))*)\r
-testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']\r
-augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |\r
- '<<=' | '>>=' | '**=' | '//=')\r
-# For normal assignments, additional restrictions enforced by the interpreter\r
-print_stmt: 'print' ( [ test (',' test)* [','] ] |\r
- '>>' test [ (',' test)+ [','] ] )\r
-del_stmt: 'del' exprlist\r
-pass_stmt: 'pass'\r
-flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt\r
-break_stmt: 'break'\r
-continue_stmt: 'continue'\r
-return_stmt: 'return' [testlist]\r
-yield_stmt: yield_expr\r
-raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]\r
-import_stmt: import_name | import_from\r
-import_name: 'import' dotted_as_names\r
-import_from: ('from' ('.'* dotted_name | '.'+)\r
- 'import' ('*' | '(' import_as_names ')' | import_as_names))\r
-import_as_name: NAME ['as' NAME]\r
-dotted_as_name: dotted_name ['as' NAME]\r
-import_as_names: import_as_name (',' import_as_name)* [',']\r
-dotted_as_names: dotted_as_name (',' dotted_as_name)*\r
-dotted_name: NAME ('.' NAME)*\r
-global_stmt: ('global' | 'nonlocal') NAME (',' NAME)*\r
-exec_stmt: 'exec' expr ['in' test [',' test]]\r
-assert_stmt: 'assert' test [',' test]\r
-\r
-compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated\r
-if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]\r
-while_stmt: 'while' test ':' suite ['else' ':' suite]\r
-for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]\r
-try_stmt: ('try' ':' suite\r
- ((except_clause ':' suite)+\r
- ['else' ':' suite]\r
- ['finally' ':' suite] |\r
- 'finally' ':' suite))\r
-with_stmt: 'with' with_item (',' with_item)* ':' suite\r
-with_item: test ['as' expr]\r
-with_var: 'as' expr\r
-# NB compile.c makes sure that the default except clause is last\r
-except_clause: 'except' [test [(',' | 'as') test]]\r
-suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT\r
-\r
-# Backward compatibility cruft to support:\r
-# [ x for x in lambda: True, lambda: False if x() ]\r
-# even while also allowing:\r
-# lambda x: 5 if x else 2\r
-# (But not a mix of the two)\r
-testlist_safe: old_test [(',' old_test)+ [',']]\r
-old_test: or_test | old_lambdef\r
-old_lambdef: 'lambda' [varargslist] ':' old_test\r
-\r
-test: or_test ['if' or_test 'else' test] | lambdef\r
-or_test: and_test ('or' and_test)*\r
-and_test: not_test ('and' not_test)*\r
-not_test: 'not' not_test | comparison\r
-comparison: expr (comp_op expr)*\r
-comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'\r
-star_expr: '*' expr\r
-expr: xor_expr ('|' xor_expr)*\r
-xor_expr: and_expr ('^' and_expr)*\r
-and_expr: shift_expr ('&' shift_expr)*\r
-shift_expr: arith_expr (('<<'|'>>') arith_expr)*\r
-arith_expr: term (('+'|'-') term)*\r
-term: factor (('*'|'/'|'%'|'//') factor)*\r
-factor: ('+'|'-'|'~') factor | power\r
-power: atom trailer* ['**' factor]\r
-atom: ('(' [yield_expr|testlist_gexp] ')' |\r
- '[' [listmaker] ']' |\r
- '{' [dictsetmaker] '}' |\r
- '`' testlist1 '`' |\r
- NAME | NUMBER | STRING+ | '.' '.' '.')\r
-listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )\r
-testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )\r
-lambdef: 'lambda' [varargslist] ':' test\r
-trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME\r
-subscriptlist: subscript (',' subscript)* [',']\r
-subscript: test | [test] ':' [test] [sliceop]\r
-sliceop: ':' [test]\r
-exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']\r
-testlist: test (',' test)* [',']\r
-dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |\r
- (test (comp_for | (',' test)* [','])) )\r
-\r
-classdef: 'class' NAME ['(' [arglist] ')'] ':' suite\r
-\r
-arglist: (argument ',')* (argument [',']\r
- |'*' test (',' argument)* [',' '**' test] \r
- |'**' test)\r
-argument: test [comp_for] | test '=' test # Really [keyword '='] test\r
-\r
-comp_iter: comp_for | comp_if\r
-comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]\r
-comp_if: 'if' old_test [comp_iter]\r
-\r
-testlist1: test (',' test)*\r
-\r
-# not used in grammar, but may appear in "node" passed from Parser to Compiler\r
-encoding_decl: NAME\r
-\r
-yield_expr: 'yield' [testlist]\r