UMBC CMSC 331 ONLINE LECTURE 3 SD Vick Mini Lectures Left Recursion defined and explained with and caveats (see http://www.csee.umbc.edu/~vick/331/online/Left_Rec _Rem_1.swf) Left recursion removal example (see http://www.csee.umbc.edu/~vick/331/online/Left_Rec _rem_2.swf) (Full text of mini-lectures http://www.csee.umbc.edu/~vick/331/online/L3.ppt ) What’s the General Rule? A -> A a1 | A a2 | … A am | b1 | b2 | bn ________________________________________ A-> b1 A’ | b2 A’ … bn A’ A’ -> a1 A’ | a2 A’ | … am A’ | e Removing Left Recursion Consider the following Grammar <z> -> <w> ? <x> | <z> ! <y> | a <z> <x> -> <z> * <x> | <x> / <y> | <w> <w> -> e | f Why is this Left Recursive? Now we must just pick our a’s and our b’s The Mechanics <z> -> <w> ? <x> | <z> -> <w> ? <x> <z’> | a <z> <z’> <z’> -> ! <y> <z’> | e b1 <z> ! <y> | a1 a <z> b2 Try the second rule on your own Here we have 2 b‘s and 1 a, what if the situation was reversed?