我正在尝试为命题逻辑编写一个语法,以便创建一个LL解析器(词法分析)。
我尝试了以下语法:
F = F and F
F = F or F
F = F => F
F = F <=> F
F = not F
F = (F)
D = a
但我发现它含糊不清。我尝试了以下方法来消除歧义:
F = F and A
F = A
A = F or B
A = B
B = F => C
B = C
C = F <=> C
C=D
D = not F
D = (F)
D = a
这个语法是否正确?我是否成功消除了歧义?
答案 0 :(得分:0)
语法仍然含糊不清。这是两个推导 不是a和a:
派生1:
F
F and A
A and A
B and B
C and C
not F and a
not A and a
not B and a
not C and a
not D and a
not a and a
派生2:
F
A
B
C
D
not F
not F and A
not A and A
not B and B
not C and C
not D and D
not a and a
你需要在你的派生词周围添加括号,例如: F =(F和A)
如果您不想使用括号,另一种可能性是使用prefix notation。