-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListLanguage.g4
More file actions
151 lines (133 loc) · 3.33 KB
/
ListLanguage.g4
File metadata and controls
151 lines (133 loc) · 3.33 KB
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
grammar ListLanguage;
program: sub_program* statement*;
block: statement+;
statement: assign_element
| print
| if_block
| sub_program_call
| for_block
| return_def
| range
| while_block
| input
| method
;
// OPERATIONS
assign_element: (get_element
| ID COMMA?)+ ASSIGN
( list_init
| elem_init
| queue_init
| tree
| operations
| input
| get_element
| method
| ID COMMA?)+
;
operations: OPEN_PAREN* (variables_and_num (ADD | MINUS | MUL | DIV)?)+ operation_list? CLOSE_PAREN*;
get_element: ID OPEN_BRACK (variables_and_num | get_element) CLOSE_BRACK;
// INIT
queue_init: OPEN_PAREN (elem_init COMMA?)* CLOSE_PAREN;
list_init: OPEN_BRACK (elem_init COMMA?)* CLOSE_BRACK;
elem_init: type;
tree: OPEN_BRACK (elem_init tree tree?)* CLOSE_BRACK;
// IF
if_block: if_init elif* else?;
if_init: IF OPEN_PAREN variables_and_num compare variables_and_num CLOSE_PAREN OPEN_BRACE block CLOSE_BRACE;
else: ELSE OPEN_PAREN block CLOSE_PAREN;
elif: ELIF OPEN_PAREN variables_and_num compare variables_and_num CLOSE_PAREN OPEN_BRACE block CLOSE_BRACE;
compare: EQUALS
| ADD
| MINUS
| MUL
| DIV
| GREATER_THAN
| GT_EQ
| LESS_THAN
| LT_EQ
;
// FOR
for_block: for_init else?;
for_init: FOR OPEN_PAREN variables IN variables_and_num CLOSE_PAREN OPEN_BRACE block CLOSE_BRACE;
// WHILE
while_block: while_init else?;
while_init: WHILE OPEN_PAREN variables_and_num compare variables_and_num CLOSE_PAREN OPEN_BRACE (block)+ CLOSE_BRACE;
// DEF
sub_program: DEF ID OPEN_PAREN type (COMMA type)* CLOSE_PAREN OPEN_BRACE (block)+ CLOSE_BRACE;
sub_program_call: ID OPEN_PAREN type (COMMA type)* CLOSE_PAREN;
// BASE FUNC
print: PRINT OPEN_PAREN (variables_and_num COMMA?)* CLOSE_PAREN;
range: RANGE OPEN_PAREN variables_and_num CLOSE_PAREN;
input: INPUT OPEN_PAREN CLOSE_PAREN;
return_def: RETURN ID
| NUM
;
method: variables POINT_FOR_M methods OPEN_PAREN variables_and_num? CLOSE_PAREN;
// VARIABLES
methods: GET
| POP
| APPEND
| REMOVE
| CLEAR
;
variables: ID
| elem_init
| sub_program_call
| get_element
;
variables_and_num: variables
| NUM
;
type: NUM
| ID
;
operation_list: ADD
| MINUS
| DIV
| MUL
| POW
;
// CONST
INPUT: 'input';
PRINT: 'print';
RANGE: 'range';
DEF: 'def';
FOR: 'for';
WHILE: 'while';
IN: 'in';
IF: 'if';
ELSE: 'else';
ELIF: 'elif';
GET: 'get';
POP: 'pop';
APPEND: 'append';
REMOVE: 'remove';
CLEAR: 'clear';
RETURN: 'return';
TWO_POINT: ':';
POINT_FOR_M: '.';
COMMA: ',';
OPEN_CLOSE_EL: '"';
OPEN_PAREN: '(';
CLOSE_PAREN: ')';
OPEN_BRACK: '[';
CLOSE_BRACK: ']';
OPEN_BRACE: '{';
CLOSE_BRACE: '}';
ASSIGN: '=';
ADD: '+';
MINUS: '-';
MUL: '*';
DIV: '/';
POW: '**';
LESS_THAN : '<';
GREATER_THAN : '>';
EQUALS : '==';
GT_EQ : '>=';
LT_EQ : '<=';
NOT_EQ_1 : '<>';
NOT_EQ_2 : '!=';
ID: [a-zA-Z_] [a-zA-Z0-9_]*;
NUM: [1-9][0-9]*|[0];
WS: [ \t\r\n]+ -> skip;