-
Notifications
You must be signed in to change notification settings - Fork 0
/
V.g4
249 lines (197 loc) · 6.15 KB
/
V.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
grammar V;
/*
* Spec Rules
*/
spec : behavioralSpec EOF
| testSpec EOF
| tempSpec EOF
| invariantSpec EOF
| synthSpec EOF
;
behavioralSpec : imports varsSection? precondSection? postcondSection
;
testSpec : imports varsSection? initSection? specSection
;
tempSpec : imports varsSection? ltlFairnessSection? ltlPropertySection
;
invariantSpec : imports varsSection? invariantSection
;
synthSpec : imports varsSection? initSection? synthSection
;
imports : IMPORT PATH imports
| /*epsilon*/
;
/*
* Section Rules
*/
varsSection : VARS_LABEL declList
;
precondSection : PRECOND_LABEL atom
;
postcondSection : POSTCOND_LABEL atom
;
initSection : INIT_LABEL seqAtom
;
specSection : SPEC_LABEL seqAtom
;
synthSection : SYNTH_LABEL atom
;
ltlFairnessSection : LTLFAIR_LABEL smartltlAtom
;
ltlPropertySection : LTLPROP_LABEL smartltlAtom
;
invariantSection : INV_LABEL invAtom
;
/*
* Sequence of atoms
*/
seqAtom : atom
| atom SEQ seqAtom
;
/*
* Variable Section Rules
*/
declList : typ ident
| typ ident COMMA declList
;
typ : IDENTIFIER
| IDENTIFIER LBRACK RBRACK
;
/*
* SmartLTL Rules
*/
smartltlAtom : atom
| LPAREN smartltlAtom RPAREN
| T_UN smartltlAtom
| L_UN smartltlAtom
| LBRACK RBRACK smartltlAtom
| smartltlAtom T_BIN smartltlAtom
| smartltlAtom IMP smartltlAtom
| smartltlAtom SEQ smartltlAtom
| smartltlAtom L_BIN smartltlAtom
;
invAtom : atom
| CONTRACT_INV LPAREN varAccess COMMA constraint RPAREN
| CONTRACT_INV LPAREN varAccess COMMA constraint PRE_SEP constraint RPAREN
;
atom : ATOM_PRE_LOC LPAREN atomFn COMMA constraint RPAREN
| ATOM_PRE_LOC LPAREN atomFn RPAREN
| ATOM_POST_LOC LPAREN atomFn COMMA constraint PRE_SEP constraint RPAREN
| ATOM_POST_LOC LPAREN atomFn COMMA constraint RPAREN
| ATOM_POST_LOC LPAREN atomFn RPAREN
| LET ident ASSN constraint
| LET ident ASSN arithExpr
| LET ident LPAREN params RPAREN ASSN constraint
| LET ident LPAREN params RPAREN ASSN arithExpr
| FOREACH LPAREN ident IN ident COMMA atom RPAREN
| SENT LPAREN constraint RPAREN
| LPAREN atom RPAREN
| L_UN atom
| atom L_BIN atom
;
atomFn : atomFnName
| atomFnName LPAREN params RPAREN
;
atomFnName : varAccess DOT ident
| varAccess DOT WILDCARD
;
params : ident
| ident COMMA params
| NUM
| NUM COMMA params
| /*epsilon*/
;
constraint : boolExpr
| LPAREN constraint RPAREN
| constraint L_BIN constraint
| constraint IMP constraint
;
boolExpr : varOrNum
| L_UN boolExpr
| LPAREN boolExpr RPAREN
| arithExpr C_BIN arithExpr
| arithExpr C_BIN arithExpr EXCEPT argList
;
arithExpr : varOrNum
| A_UN arithExpr
| LPAREN arithExpr RPAREN
| arithExpr A1_BIN arithExpr
| arithExpr WILDCARD arithExpr
| arithExpr A2_BIN arithExpr
| arithExpr A_UN arithExpr
;
fnCall : FSUM LPAREN atomFn COMMA varOrNum COMMA constraint RPAREN
| fnName LPAREN argList RPAREN
;
fnName : fnName LPAREN argList RPAREN DOT ident
| fnName LBRACK arithExpr RBRACK DOT ident
| fnName DOT ident
| ident
;
argList : constraint
| arithExpr
| arithExpr COMMA argList
| constraint COMMA argList
| /*epsilon*/
;
ident : IDENTIFIER
| ATOM_PRE_LOC
| ATOM_POST_LOC
;
varOrNum : varAccess
| num
;
num : NUM
;
varAccess : ident
| fnCall
| varAccess LBRACK arithExpr RBRACK
| varAccess DOT ident
;
/*
* Lexer Rules
*/
LPAREN : '(' ;
RPAREN : ')' ;
LBRACK : '[' ;
RBRACK : ']' ;
COMMA : ',' ;
SENT : 'sent' ;
FSUM : 'fsum' ;
WILDCARD : '*' ;
DOT : '.' ;
SEQ : ';' ;
ASSN : ':=' ;
LET : 'let' ;
FOREACH : 'foreach' ;
IN : ':' ;
IMPORT : 'import:' ;
EXCEPT : 'except' ;
VARS_LABEL : ('Vars:' | 'vars:' | 'Variables:' | 'variables:') ;
PRECOND_LABEL : ('Pre:' | 'pre:'| 'Preconditions:' | 'preconditions:') ;
POSTCOND_LABEL : ('Post:' | 'post:' | 'Postconditions:' | 'postconditions:') ;
INIT_LABEL : ('Init:' | 'init:' | 'Assume:' | 'assume:') ;
SPEC_LABEL : ('Spec:' | 'Specification:' | 'spec:' | 'specification:' | 'Assert:' | 'assert:') ;
SYNTH_LABEL: ('Synth:' | 'Synthesize:' | 'synth:' | 'synthesize:') ;
LTLFAIR_LABEL : 'LTLFairness:' ;
LTLPROP_LABEL : 'LTLProperty:' ;
INV_LABEL : ('Inv:' | 'inv:' | 'Invariant:' | 'invariant:') ;
ATOM_PRE_LOC : ('started' | 'reverted' | 'willSucceed' | 'revertedIff') ;
ATOM_POST_LOC : ('executed' | 'finished') ;
CONTRACT_INV : 'Cinv' ;
PRE_SEP : '|=>' ;
IMP : '==>' ;
T_BIN : ('U' | 'R') ; // also includes ';' and '==>' but already specified above
T_UN : ('<>' | 'X') ; // also includes '[]' but necessary in types also so specified above
PATH : '"'[@./][a-zA-Z0-9/._\-]+'"' ;
IDENTIFIER : [a-zA-Z_][a-zA-Z_0-9]* ;
A_UN : '-';
A1_BIN : ('*' | '/') ;
A2_BIN : ('+' | '-') ;
C_BIN : ('=' | '!=' | '<' | '>' | '<=' | '>=') ;
L_BIN : ('&&' | '||') ;
L_UN : '!' ;
NUM : ([0-9]+ | [0-9]+ 'e' [0-9]+) ;
NEWLINE : ('\r'? '\n' | '\r')+ -> skip ;
WHITESPACE : (' ' | '\t') -> skip ;
LINE_COMMENT : '#' ~[\r\n]* -> skip ;