-
Notifications
You must be signed in to change notification settings - Fork 0
/
propParser.mly
48 lines (42 loc) · 877 Bytes
/
propParser.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
%{
open PropAst
%}
(* Tokens to be used in parsing. Support exists for:
* 1. Parentheses
* 2. NOT (~)
* 3. AND (/\)
* 4. OR (\/)
* 5. IMPLIES (=>)
* 6. FALSE (false)
* 7. ATOM (P,Q,etc.)
*)
%token LPAREN
%token RPAREN
%token NOT
%token AND
%token OR
%token IMPLIES
%token FALSE
%token <string> ATOM
%token EOF
(* Assigns precedence and associativity to the propositional terms. *)
%right IMPLIES
%left OR
%left AND
%nonassoc NOT
(* Starts parsing the language. *)
%start <PropAst.prop> prog
%%
(* Rules of propositional logic. *)
prog:
| p = prop; EOF { p }
;
prop:
| LPAREN; p = prop; RPAREN { p }
| NOT; p = prop { Not p }
| p1 = prop; AND; p2 = prop { And (p1,p2) }
| p1 = prop; OR ; p2 = prop { Or (p1,p2) }
| p1 = prop; IMPLIES; p2 = prop { Implies (p1,p2) }
| s = ATOM { Atom s }
| FALSE { False }
;