-
Notifications
You must be signed in to change notification settings - Fork 0
/
raa_tt.par
70 lines (54 loc) · 1004 Bytes
/
raa_tt.par
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
%start RaaTt
%title "RaaTt grammar"
%comment "Grammar to define expressions in propositional calculus"
%line_comment "//"
%%
Not : '!'
;
And : '&'
;
Or : '|'
;
Cond: '->'
;
BiCond
: '<->'
;
LPar: '('
;
RPar: ')'
;
Var : /[a-z][_a-zA-Z0-9]*/
;
// We use some operator precedence rules which are commonly used in propositional calculus to reduce
// the number of parentheses needed.
// Also the top level expression doesn't need to be set in parentheses.
// Highest to lowest:
// * Negation
// * Conjunction
// * Disjunction
// * Conditional (Implication)
// * Biconditional (BiImplication)
RaaTt
: { Biconditional }
;
Biconditional
: Conditional { BiCond^ Conditional }
;
Conditional
: Disjunction { Cond^ Disjunction }
;
Disjunction
: Conjunction { Or^ Conjunction }
;
Conjunction
: Factor { And^ Factor }
;
Negation
: Not^ Factor
;
Factor
: Var
| Negation
| LPar^ Biconditional RPar^
;