-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNomos.g4
More file actions
156 lines (124 loc) · 2.58 KB
/
Nomos.g4
File metadata and controls
156 lines (124 loc) · 2.58 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
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
grammar Nomos;
spec
: import_ input_* vars_* precondition* output* program vars_* postcondition*
;
import_
: 'import ' dataset=('german_credit' | 'compas' | 'mnist' | 'speech_command' | 'hotel_review' | 'lunar' | 'bipedal' | 'transpiler') SEMICOLON
;
input_
: INPUT inp=inpvar SEMICOLON
;
output
: OUTPUT out=outvar SEMICOLON
;
vars_
: VARKW assignment SEMICOLON
;
program
: prog=PROGRAM
;
assignment
: left=record ASS right_rec=record
| left=record ASS right_math=math
;
precondition
: REQUIRES expr SEMICOLON
;
postcondition
: ENSURES expr SEMICOLON
;
expr
: NOT expr # exprNot
| LBR expr RBR # exprPrn
| left=expr (AND | OR | IMPL) right=expr # exprBinary
| left=math op=cmpOp right=math # exprPred
| record # exprRec
;
record
: NUM # recNum
| STRING # recStr
| NULL # recNull
| EMPTYSTR # recEmptyStr
| ( inpvar | outvar | commonvar) # recVar
| feature # recFtr
| func=FUNC LBR params=funcParam RBR # recFunc
| var=inpvar '.' ftr=feature # recVarFtr
| var=inpvar (LSBR assignment RSBR)+ # recFtrAss
;
math
: LBR math RBR # mathPrn
| left=math (PLUS | MINUS | MULT | DIV) right=math # mathBinary
| record # mathRec
;
funcParam
: param=record
| param=record COMMA funcParam
;
cmpOp
: LSQ
| GRQ
| LSS
| GRT
| EQL
| NEQ
;
commonvar
: 'v' NUM
;
inpvar
: ('x'|'s') NUM
;
outvar
: ('d'|'o') NUM
;
feature
: 'f' NUM # llvlFeature
| ( 'pos' | 'neg' ) # hlvlFeature
;
PROGRAM :
LCBR
.*?
RCBR
;
INPUT : 'input';
OUTPUT : 'output' ;
VARKW : 'var' ;
REQUIRES : 'requires' ;
ENSURES : 'ensures' ;
NULL : 'null' ;
// WATCHOUT: keywords have to come before this
// https://github.com/antlr/antlr4/blob/master/doc/predicates.md#predicates-in-lexer-rules
FUNC : [A-Za-z]+ ;
PLUS : '+' ;
MINUS : '-' ;
MULT : '*' ;
DIV : '/' ;
NUM : '-'?[0-9]+ ('.' [0-9]+)? ([eE] [+-]? [0-9]+)? ;
EMPTYSTR : '""' ;
STRING
: '"' [A-Za-z]+ '"'
| '\'' [A-Za-z]+ '\''
;
LCBR : '{' ;
RCBR : '}' ;
LSBR : '[' ;
RSBR : ']' ;
LBR : '(' ;
RBR : ')' ;
LSS : '<' ;
LSQ : '<=' ;
GRT : '>' ;
GRQ : '>=' ;
EQL : '==' ;
NEQ : '!=' ;
AND : '&&' ;
OR : '||' ;
NOT : '!' ;
IMPL: '==>' ;
ASS : ':=' ;
// SAMPLE : '~' ;
COMMA : ',' ;
SEMICOLON : ';' ;
WS : [ \t\r\n]+ -> skip ;
COMMENT : '/*' .*? '*/' -> skip ;
LINE_COMMENT : '//' ~[\r\n]* -> skip ;