-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfoyacc.mly
184 lines (169 loc) · 3.32 KB
/
foyacc.mly
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
%{
open Fotypes;;
let rec introduceVars vlist form = match vlist with
| head::tail -> introduceVars tail ( Fofunctions.subst form (Constant(head)) (Variable(head)) )
| [] -> form
;;
(* checks whether a string represents a variable *)
let isVariable str = (Fofunctions.isUpper (str.[0]))
;;
%}
%token TOK_EOF
%token <string> TOK_IDENT
%token TOK_LPAR
%token TOK_RPAR
%token TOK_LBRACKET
%token TOK_RBRACKET
%token TOK_NOT
%token TOK_CONJ
%token TOK_DISJ
%token TOK_IMPL
%token TOK_EQUIV
%token TOK_COMMA
%token TOK_FORALL
%token TOK_EXISTS
%token TOK_ALWAYS
%token TOK_ALWAYSP
%token TOK_SOMETIME
%token TOK_SOMETIMEP
%token TOK_NEXT
%token TOK_UNTIL
%token TOK_TRUE
%token TOK_FALSE
%token TOK_UNLESS
%left TOK_UNTIL
%left TOK_UNLESS
%left TOK_EQUIV
%left TOK_DISJ
%left TOK_IMPL
%left TOK_CONJ
%left TOK_NOT Quantification
%left TOK_SOMETIME
%left TOK_ALWAYS
%left TOK_NEXT
%start start
%type <Fotypes.formula> start
%%
start: formula TOK_EOF
{
$1;
}
formula: atom {$1}
| quantified {$1}
| connective {$1}
;
atom: TOK_IDENT
{
Literal(Atom($1,[]))
}
| TOK_IDENT TOK_LPAR termlist TOK_RPAR
{
Literal(Atom($1,$3))
}
;
quantified: TOK_FORALL boundvars formula %prec Quantification
{
let f = introduceVars $2 $3 in
Forall($2, f)
}
| TOK_EXISTS boundvars formula %prec Quantification
{
let f = introduceVars $2 $3 in
Exists($2, f)
}
;
boundvars: TOK_LBRACKET varlist TOK_RBRACKET
{
$2
}
varlist: TOK_IDENT
{
if not (isVariable $1)
then
(print_string ($1^ " is not uppercase\n");
raise Parsing.Parse_error;
(* return any string *)
["nonesense"])
else
[$1]
}
| TOK_IDENT TOK_COMMA varlist
{
$1::$3
}
;
connective: TOK_TRUE
{
True
}
| TOK_FALSE
{
False
}
| TOK_NOT formula
{
Not($2)
}
| formula TOK_CONJ formula
{
And($1,$3)
}
| formula TOK_DISJ formula
{
Or($1,$3)
}
| formula TOK_IMPL formula
{
Implies($1,$3)
}
| formula TOK_EQUIV formula
{
And(Implies($1,$3),Implies($3,$1))
}
| TOK_ALWAYS formula
{
Always($2)
}
| TOK_ALWAYSP formula
{
AlwaysP($2)
}
| TOK_SOMETIME formula
{
Sometime($2)
}
| TOK_SOMETIMEP formula
{
SometimeP($2)
}
| TOK_NEXT formula
{
Next($2)
}
| formula TOK_UNTIL formula
{
Until($1, $3)
}
| formula TOK_UNLESS formula
{
Unless($1, $3)
}
| TOK_LPAR formula TOK_RPAR
{
$2;
}
;
termlist: term
{
[$1]
}
| term TOK_COMMA termlist
{
$1::$3
}
;
term: TOK_IDENT
{
Constant($1)
}
;