csc402-ln005

csc402-ln005 - LL(1) vs. Left-Recursive Grammars Let us...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: LL(1) vs. Left-Recursive Grammars Let us review LL(1) grammars and top-down 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 left-recursive and cannot be used to parse sentences in a recursive descent fashion. Note: Examples are due to Michael J. Fromberger LL(1) vs. Left-Recursive 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. Left-Recursive 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. Left-Recursive Grammars A : a | B B : A b Be aware, sometimes left-recursion is hidden, but it is easily exposed by computing the lookahead sets. Start symbol: A Grammar: Eliminating Left-Recursion Left-recursive 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 left-recursive 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.

Page1 / 17

csc402-ln005 - LL(1) vs. Left-Recursive Grammars Let us...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online