1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pyparser/data/Grammar2.5 Sun Jan 08 20:20:39 2017 +0100
1.3 @@ -0,0 +1,148 @@
1.4 +# Grammar for Python
1.5 +
1.6 +# Note: Changing the grammar specified in this file will most likely
1.7 +# require corresponding changes in the parser module
1.8 +# (../Modules/parsermodule.c). If you can't make the changes to
1.9 +# that module yourself, please co-ordinate the required changes
1.10 +# with someone who can; ask around on python-dev for help. Fred
1.11 +# Drake <fdrake@acm.org> will probably be listening there.
1.12 +
1.13 +# NOTE WELL: You should also follow all the steps listed in PEP 306,
1.14 +# "How to Change Python's Grammar"
1.15 +
1.16 +# Commands for Kees Blom's railroad program
1.17 +#diagram:token NAME
1.18 +#diagram:token NUMBER
1.19 +#diagram:token STRING
1.20 +#diagram:token NEWLINE
1.21 +#diagram:token ENDMARKER
1.22 +#diagram:token INDENT
1.23 +#diagram:output\input python.bla
1.24 +#diagram:token DEDENT
1.25 +#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm
1.26 +#diagram:rules
1.27 +
1.28 +# Start symbols for the grammar:
1.29 +# single_input is a single interactive statement;
1.30 +# file_input is a module or sequence of commands read from an input file;
1.31 +# eval_input is the input for the eval() and input() functions.
1.32 +# NB: compound_stmt in single_input is followed by extra NEWLINE!
1.33 +single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
1.34 +file_input: (NEWLINE | stmt)* ENDMARKER
1.35 +eval_input: testlist NEWLINE* ENDMARKER
1.36 +
1.37 +decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
1.38 +decorators: decorator+
1.39 +funcdef: [decorators] 'def' NAME parameters ':' suite
1.40 +parameters: '(' [varargslist] ')'
1.41 +varargslist: ((fpdef ['=' test] ',')*
1.42 + ('*' NAME [',' '**' NAME] | '**' NAME) |
1.43 + fpdef ['=' test] (',' fpdef ['=' test])* [','])
1.44 +fpdef: NAME | '(' fplist ')'
1.45 +fplist: fpdef (',' fpdef)* [',']
1.46 +
1.47 +stmt: simple_stmt | compound_stmt
1.48 +simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
1.49 +small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
1.50 + import_stmt | global_stmt | exec_stmt | assert_stmt)
1.51 +expr_stmt: testlist (augassign (yield_expr|testlist) |
1.52 + ('=' (yield_expr|testlist))*)
1.53 +augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
1.54 + '<<=' | '>>=' | '**=' | '//=')
1.55 +# For normal assignments, additional restrictions enforced by the interpreter
1.56 +print_stmt: 'print' ( [ test (',' test)* [','] ] |
1.57 + '>>' test [ (',' test)+ [','] ] )
1.58 +del_stmt: 'del' exprlist
1.59 +pass_stmt: 'pass'
1.60 +flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
1.61 +break_stmt: 'break'
1.62 +continue_stmt: 'continue'
1.63 +return_stmt: 'return' [testlist]
1.64 +yield_stmt: yield_expr
1.65 +raise_stmt: 'raise' [test [',' test [',' test]]]
1.66 +import_stmt: import_name | import_from
1.67 +import_name: 'import' dotted_as_names
1.68 +import_from: ('from' ('.'* dotted_name | '.'+)
1.69 + 'import' ('*' | '(' import_as_names ')' | import_as_names))
1.70 +import_as_name: NAME [('as' | NAME) NAME]
1.71 +dotted_as_name: dotted_name [('as' | NAME) NAME]
1.72 +import_as_names: import_as_name (',' import_as_name)* [',']
1.73 +dotted_as_names: dotted_as_name (',' dotted_as_name)*
1.74 +dotted_name: NAME ('.' NAME)*
1.75 +global_stmt: 'global' NAME (',' NAME)*
1.76 +exec_stmt: 'exec' expr ['in' test [',' test]]
1.77 +assert_stmt: 'assert' test [',' test]
1.78 +
1.79 +compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef
1.80 +if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
1.81 +while_stmt: 'while' test ':' suite ['else' ':' suite]
1.82 +for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
1.83 +try_stmt: ('try' ':' suite
1.84 + ((except_clause ':' suite)+
1.85 + ['else' ':' suite]
1.86 + ['finally' ':' suite] |
1.87 + 'finally' ':' suite))
1.88 +with_stmt: 'with' test [ with_var ] ':' suite
1.89 +with_var: ('as' | NAME) expr
1.90 +# NB compile.c makes sure that the default except clause is last
1.91 +except_clause: 'except' [test [',' test]]
1.92 +suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
1.93 +
1.94 +# Backward compatibility cruft to support:
1.95 +# [ x for x in lambda: True, lambda: False if x() ]
1.96 +# even while also allowing:
1.97 +# lambda x: 5 if x else 2
1.98 +# (But not a mix of the two)
1.99 +testlist_safe: old_test [(',' old_test)+ [',']]
1.100 +old_test: or_test | old_lambdef
1.101 +old_lambdef: 'lambda' [varargslist] ':' old_test
1.102 +
1.103 +test: or_test ['if' or_test 'else' test] | lambdef
1.104 +or_test: and_test ('or' and_test)*
1.105 +and_test: not_test ('and' not_test)*
1.106 +not_test: 'not' not_test | comparison
1.107 +comparison: expr (comp_op expr)*
1.108 +comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
1.109 +expr: xor_expr ('|' xor_expr)*
1.110 +xor_expr: and_expr ('^' and_expr)*
1.111 +and_expr: shift_expr ('&' shift_expr)*
1.112 +shift_expr: arith_expr (('<<'|'>>') arith_expr)*
1.113 +arith_expr: term (('+'|'-') term)*
1.114 +term: factor (('*'|'/'|'%'|'//') factor)*
1.115 +factor: ('+'|'-'|'~') factor | power
1.116 +power: atom trailer* ['**' factor]
1.117 +atom: ('(' [yield_expr|testlist_gexp] ')' |
1.118 + '[' [listmaker] ']' |
1.119 + '{' [dictmaker] '}' |
1.120 + '`' testlist1 '`' |
1.121 + NAME | NUMBER | STRING+)
1.122 +listmaker: test ( list_for | (',' test)* [','] )
1.123 +testlist_gexp: test ( gen_for | (',' test)* [','] )
1.124 +lambdef: 'lambda' [varargslist] ':' test
1.125 +trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
1.126 +subscriptlist: subscript (',' subscript)* [',']
1.127 +subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
1.128 +sliceop: ':' [test]
1.129 +exprlist: expr (',' expr)* [',']
1.130 +testlist: test (',' test)* [',']
1.131 +dictmaker: test ':' test (',' test ':' test)* [',']
1.132 +
1.133 +classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
1.134 +
1.135 +arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
1.136 +argument: test [gen_for] | test '=' test # Really [keyword '='] test
1.137 +
1.138 +list_iter: list_for | list_if
1.139 +list_for: 'for' exprlist 'in' testlist_safe [list_iter]
1.140 +list_if: 'if' old_test [list_iter]
1.141 +
1.142 +gen_iter: gen_for | gen_if
1.143 +gen_for: 'for' exprlist 'in' or_test [gen_iter]
1.144 +gen_if: 'if' old_test [gen_iter]
1.145 +
1.146 +testlist1: test (',' test)*
1.147 +
1.148 +# not used in grammar, but may appear in "node" passed from Parser to Compiler
1.149 +encoding_decl: NAME
1.150 +
1.151 +yield_expr: 'yield' [testlist]