









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Where are we??
Left Recursive Right Recursive E -> E + Num E -> Num ** this one causes problems later!
E -> Num + E E -> Num
Both of these grammars describe the same language!!
1 + 2 + 3 = (L Recursive) = valid 1 + 2 + 3 = (R Recursive) = valid
Intro. to Top Down Parsing Methods
http://www.cs.wright.edu/~tkprasad/courses/cs780/L101TDP.pdf
S -> NP VP VP -> V NP | V NP PP PP -> P NP V -> "saw" | "ate" | "walked" NP -> "John" | "Mary" | "Bob" | Det N | Det N PP Det -> "a" | "an" | "the" | "my" N -> "man" | "dog" | "cat" | "telescope" | "park" P -> "in" | "on" | "by" | "with"
notice by nature it’s Left Most!! Create another sentence that will work, and one that does not (but may look close)
This newly created symbol is often called the "tail", or the "rest".
As an example, consider the rule
This could be rewritten to avoid left recursion as
The last rule happens to be equivalent to the slightly shorter form
Consider left-recursive grammar S S S
S generates strings
Rewrite using right-recursion S S’ S’ S’|
Consider left-recursive grammar exp exp addop term | term
Rewrite using right-recursion exp term exp’ exp’ addop term exp’ |
Try these:
exp --> exp + term | exp - term | term
A ABc | AAdd | a | aa B Bee | b
Answer: (^) Answer:
Try if for the entire grammar:
exp --> exp addop term | term addop --> + | - term --> term mulop factor | factor mulop --> * factor --> ( exp ) | number
Answer:
How about these Grammars?? Good/Bad??
E T E' E' + T E' | - T E' | T F T' T' * F T' | / F T' | F num | id Consider the grammar E T + E E T T int T int * T T ( E )
Answer:
LL(n) LR(n) Left to right, Leftmost derivation, look ahead at most n symbols.
Left to right, Right derivation, look ahead at most n symbols.
Predictive Parsing and Left Factoring
Remember the grammar?? E T + E E T T int T int * T T ( E )
Video: (many need to adjust screen resolution) http://userpages.umbc.edu/~slupoli/notes/ProgLanguages/videos/ LL1ParingTableExample.swf
missed ( and ) as terminals in video!!
Using the same layout, try (using the same table):
Bottom up- Try www.cs.virginia.edu/kim/courses/ cs671 /lec/ cs671 -05- bottomup .ppt
Resources: Dr. Finin – UMBC Sebesta http://nltk.googlecode.com/svn/trunk/doc/book/ch08.html F 0 6 5
F 0 http://www.cs.sun.ac.za/rw711/2012term2/lectures/lec9 F 0 2010/l96 5 2010.pdf http://en.wikipedia.org/wiki/Left6 5 recursion