-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwoeighty.g4
51 lines (42 loc) · 1.52 KB
/
twoeighty.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
47
48
49
50
51
grammar twoeighty;
program : variableDec* loop (statement ';')*;
variableDec : ID '=' value ';';
loop : INT unit=('ms'|'s') ':';
statement : clear
| colour
| shape
| increment
| decrement
| variableAssign;
clear : 'clr' | 'clear';
colour : ('colour' | '#') COLOUR;
shape : rectangle | circle | line | arc ;
rectangle : ('rect' | 'r') x=value ',' y=value ',' w=value ',' h=value;
circle : ('circle' | 'c') x=value ',' y=value ',' r=value;
line : ('line' | 'l') x1=value ',' y1=value ',' x2=value ',' y2=value;
arc : ('arc' | 'a') x1=value ',' y1=value ',' x2=value ',' y2=value ',' cx=value ',' cy=value;
increment : ID '++';
decrement : ID '--';
variableAssign : ID '=' value;
value : l=value op r=value #Binop
| funccall '(' value (',' value)* ')' #MathFunc
| '%' #Thousand
| ID #Variable
| INT #Integer;
op : '/'
| '//'
| '*'
| '+'
| '-'
| '%'
;
funccall : 'sin'
| 'cos'
| 'tan'
| 'pow'
| 'rand'
| 'abs'
;
ID : [a-z];
INT : ('-')? [0-9]+;
COLOUR : [0-9a-z]+;