-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoolParser.g4
More file actions
59 lines (42 loc) · 1.56 KB
/
Copy pathPoolParser.g4
File metadata and controls
59 lines (42 loc) · 1.56 KB
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
parser grammar PoolParser;
options {
language=Cpp;
tokenVocab=PoolLexer;
}
program: statement* EOF;
statement: expression? SEMI;
expression: a=assignment | c=call;
assignment returns [enum Type {V,C} type]:
assignee=access EQ value=call {$type=AssignmentContext::V;} |
assignee=access CEQ value=call {$type=AssignmentContext::C;};
access returns [enum Type {G,L,I} type]:
callee=call DOT ID {$type=AccessContext::G;} |
callee=call DOTDOT ID {$type=AccessContext::L;} |
ID {$type=AccessContext::I;};
call returns [enum Type {IA,ILA,A,T} type]:
callee=call DOT ID a=args? {$type=CallContext::IA;} |
callee=call DOTDOT ID a=args? {$type=CallContext::ILA;} |
callee=call a=args {$type=CallContext::A;} |
term {$type=CallContext::T;};
args: LP arg? (COMMA arg)* RP;
arg: DOTS? call;
term returns [enum Type {NUM,STR,FUN,PAR,BLK,ARR,NSM,IDT} type]:
num {$type=TermContext::NUM;} |
string {$type=TermContext::STR;} |
fun {$type=TermContext::FUN;} |
par {$type=TermContext::PAR;} |
block {$type=TermContext::BLK;} |
array {$type=TermContext::ARR;} |
NATIVE_SYMBOL {$type=TermContext::NSM;} |
ID {$type=TermContext::IDT;};
par: LP expression RP;
block: LB statement* RB;
array: LSB arg? (COMMA arg)* RSB;
fun: LP param? (COMMA param)* RP COLON LB statement* RB;
param: DOTS? name=ID (COLON type=ID)?;
num returns [enum Type {DEC,HEX,BIN,FLT} type]:
DECIMAL_INTEGER_LITERAL {$type=NumContext::DEC;} |
HEX_INTEGER_LITERAL {$type=NumContext::HEX;} |
BIN_INTEGER_LITERAL {$type=NumContext::BIN;} |
FLOAT_LITERAL {$type=NumContext::FLT;};
string: STRING_LITERAL;