0

In this old exam-question I need to convert a grammar to CNF, but I suspect the provided solution is wrong.

Grammar:

S -> aAB|a|aA|aB|AbB|b|Ab|bB
A -> aA|a|cC|c
B -> bB|b|dD|d
C -> cC|c
D -> dD|d

In the first step I set variables for the four terminals:

V -> a
X -> b
Y -> c
Z -> d

In the second step I replace the terminals with the variables(only the productions in S for now):

S -> VAB|a|VA|VB|AXB|AX|XB

In the third step I replace AB in VAB with U -> AB so I get:

S -> VU|a|VA|VB|AXB|AX|XB

In the solution, I don't understand what's happening with the S-productions AbB and bB(which I have set to AXB and XB). This is the provided answer for the S-productions:

S → VU|a|VA|VB|UX|b|AX|BX

How come AbB is set to UX and bB to BX? Should not bB be set to XB at least?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
TheEagle
  • 117
  • 2
  • 8
  • As you say, `AbB` does not transform into `UX` since `Ab` does not transform into `U`. And likewise, `bB` does not transform into `BX`, but rather `XB` as you also say. – sshine Jun 27 '14 at 13:43
  • Why is the lone `a` not mapped to `V` in the second step? – Jonathan Leffler Jun 27 '14 at 14:18
  • "Why is the lone a not mapped to V in the second step?" Not sure. Because that would be a unit-production? – TheEagle Jun 27 '14 at 14:26
  • @JonathanLeffler: In CNF, all productions are either `T→UV` or `T→a` (`TUV` non-terminals, `a` terminal). `T→U` is not allowed. So pre-existing unit productions are not modified. `T→aU` isn't allowed, so it's necessary to introduce a unit production for `a`. – rici Jun 27 '14 at 15:12
  • @rici: OK — thanks. You can tell that CNF was not part of my training. – Jonathan Leffler Jun 27 '14 at 15:13

0 Answers0