How would I eliminate the left recursion in this CFG?
<RE> -> <RE>'|'<CONCAT> | <CONCAT>
<CONCAT> -> <CONCAT><KLEEN> | <KLEEN>
<KLEEN> -> <KLEEN>'*' | <ELEM>
<ELEM> -> 'a' | 'b' | 'c' | 'd' | '('<RE>')'
I came up with this:
<RE> -> <CONCAT><re>
<re> -> '|'<CONCAT><re> | (e)
<CONCAT> -> <KLEEN><concat>
<concat> -> <KLEEN><concat> | (e)
<KLEEN> -> <ELEM><kleen>
<kleen> -> '*'<kleen> | (e)
<ELEM> -> 'a' | 'b' | 'c' | 'd' | '('<RE>')'
But it seems that, when I try to implement this as a recursive descent parser & parse simple strings such as "ab", I get an infinite loop caused by the concat
production.
Am I eliminating the left recursion incorrectly?