-
Notifications
You must be signed in to change notification settings - Fork 0
/
hornParse.mly
147 lines (120 loc) · 3.62 KB
/
hornParse.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
%{
module A = Ast
module So = A.Sort
module Sy = A.Symbol
module E = A.Expression
module P = A.Predicate
module H = A.Horn
module Su = A.Subst
module C = FixConstraint
let parse_error msg =
Errorline.error (symbol_start ()) msg
%}
%token <string> Var
%token <string> Id
%token <int> Num
%token BEXP
%token TRUE FALSE
%token LPAREN RPAREN LB RB LC RC
%token EQ NE GT GE LT LE
%token AND OR NOT IMPL FORALL SEMI COMMA COLON DOT
%token EOF
%token PLUS
%token MINUS
%token TIMES
%token DIV
%token HC
%right PLUS
%right MINUS
%right TIMES
%right DIV
%start horns
%type <A.pred list> preds, predsne
%type <A.pred> pred
%type <A.expr list> exprs, exprsne
%type <A.expr> expr
%type <A.brel> brel
%type <A.bop> bop
%type <H.pr> pr
%type <H.gd> guard
%type <H.gd list> guards, guardsne
%type <Ast.Horn.t> hc
%type <Ast.Horn.t list> horns
%%
preds:
LB RB { [] }
| LB predsne RB { $2 }
;
predsne:
pred { [$1] }
| pred SEMI predsne { $1 :: $3 }
;
pred:
TRUE { A.pTrue }
| FALSE { A.pFalse }
| BEXP expr { A.pBexp $2 }
| AND preds { A.pAnd ($2) }
| OR preds { A.pOr ($2) }
| NOT pred { A.pNot ($2) }
| pred IMPL pred { A.pImp ($1, $3) }
| expr brel expr { A.pAtom ($1, $2, $3) }
| LPAREN pred RPAREN { $2 }
;
exprs:
LB RB { [] }
| LB exprsne RB { $2 }
;
exprsne:
expr { [$1] }
| expr SEMI exprsne { $1 :: $3 }
;
expr:
Id { A.eVar (Sy.of_string $1) }
| Num { A.eCon (A.Constant.Int $1) }
| MINUS Num { A.eCon (A.Constant.Int (-1 * $2)) }
| MINUS LPAREN expr RPAREN { A.eBin (A.zero, A.Minus, $3) }
| expr bop expr { A.eBin ($1, $2, $3) }
| Id LPAREN exprs RPAREN { A.eApp ((Sy.of_string $1), $3) }
| LPAREN expr RPAREN { $2 }
;
brel:
EQ { A.Eq }
| NE { A.Ne }
| GT { A.Gt }
| GE { A.Ge }
| LT { A.Lt }
| LE { A.Le }
;
bop:
PLUS { A.Plus }
| MINUS { A.Minus }
| TIMES { A.Times }
| DIV { A.Div }
;
idsne:
Id { [$1] }
| Id COMMA idsne { $1 :: $3 }
;
pr:
Var LPAREN RPAREN { ($1, []) }
| Var LPAREN idsne RPAREN { ($1, $3) }
| Var { ($1, []) }
;
guard:
pr { H.K ($1) }
| pred { H.C ($1) }
;
guards:
LB RB { [] }
| LB guardsne RB { $2 }
;
guardsne:
guard { [$1] }
| guard COMMA guardsne { $1 :: $3 }
;
hc:
HC LPAREN pr COMMA guards RPAREN DOT {($3, $5)}
;
horns:
{ [] }
| hc horns { $1 :: $2 }