1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pyparser/data/Grammar-Lichen Mon Jan 09 19:10:12 2017 +0100
1.3 @@ -0,0 +1,119 @@
1.4 +# Grammar for Lichen
1.5 +
1.6 +# Start symbols for the grammar:
1.7 +# single_input is a single interactive statement;
1.8 +# file_input is a module or sequence of commands read from an input file;
1.9 +# eval_input is the input for the eval() and input() functions.
1.10 +# NB: compound_stmt in single_input is followed by extra NEWLINE!
1.11 +single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
1.12 +file_input: (NEWLINE | stmt)* ENDMARKER
1.13 +eval_input: testlist NEWLINE* ENDMARKER
1.14 +
1.15 +funcdef: 'def' NAME parameters ':' suite
1.16 +parameters: '(' [varargslist] ')'
1.17 +varargslist: ((fpdef ['=' test] ',')*
1.18 + ('*' NAME [',' '**' NAME] | '**' NAME) |
1.19 + fpdef ['=' test] (',' fpdef ['=' test])* [','])
1.20 +fpdef: NAME | '(' fplist ')'
1.21 +fplist: fpdef (',' fpdef)* [',']
1.22 +
1.23 +stmt: simple_stmt | compound_stmt
1.24 +simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
1.25 +small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
1.26 + import_stmt | global_stmt | exec_stmt | assert_stmt)
1.27 +expr_stmt: testlist (augassign testlist |
1.28 + ('=' testlist)*)
1.29 +augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
1.30 + '<<=' | '>>=' | '**=' | '//=')
1.31 +# For normal assignments, additional restrictions enforced by the interpreter
1.32 +print_stmt: 'print' ( [ test (',' test)* [','] ] |
1.33 + '>>' test [ (',' test)+ [','] ] )
1.34 +del_stmt: 'del' exprlist
1.35 +pass_stmt: 'pass'
1.36 +flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
1.37 +break_stmt: 'break'
1.38 +continue_stmt: 'continue'
1.39 +return_stmt: 'return' [testlist]
1.40 +raise_stmt: 'raise' [test [',' test [',' test]]]
1.41 +import_stmt: import_name | import_from
1.42 +import_name: 'import' dotted_as_names
1.43 +import_from: ('from' ('.'* dotted_name | '.'+)
1.44 + 'import' ('*' | '(' import_as_names ')' | import_as_names))
1.45 +import_as_name: NAME ['as' NAME]
1.46 +dotted_as_name: dotted_name ['as' NAME]
1.47 +import_as_names: import_as_name (',' import_as_name)* [',']
1.48 +dotted_as_names: dotted_as_name (',' dotted_as_name)*
1.49 +dotted_name: NAME ('.' NAME)*
1.50 +global_stmt: 'global' NAME (',' NAME)*
1.51 +exec_stmt: 'exec' expr ['in' test [',' test]]
1.52 +assert_stmt: 'assert' test [',' test]
1.53 +
1.54 +compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef
1.55 +if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
1.56 +while_stmt: 'while' test ':' suite ['else' ':' suite]
1.57 +for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
1.58 +try_stmt: ('try' ':' suite
1.59 + ((except_clause ':' suite)+
1.60 + ['else' ':' suite]
1.61 + ['finally' ':' suite] |
1.62 + 'finally' ':' suite))
1.63 +with_stmt: 'with' with_item (',' with_item)* ':' suite
1.64 +with_item: test ['as' expr]
1.65 +# NB compile.c makes sure that the default except clause is last
1.66 +except_clause: 'except' [test [('as' | ',') test]]
1.67 +suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
1.68 +
1.69 +# Backward compatibility cruft to support:
1.70 +# [ x for x in lambda: True, lambda: False if x() ]
1.71 +# even while also allowing:
1.72 +# lambda x: 5 if x else 2
1.73 +# (But not a mix of the two)
1.74 +testlist_safe: old_test [(',' old_test)+ [',']]
1.75 +old_test: or_test | old_lambdef
1.76 +old_lambdef: 'lambda' [varargslist] ':' old_test
1.77 +
1.78 +test: or_test ['if' or_test 'else' test] | lambdef
1.79 +or_test: and_test ('or' and_test)*
1.80 +and_test: not_test ('and' not_test)*
1.81 +not_test: 'not' not_test | comparison
1.82 +comparison: expr (comp_op expr)*
1.83 +comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
1.84 +expr: xor_expr ('|' xor_expr)*
1.85 +xor_expr: and_expr ('^' and_expr)*
1.86 +and_expr: shift_expr ('&' shift_expr)*
1.87 +shift_expr: arith_expr (('<<'|'>>') arith_expr)*
1.88 +arith_expr: term (('+'|'-') term)*
1.89 +term: factor (('*'|'/'|'%'|'//') factor)*
1.90 +factor: ('+'|'-'|'~') factor | power
1.91 +power: atom trailer* ['**' factor]
1.92 +atom: ('(' [testlist_comp] ')' |
1.93 + '[' [listmaker] ']' |
1.94 + '{' [dictorsetmaker] '}' |
1.95 + '`' testlist1 '`' |
1.96 + NAME | NUMBER | STRING+)
1.97 +listmaker: test ( (',' test)* [','] )
1.98 +testlist_comp: test ( (',' test)* [','] )
1.99 +lambdef: 'lambda' [varargslist] ':' test
1.100 +trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
1.101 +subscriptlist: subscript (',' subscript)* [',']
1.102 +subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
1.103 +sliceop: ':' [test]
1.104 +exprlist: expr (',' expr)* [',']
1.105 +testlist: test (',' test)* [',']
1.106 +dictmaker: test ':' test (',' test ':' test)* [',']
1.107 +dictorsetmaker: ( (test ':' test ( (',' test ':' test)* [','])) |
1.108 + (test ( (',' test)* [','])) )
1.109 +
1.110 +classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
1.111 +
1.112 +arglist: (argument ',')* (argument [',']
1.113 + |'*' test (',' argument)* [',' '**' test]
1.114 + |'**' test)
1.115 +# The reason that keywords are test nodes instead of NAME is that using NAME
1.116 +# results in an ambiguity. ast.c makes sure it's a NAME.
1.117 +argument: test | test '=' test
1.118 +
1.119 +testlist1: test (',' test)*
1.120 +
1.121 +# not used in grammar, but may appear in "node" passed from Parser to Compiler
1.122 +encoding_decl: NAME