0

Suppose we have the following CFG:

A → Bd
B → dA|a|ɛ

Now if I try to calculate FIRST and FOLLOW sets, I think I can get it done as follows:

First(A) = { d, a }
First(B) = { d, a, ɛ }

FOLLOW(A) = { d, $ }
FOLLOW(B) = { d }

And the parser table must be this:

+---+--------+------------------+---+
|   |    a   |         d        | $ |
+===+========+==================+===+
| A | A → Bd |      A → Bd      |   |
+---+--------+------------------+---+
| B |  B → a | B → dA and B → ɛ |   |
+---+--------+------------------+---+

Now we have multiple entries for our table.
What is the correct way to build an LL(1) parsing table for this grammar?

M0B
  • 49
  • 4
  • You say `FOLLOW(A) = { d, a }`. That means there is some sentential form containing `...Ad...`, and another one containing `...Aa...`. What are these sentential forms, and how are they derived? (Asking for a friend, as they say.) – rici Jul 19 '20 at 21:25
  • Yes, you're right sir. I changed it. – M0B Jul 19 '20 at 22:17
  • 1:A→Bd (replace B with dA) 2:A→dAd – M0B Jul 19 '20 at 22:26
  • Ok, so you have a real LL(1) conflict. Are you supposed to fix the grammar? Because the parsing table reflects the grammar. (It should have at least one `$` entry, though: you're still missing the `$` in FOLLOW(A), assuming `A` is the start symbol.) – rici Jul 19 '20 at 22:37
  • I supposed to either fix it or give a proof to show that it can't be converted to LL(1) grammar. – M0B Jul 19 '20 at 22:51

0 Answers0