-
Notifications
You must be signed in to change notification settings - Fork 0
/
logo3d.g
79 lines (68 loc) · 1.32 KB
/
logo3d.g
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
grammar logo3d;
root : proc* stat EOF
| proc* EOF
| stat EOF;
proc : PROC ID '(' arg1 ')' IS stat END;
PROC : 'PROC';
IS : 'IS';
arg1 : ID ',' arg1
| ID
|
;
stat : assig stat
| read stat
| write stat
| cond stat
| loop stat
| invoc stat
|
;
write : '<<' (expr|boolex);
read : '>>' ID;
assig : ID ':=' (expr|boolex);
invoc : ID '(' arg ')';
arg : (ID | NUM) ',' arg #ArgSimp
| (ID | NUM) #ArgSimp
| expr ',' arg #ArgExpr
| expr #ArgExpr
| #ArgSimp
;
cond : IF boolex THEN stat END
| IF boolex THEN stat ELSE stat END;
IF : 'IF';
THEN : 'THEN';
ELSE : 'ELSE';
END : 'END';
loop : WHILE boolex DO stat END #While
| FOR ID FROM (NUM | ID) TO (NUM | ID) DO stat END #For
;
WHILE : 'WHILE';
DO : 'DO';
FOR : 'FOR';
FROM : 'FROM';
TO : 'TO';
boolex : OP boolex CP
| boolex ('&&' | '||') boolex
| boolex ('==' | '!=' | '>' | '<' | '>=' | '<=') boolex
| ID
| NUM
;
expr : OP expr CP
| expr (MULT|DIV) expr
| expr (SUM|SUB) expr
| NUM
| ID;
idnum : ID | NUM;
CP : ')';
OP : '(';
ID : [a-zA-Z_]+;
NUM : INT | FLOAT;
INT : [0-9]+ ;
FLOAT : INT '.' INT;
SUM : '+' ;
SUB : '-' ;
MULT: '*' ;
DIV : '/' ;
POW : '^' ;
COMMENT: '//' ~[\n]+ -> skip;
WS : [ \n]+ -> skip ;