-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-654.py
70 lines (58 loc) · 1.24 KB
/
parse-654.py
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
forall = '∀'
exists = '∃'
mp = '→'
land = '∧'
lor = '∨'
lnot = '¬'
liff = '↔'
def checkFormula(fmla):
r0 = [*fmla]
r0.reverse()
r1 = ['F']
while r0 != []:
print(r0,r1)
if r0[-1] in [forall,exists]:
if r1[-1] == 'F':
r1.append('V')
else:
print("Not a formula due to",r0[-1])
break
if r0[-1] in ['x','a','y','c','0','1']: # add more single-symbol variables and constants as needed
if r1[-1] == 'V' or r1[-1] == 'T':
r1.pop()
if r0[-1] == lnot:
if r1[-1] == 'F':
pass
else:
print("Not a formula due to",r0[-1])
break
if r0[-1] in [mp,land,lor,liff]:
if r1[-1] == 'F':
r1.append('F')
else:
print("Not a formula due to",r0[-1])
break
if r0[-1] == '=':
if r1[-1] == 'F':
r1.pop()
r1.append('T')
r1.append('T')
else:
print("Not a formula due to",r0[-1])
break
if r0[-1] == '+' or r0[-1] == '*':
if r1[-1] == 'T':
r1.append('T')
else:
print("Not a formula due to",r0[-1])
break
r0.pop()
fmla = '∀x∀y→=+ax+ay=xy'
checkFormula(fmla)
fmla = '∀x∀y→*ax*ay=xy'
checkFormula(fmla)
fmla = '∀x∀y→=x*ay=xy'
checkFormula(fmla)
fmla = '∀x∀y→=*ax*ay=x*aa'
checkFormula(fmla)
checkFormula([forall,forall])