-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemo.g4
More file actions
36 lines (29 loc) · 647 Bytes
/
Demo.g4
File metadata and controls
36 lines (29 loc) · 647 Bytes
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
grammar Demo;
program: subroutine+;
subroutine: 'sub' ID '{' body '}';
body: statement+;
statement: print | read | gosub | assign | halt | biz | bgz;
print: 'print' expr ';';
read: 'read' ID ';';
gosub: 'gosub' ID ';';
assign: ID '=' expr ';';
halt: 'halt' ';';
biz: 'biz' expr ID ';';
bgz: 'bgz' expr ID ';';
expr:
expr op = ('*' | '/') expr # MulDiv
| expr op = ('+' | '-') expr # AddSub
| ID # Id
| NUMBER # Number
| STRING # String
| '(' expr ')' # Parens;
NUMBER: [0-9]+;
ID: [a-zA-Z][a-zA-Z0-9]*;
STRING: '"' .*? '"';
ADD: '+';
SUB: '-';
MUL: '*';
DIV: '/';
LPAREN: '(';
RPAREN: ')';
WS: [ \t\r\n]+ -> skip;