This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: LL(1) vs. LeftRecursive Grammars Let us review LL(1) grammars and topdown parsing Given an LL(1) grammar we should be able to construct a parse tree given two pieces of information: Given the current pointer into the sentence to be parsed A single token lookahead Consider the next two grammars The first one is LL(1) The second is not; it is leftrecursive and cannot be used to parse sentences in a recursive descent fashion. Note: Examples are due to Michael J. Fromberger LL(1) vs. LeftRecursive Grammars A : b C b C : D S D : {d} d D  {x} x S : {s} s S  {y} y Parse the sentence: bdxsyb Start symbol: A No problems here! Grammar: LL(1) vs. LeftRecursive Grammars A : B C B : {c} B b  {c} c C : c Parse the sentence: c b b c Start symbol: A Cant be done  problem choosing the right alternative. Grammar: LL(1) vs. LeftRecursive Grammars A : a  B B : A b Be aware, sometimes leftrecursion is hidden, but it is easily exposed by computing the lookahead sets. Start symbol: A Grammar: Eliminating LeftRecursion Leftrecursive grammars often describe lists and other recursive structures In most cases those recursive structures can be described with alternative LL(1) grammars, consider: A : A b  a This leftrecursive grammar defines the language of all strings that start with a single a and finish with zero or more bs.or more bs....
View
Full
Document
This note was uploaded on 10/03/2011 for the course CSC 402 taught by Professor Staff during the Fall '09 term at Rhode Island.
 Fall '09
 Staff

Click to edit the document details