-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathRJ.g4
More file actions
102 lines (78 loc) · 1.67 KB
/
RJ.g4
File metadata and controls
102 lines (78 loc) · 1.67 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
grammar RJ;
prog: start | ;
start:
pred #startPred
| alias #startAlias
| ghost #startGhost
;
pred:
'(' pred ')' #predGroup
| '!' pred #predNegate
| pred LOGOP pred #predLogic
| pred '?' pred ':' pred #ite
| exp #predExp
;
exp:
'(' exp ')' #expGroup
| exp BOOLOP exp #expBool
| operand #expOperand
;
operand:
literalExpression #opLiteral
| operand ARITHOP operand #opArith
| operand '-' operand #opSub
| '-' operand #opMinus
| '!' operand #opNot
| '(' operand ')' #opGroup
;
literalExpression:
'(' literalExpression ')' #litGroup
| literal #lit
| ID #var
| ID '.' functionCall #targetInvocation
| functionCall #invocation
;
functionCall:
ghostCall
| aliasCall;
ghostCall:
ID '(' args? ')';
aliasCall:
ID_UPPER '(' args? ')';
args: pred (',' pred)* ;
literal:
BOOL
| STRING
| INT
| REAL
| NULL;
//----------------------- Declarations -----------------------
alias:
'type'? ID_UPPER '(' argDeclID ')' '{' pred '}';
ghost:
'ghost'? type ID ('(' argDecl? ')')?;
argDecl:
type ID? (',' argDecl)?;
argDeclID:
type ID (',' argDeclID)?;
type:
'int'
| 'double'
| 'float'
| 'boolean'
| ID_UPPER
| OBJECT_TYPE
| type '[]';
LOGOP : '&&'|'||'| '-->';
BOOLOP : '=='|'!='|'>='|'>'|'<='|'<';
ARITHOP : '+'|'*'|'/'|'%';//|'-';
BOOL : 'true' | 'false';
NULL : 'null';
ID_UPPER: ([A-Z][a-zA-Z0-9]*);
OBJECT_TYPE:
(([a-zA-Z][a-zA-Z0-9]+) ('.' [a-zA-Z][a-zA-Z0-9]*)+);
ID : '#'*[a-zA-Z_][a-zA-Z0-9_#]*;
STRING : '"'(~["])*'"';
INT : (([0-9]+) | ([0-9]+('_'[0-9]+)*));
REAL : (([0-9]+('.'[0-9]+)?) | '.'[0-9]+);
WS : (' '|'\t'|'\n'|'\r')+ -> channel(HIDDEN);