0

I am trying to write a grammar for propositional logic for the purpose of creating a LL parser (lexical analysis).

I tried the following grammar:

F = F and F
F = F or F 
F = F => F
F = F <=> F
F = not F
F = (F)
D = a

but I discovered that it is ambiguous. I tried the following to remove the ambiguity:

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

Is this grammar correct? Was I successful in removing the ambiguity?

halm helmi
  • 11
  • 4

1 Answers1

0

The grammar is still ambiguous. Here are two derivations for not a and a:

Derivation 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

Derivation 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

You need to put parentheses around your derivations, e.g. F = (F and A)

Another possibility if you don't want to use parentheses is to use prefix notation.

tomkot
  • 926
  • 5
  • 7