I have a list of productions. There are several instances of left recursion in it. I'm having trouble eliminating them even after reading my notes and the textbook on it.
*Production* (With AST definition)
MuMu-program: declaration-list; stmt-seq {Mumuprog l: id r: stmt}
stmt:
id := expr {assstmt l: id r: expr}
if expr then stmt {ifstmt l: exp r: stmt }
if expr then stmt else stmt { iftmt l: expr c: stmt r:stmt }
for id := expr to expr do stmt {forstmt l: expr c:expr r: stmt}
break {brkstmt}
null {nullstmt}
stmt-seq:
stmt-seq; stmt { stmt r: stmt}
stmt { stmt }
expr:
integer-constant { expr }
id { expr }
( expr ) { expr }
- expr { expr }
expr binary-operator expr { op l: expr r: expr}
null:
declaration-list:
var id-seq {id r: id}
id-seq:
id { id }
id-seq, id { id r: id }
I get that Mumu-Program: declaration-list; stmt-seq is the start.
I step into declaration-list: id-seq.
id-seq: id
id-seq: id-seq, id (The instance of left recursion, because the Non-terminal is the first element in the RHS)
My textbook says to introduce a new non-terminal id-seq'
Would the production become:
id-seq: id-seq' , id
id-seq: id
id-seq': id-seq
id-seq': epislon
Not sure if that is all I need to do to eliminate the left recursion of id-seq. Have I defined id-seq' enough?
Thanks in advance for any comments.