# UMBC CMSC 331 O NLINE L ECTURE 3 P ART 1 SD Vick.

## Presentation on theme: "UMBC CMSC 331 O NLINE L ECTURE 3 P ART 1 SD Vick."— Presentation transcript:

UMBC CMSC 331 O NLINE L ECTURE 3 P ART 1 SD Vick

What is Left Recursion? Left Recursion is when you have a grammar with one or more rules of the following form A -> A  |  Example where  is and  is c  A -> A a b | c In the technique I’ll show you  can’t directly (or indirectly) start with A 1) A -> A a b | Ac is illegal 2) A -> A a b | Bc so is this B -> d | Ae A -> B -> A Why?

What’s the General Rule? A -> A    | A    | … A  m  |      n  A   A’ |   A’ …  n A’ A’ ->   A’ |   A’ | …  m A’ | 

-> ? | ! | a -> * | / | ->e | f Removing Left Recursion Consider the following Grammar Why is this Left Recursive? Now we must just  pick our  ’s  and  our  ’s

The Mechanics -> ? | ! | a    -> ? | a -> ! |  Try the second rule on your own Here we have 2  ‘s and 1 , what if the situation was reversed?

Download ppt "UMBC CMSC 331 O NLINE L ECTURE 3 P ART 1 SD Vick."

Similar presentations