]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Grammar/Grammar
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Grammar / Grammar
CommitLineData
4710c53d 1# Grammar for Python\r
2\r
3# Note: Changing the grammar specified in this file will most likely\r
4# require corresponding changes in the parser module\r
5# (../Modules/parsermodule.c). If you can't make the changes to\r
6# that module yourself, please co-ordinate the required changes\r
7# with someone who can; ask around on python-dev for help. Fred\r
8# Drake <fdrake@acm.org> will probably be listening there.\r
9\r
10# NOTE WELL: You should also follow all the steps listed in PEP 306,\r
11# "How to Change Python's Grammar"\r
12\r
13# Start symbols for the grammar:\r
14# single_input is a single interactive statement;\r
15# file_input is a module or sequence of commands read from an input file;\r
16# eval_input is the input for the eval() and input() functions.\r
17# NB: compound_stmt in single_input is followed by extra NEWLINE!\r
18single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE\r
19file_input: (NEWLINE | stmt)* ENDMARKER\r
20eval_input: testlist NEWLINE* ENDMARKER\r
21\r
22decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE\r
23decorators: decorator+\r
24decorated: decorators (classdef | funcdef)\r
25funcdef: 'def' NAME parameters ':' suite\r
26parameters: '(' [varargslist] ')'\r
27varargslist: ((fpdef ['=' test] ',')*\r
28 ('*' NAME [',' '**' NAME] | '**' NAME) |\r
29 fpdef ['=' test] (',' fpdef ['=' test])* [','])\r
30fpdef: NAME | '(' fplist ')'\r
31fplist: fpdef (',' fpdef)* [',']\r
32\r
33stmt: simple_stmt | compound_stmt\r
34simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE\r
35small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |\r
36 import_stmt | global_stmt | exec_stmt | assert_stmt)\r
37expr_stmt: testlist (augassign (yield_expr|testlist) |\r
38 ('=' (yield_expr|testlist))*)\r
39augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |\r
40 '<<=' | '>>=' | '**=' | '//=')\r
41# For normal assignments, additional restrictions enforced by the interpreter\r
42print_stmt: 'print' ( [ test (',' test)* [','] ] |\r
43 '>>' test [ (',' test)+ [','] ] )\r
44del_stmt: 'del' exprlist\r
45pass_stmt: 'pass'\r
46flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt\r
47break_stmt: 'break'\r
48continue_stmt: 'continue'\r
49return_stmt: 'return' [testlist]\r
50yield_stmt: yield_expr\r
51raise_stmt: 'raise' [test [',' test [',' test]]]\r
52import_stmt: import_name | import_from\r
53import_name: 'import' dotted_as_names\r
54import_from: ('from' ('.'* dotted_name | '.'+)\r
55 'import' ('*' | '(' import_as_names ')' | import_as_names))\r
56import_as_name: NAME ['as' NAME]\r
57dotted_as_name: dotted_name ['as' NAME]\r
58import_as_names: import_as_name (',' import_as_name)* [',']\r
59dotted_as_names: dotted_as_name (',' dotted_as_name)*\r
60dotted_name: NAME ('.' NAME)*\r
61global_stmt: 'global' NAME (',' NAME)*\r
62exec_stmt: 'exec' expr ['in' test [',' test]]\r
63assert_stmt: 'assert' test [',' test]\r
64\r
65compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated\r
66if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]\r
67while_stmt: 'while' test ':' suite ['else' ':' suite]\r
68for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]\r
69try_stmt: ('try' ':' suite\r
70 ((except_clause ':' suite)+\r
71 ['else' ':' suite]\r
72 ['finally' ':' suite] |\r
73 'finally' ':' suite))\r
74with_stmt: 'with' with_item (',' with_item)* ':' suite\r
75with_item: test ['as' expr]\r
76# NB compile.c makes sure that the default except clause is last\r
77except_clause: 'except' [test [('as' | ',') test]]\r
78suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT\r
79\r
80# Backward compatibility cruft to support:\r
81# [ x for x in lambda: True, lambda: False if x() ]\r
82# even while also allowing:\r
83# lambda x: 5 if x else 2\r
84# (But not a mix of the two)\r
85testlist_safe: old_test [(',' old_test)+ [',']]\r
86old_test: or_test | old_lambdef\r
87old_lambdef: 'lambda' [varargslist] ':' old_test\r
88\r
89test: or_test ['if' or_test 'else' test] | lambdef\r
90or_test: and_test ('or' and_test)*\r
91and_test: not_test ('and' not_test)*\r
92not_test: 'not' not_test | comparison\r
93comparison: expr (comp_op expr)*\r
94comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'\r
95expr: xor_expr ('|' xor_expr)*\r
96xor_expr: and_expr ('^' and_expr)*\r
97and_expr: shift_expr ('&' shift_expr)*\r
98shift_expr: arith_expr (('<<'|'>>') arith_expr)*\r
99arith_expr: term (('+'|'-') term)*\r
100term: factor (('*'|'/'|'%'|'//') factor)*\r
101factor: ('+'|'-'|'~') factor | power\r
102power: atom trailer* ['**' factor]\r
103atom: ('(' [yield_expr|testlist_comp] ')' |\r
104 '[' [listmaker] ']' |\r
105 '{' [dictorsetmaker] '}' |\r
106 '`' testlist1 '`' |\r
107 NAME | NUMBER | STRING+)\r
108listmaker: test ( list_for | (',' test)* [','] )\r
109testlist_comp: test ( comp_for | (',' test)* [','] )\r
110lambdef: 'lambda' [varargslist] ':' test\r
111trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME\r
112subscriptlist: subscript (',' subscript)* [',']\r
113subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]\r
114sliceop: ':' [test]\r
115exprlist: expr (',' expr)* [',']\r
116testlist: test (',' test)* [',']\r
117dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |\r
118 (test (comp_for | (',' test)* [','])) )\r
119\r
120classdef: 'class' NAME ['(' [testlist] ')'] ':' suite\r
121\r
122arglist: (argument ',')* (argument [',']\r
123 |'*' test (',' argument)* [',' '**' test] \r
124 |'**' test)\r
125# The reason that keywords are test nodes instead of NAME is that using NAME\r
126# results in an ambiguity. ast.c makes sure it's a NAME.\r
127argument: test [comp_for] | test '=' test\r
128\r
129list_iter: list_for | list_if\r
130list_for: 'for' exprlist 'in' testlist_safe [list_iter]\r
131list_if: 'if' old_test [list_iter]\r
132\r
133comp_iter: comp_for | comp_if\r
134comp_for: 'for' exprlist 'in' or_test [comp_iter]\r
135comp_if: 'if' old_test [comp_iter]\r
136\r
137testlist1: test (',' test)*\r
138\r
139# not used in grammar, but may appear in "node" passed from Parser to Compiler\r
140encoding_decl: NAME\r
141\r
142yield_expr: 'yield' [testlist]\r