0

I have a problem with this exercise. This is the LALR(1) parsing table for the grammar G. How can i get the productions of G?

LALR(1) Parsing Table

Thanks :)

  • I don't believe you can, in general. – orlp Jan 08 '19 at 10:22
  • I agree with you, but this was an exercise from an exam of Formal Languages and Compilers of my university... – Daniel Dissegna Jan 08 '19 at 10:25
  • @orlp: https://cs.stackexchange.com/questions/51658/how-to-convert-pda-to-cfg – rici Jan 08 '19 at 15:13
  • Technically, you could prove equivalence without a constructive proof but the constructive proof is available. – rici Jan 08 '19 at 15:15
  • @rici The OP asks for the production rules of grammar $G$, not an arbitrary one of the language it generates. – orlp Jan 08 '19 at 18:52
  • @rici Furthermore, we don't have a PDA. We have a LALR(1) parsing table. Note that in state 3 on input $a$ we have to reduce by rule 2. We don't know what rule 2 is or what symbol it reduces to. – orlp Jan 08 '19 at 18:56
  • @orlp: rule 2 is $A\to b$. You can get to state 3 from the start state by reading $b$, so that's the only thing on the rhs. Deducing the $A$ would be more work if there were more non-terminals. I'm not sure that it's really accurate to say this is an LALR(1) table since it includes shift/reduce conflicts but the fact that it was produced by the LALR algorithm probably helps deduce what it was produced from. It's certain that not every parsing table $T$ can be turned into a CFG for which the LALR algorithm would produce $T$, but you can always turn it into a CFG which will recognize... – rici Jan 08 '19 at 21:56
  • ...the same language (because it is equivalent to a PDA), which I think is an interesting fact. – rici Jan 08 '19 at 21:57

0 Answers0