-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointers.g4
46 lines (36 loc) · 1.02 KB
/
pointers.g4
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
grammar pointers;
/*
* Parser Rules
*/
variable: VAR # variableName
| NULL # nullvar;
statement: SKIPSTATEMENT # skip
| variable ':=' ALLOC VAR # alloc
| variable ':=' variable # assign
| IF '(' cond=variable ')' '{' (ifs+=statement ';')+ '}' (ELSE '{' (elses+=statement ';')+ '}' )? # if
| WHILE '(' cond=variable ')' '{' (statement ';')+ '}' # while
;
program: (statement ';')+
;
/*
* Lexer Rules
*/
SKIPSTATEMENT : 'skip';
ALLOC : 'newObject';
IF : 'if';
THEN : 'then';
ELSE : 'else';
DONE : 'done';
WHILE : 'while';
DO : 'do';
OD : 'od';
NULL : 'null';
VAR : [a-zA-Z] [._0-9A-Za-z]*;
INT : [0-9] +;
PLUS : '+';
MINUS : '-';
MULTIPLY : '*';
DIVISION : '/';
EQUALS : '==';
LEQ : '<';
WHITESPACE : [ \t\r\n\f]+ -> channel(HIDDEN);