-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
261 lines (187 loc) · 7.82 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
program : nonexecutables imports nonexecutables definitions_and_statements nonexecutables
newlines : newlines NEWLINE
| NEWLINE
empty :
imports : imports nonexecutables import
| import
| empty
import : IMPORT compound_identifier NEWLINE
| IMPORT compound_identifier AS IDENTIFIER NEWLINE
| IMPORT compound_identifier FROM compound_identifier NEWLINE
| IMPORT compound_identifier FROM compound_identifier AS IDENTIFIER NEWLINE
definitions_and_statements : definitions_and_statements nonexecutables definition
| definitions_and_statements nonexecutables statement
| definition
| statement
| empty
type : TYPE
| IDENTIFIER
| LIST LEFTARROW type RIGHTARROW
| TUPLE LEFTARROW types RIGHTARROW
| DICT LEFTARROW type COMMA type RIGHTARROW
| SET LEFTARROW type RIGHTARROW
types : types COMMA type
| type
definition : class_definition
| function_definition
| variable_definition
variable_definition : type IDENTIFIER ASSIGN expression NEWLINE
| type IDENTIFIER ASSIGN expression oneline_comment
function_definition : function_naming LPAREN parameters RPAREN RETURNARROW type LBRACE NEWLINE function_body RBRACE NEWLINE
| function_naming LPAREN parameters RPAREN RETURNARROW NONE LBRACE NEWLINE function_body RBRACE NEWLINE
function_naming : FUNCTION IDENTIFIER
function_body : function_body statement nonexecutables
| function_body variable_definition nonexecutables
| function_body function_definition nonexecutables
| nonexecutables
| empty
statement : assignment_statement
| call_statement
| if_statement
| match_statement
| loop_statement
| continue_statement
| break_statement
| return_statement
| pass_statement
| NEWLINE
statements : statements comments statement
| statement
| empty
return_statement : RETURN expression NEWLINE
| RETURN NEWLINE
assignment_statement : compound_identifier assign expression NEWLINE
| subscript_expression assign expression NEWLINE
| compound_identifier assign expression oneline_comment
| subscript_expression assign expression oneline_comment
assign : ASSIGN
| PLUSASSIGN
| MINUSASSIGN
| TIMESASSIGN
| DIVIDEASSIGN
| MODULOASSIGN
| POWERASSIGN
| FLOORASSIGN
call_statement : call NEWLINE
if_statement : simple_if_statement
| compound_if_statement
simple_if_statement : LEAF LPAREN expression RPAREN LBRACE NEWLINE if_body RBRACE NEWLINE
if_body : if_body statement nonexecutables
| if_body variable_definition nonexecutables
| nonexecutables
| empty
compound_if_statement : TREE LBRACE NEWLINE if_elseif_statements else_block RBRACE NEWLINE
| TREE LBRACE NEWLINE if_elseif_statements RBRACE NEWLINE
if_elseif_statements : if_elseif_statements elseif_statement
| simple_if_statement
elseif_statement : LEAF LPAREN expression RPAREN LBRACE NEWLINE if_body RBRACE NEWLINE
else_block : FALLENLEAF LBRACE NEWLINE if_body RBRACE NEWLINE
match_statement : TREE LPAREN compound_identifier RPAREN LBRACE NEWLINE match_cases match_default RBRACE NEWLINE
match_cases : match_cases match_case
| match_case
match_case : LEAF LPAREN expression RPAREN LBRACE case_body RBRACE NEWLINE
match_default : FALLENLEAF LBRACE case_body RBRACE NEWLINE
case_body : case_body statement nonexecutables
| case_body variable_definition nonexecutables
| nonexecutables
| empty
loop_statement : while_statement
| for_statement
while_statement : loop_beginning LPAREN expression RPAREN LBRACE NEWLINE statements RBRACE NEWLINE
| loop_beginning LBRACE NEWLINE statements RBRACE NEWLINE
loop_beginning : LOOP
for_statement : for_beginning LBRACE NEWLINE definitions_and_statements RBRACE NEWLINE
for_beginning : loop_beginning LPAREN type IDENTIFIER ASSIGN expression RPAREN
continue_statement : CONTINUE NEWLINE
break_statement : BREAK NEWLINE
pass_statement : PASS NEWLINE
comment : oneline_comment
| multiline_comment
multiline_comment : MULTILINECOMMENT
oneline_comment : ONELINECOMMENT
comments : comments comment
| comment
nonexecutables : nonexecutables comments
| nonexecutables newlines
| empty
parameters : parameters COMMA parameter
| parameter
| empty
class_parameters : parameters
parameter : simple_parameter
| default_parameter
simple_parameter : type IDENTIFIER
default_parameter : type IDENTIFIER ASSIGN expression
class_definition : class_naming LBRACE NEWLINE class_body RBRACE NEWLINE
| class_naming INHERITS IDENTIFIER LBRACE NEWLINE class_body RBRACE NEWLINE
class_naming : CLASS IDENTIFIER
class_body : nonexecutables fields_declarations nonexecutables constructor_definition nonexecutables
methods_definitions nonexecutables
fields_declarations : fields_declarations nonexecutables field_declaration
| field_declaration
| empty
field_declaration : type IDENTIFIER NEWLINE
| CLASS type IDENTIFIER NEWLINE
constructor_definition : constructor_naming LPAREN class_parameters RPAREN LBRACE NEWLINE constructor_body RBRACE NEWLINE
| empty
constructor_naming : CONSTRUCTOR IDENTIFIER
constructor_body : function_body
| function_body super_init_call function_body
super_init_call : INHERITS LPAREN arguments RPAREN
methods_definitions : methods_definitions nonexecutables method_definition
| method_definition
| empty
method_definition : method_naming LPAREN class_parameters RPAREN RETURNARROW type LBRACE NEWLINE function_body RBRACE NEWLINE
| method_naming LPAREN class_parameters RPAREN RETURNARROW NONE LBRACE NEWLINE function_body RBRACE NEWLINE
method_naming : FUNCTION IDENTIFIER
| CLASS FUNCTION IDENTIFIER
expression : LPAREN expression RPAREN
| binary_expression
| unary_expression
| call_expression
| literal_expression
| identifier_expression
| subscript_expression
binary_operator : PLUS
| MINUS
| TIMES
| DIVIDE
| MODULO
| POWER
| FLOOR
| EQUAL
| NOTEQUAL
| LESS
| GREATER
| LESSEQUAL
| GREATEREQUAL
| AND
| OR
binary_expression : expression binary_operator expression
unary_expression : MINUS expression
| NOT expression
call_expression : call
call : compound_identifier LPAREN arguments RPAREN
| LIST LPAREN arguments RPAREN
| SET LPAREN arguments RPAREN
| TUPLE LPAREN arguments RPAREN
| DICT LPAREN items RPAREN
| PRINT LPAREN arguments RPAREN
items : items COMMA item
| item
| empty
item : expression COLON expression
compound_identifier : compound_identifier DOT IDENTIFIER
| IDENTIFIER
| SELF DOT IDENTIFIER
arguments : arguments COMMA expression
| expression
| empty
literal_expression : literal
literal : INT
| FLOAT
| STRING
| BOOLEAN
| NONE
identifier_expression : compound_identifier
subscript_expression : expression LBRACKET expression RBRACKET