blob: a13a80ff38aac7c3418a8f3e8546691671997f73 (
plain)
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
|
grammar Query;
prog: stat+ EOF? ;
stat: expr # rawExpr
| ID '=' expr # assign
;
expr: expr '.' ID # access
| expr '(' (args=expr*) ')' # call
| expr op=('*'|'/') expr # MulDiv
| expr op=('+'|'-') expr # AddSub
| INT # int
| STRINGLITERAL # string
| ID # id
| '(' expr ')' # parens
| '{' (args=arguments)? prog '}' # func
;
arguments: ID (',' ID)* '->';
STRINGLITERAL : '"' ( StringEscapeSeq | ~( '\\' | '"' | '\r' | '\n' ) )* '"' ;
StringEscapeSeq : '\\' ( 't' | 'n' | 'r' | '"' | '\\' | '$' | ('0'..'9')) ;
MUL : '*' ; // assigns token name to '*' used above in grammar
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' -> skip ; // return newlines to parser (is end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace
|