-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammar.txt
122 lines (95 loc) · 4.35 KB
/
grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# A minimal grammar based on Python 3
file_input ::= (NEWLINE | statement)*
interactive_input ::= [stmt_list] NEWLINE | compound_stmt NEWLINE
eval_input ::= expression NEWLINE*
statement ::= stmt_list NEWLINE | compound_stmt
stmt_list ::= simple_stmt (";" simple_stmt)* [;]
simple_stmt ::= expression_stmt
| assignment_stmt
| augmented_assignment_stmt
| pass_stmt
| del_stmt
| return_stmt
| break_stmt
| continue_stmt
expression_stmt ::= expression
expression ::= conditional_expression
conditional_expression ::= or_test ["if" or_test "else" expression]
or_test ::= and_test | or_test "or" and_test
and_test ::= not_test | and_test "and" not_test
not_test ::= comparison | "not" not_test
comparison ::= or_expr ( comp_operator or_expr )*
comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!=" | "is" | in"
or_expr ::= xor_expr | or_expr "|" xor_expr
xor_expr ::= and_expr | xor_expr "^" and_expr
and_expr ::= shift_expr | and_expr "&" shift_expr
shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr
a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr
m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr | m_expr "%" u_expr
u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr
power ::= primary ["**" u_expr]
primary ::= atom | attributeref | subscription | call
atom ::= identifier | literal | enclosure
literal ::= stringliteral | integer | floatnumber
enclosure ::= parenth_form | list_display | set_display | dict_display
parenth_form ::= "(" [expression] ")"
list_display ::= "[" [expression_list] "]"
set_display ::= "{" expression_list "}"
expression_list ::= expression ( "," expression )*
dict_display ::= "{" [key_datum_list] "}"
key_datum_list ::= key_datum ("," key_datum)*
key_datum ::= expression ":" expression
identifier ::= (letter | "_") (letter | digit | "_")*
letter ::= lowercase | uppercase
lowercase ::= "a"..."z"
uppercase ::= "A"..."Z"
digit ::= "0"..."9"
stringliteral. ::= "'" stringitem* "'" | '"' stringitem* '"'
stringitem ::= stringchar | stringescapeseq
stringchar ::= <any source character except "\" or newline or the quote>
stringescapeseq ::= "\" <any source character>
integer ::= decimalinteger | octinteger | hexinteger | bininteger
decimalinteger ::= nonzerodigit digit* | "0"+
nonzerodigit ::= "1"..."9"
digit ::= "0"..."9"
octinteger ::= "0" ("o" | "O") octdigit+
hexinteger ::= "0" ("x" | "X") hexdigit+
bininteger ::= "0" ("b" | "B") bindigit+
octdigit ::= "0"..."7"
hexdigit ::= digit | "a"..."f" | "A"..."F"
bindigit ::= "0" | "1"
floatnumber ::= pointfloat | exponentfloat
pointfloat ::= [intpart] fraction | intpart "."
exponentfloat ::= (intpart | pointfloat) exponent
intpart ::= digit+
fraction ::= "." digit+
exponent ::= ("e" | "E") ["+" | "-"] digit+
attributeref ::= primary "." identifier
subscription ::= primary "[" expression "]"
call ::= primary "(" [argument_list] ")"
argument_list ::= expression ("," expression)*
target ::= identifier | attributeref | subscription
assignment_stmt ::= (target "=")+ expression
augmented_assignment_stmt ::= target augop expression
augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**=" | ">>=" | "<<=" | "&=" | "^=" | "|="
pass_stmt ::= "pass"
del_stmt ::= "del" target
return_stmt ::= "return" [expression]
break_stmt ::= "break"
continue_stmt ::= "continue"
compound_stmt ::= if_stmt | while_stmt | for_stmt | funcdef | classdef
suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT
if_stmt ::= "if" expression ":" suite
( "elif" expression ":" suite )*
["else" ":" suite]
while_stmt ::= "while" expression ":" suite
["else" ":" suite]
for_stmt ::= "for" target "in" expression ":" suite
["else" ":" suite]
funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite
parameter_list ::= parameter ("," parameter)*
parameter ::= identifier
funcname ::= identifier
classdef ::= "class" classname [inheritance] ":" suite
inheritance ::= "(" [argument_list] ")"
classname ::= identifier