1

For this grammar:

A -> B a | A a | c
B -> B b | A b | d

How to remove the left recursion?

====== My attempts ======

  1. Eliminate direct left_rec first.
A -> (B a | c) A'
A' -> a A' | ε
B -> (A b | d) B'
B' -> b B' | ε
  1. Then indirect. Put B into A.

A -> A b B' a A ' | d B' A' | c A'

And then I got:

A -> (d B A' | c A') A''
A' -> a A' | ε
A'' -> b B' a A' A'' | ε

This result is quite complicated. How can I use only one A' to represent this?

z0gSh1u
  • 355
  • 3
  • 6
  • 1
    For this relatively simple grammar, you can try to understand the language it generates, and then create a new grammar for the language using only right recursion. If you're having trouble understanding the language, try generating a bunch of strings and seeing what you get. – jirassimok Jan 08 '20 at 01:37

0 Answers0