05-TopDownParseLL1

05-TopDownParseLL1 - Discussion #5 Top-Down Parsing, LL(1)...

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

View Full Document Right Arrow Icon
Discussion #5 Chapter 10, Section 2 1/18 Discussion #5 Top-Down Parsing, LL(1) Grammars
Background image of page 1

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

View Full DocumentRight Arrow Icon
Discussion #5 Chapter 10, Section 2 2/18 Topics Approaches to Parsing Full backtracking Deterministic Simple LL(1), table-driven parsing Improvements to simple LL(1) grammars
Background image of page 2
Discussion #5 Chapter 10, Section 2 3/18 Prefix Expression Grammar Consider the following grammar (which yields prefix expressions for binary operators): E N | OEE O + | - | * | / N 0 | 1 | 2 | 3 | 4 Here, prefix expressions associate an operator with the next two operands. * + 2 3 4 (* (+ 2 3) 4) (2 + 3) * 4 = 20 * 2 + 3 4 (* 2 (+ 3 4)) 2 * (3 + 4) = 14
Background image of page 3

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

View Full DocumentRight Arrow Icon
Discussion #5 Chapter 10, Section 2 4/18 E N O E E … + - * N O E E N + N N 0 1 2 0 1 2 3 0 1 2 3 4 E N | OEE O + | - | * | / N 0 | 1 | 2 | 3 | 4 *+342 Top-Down Parsing with Backtracking
Background image of page 4
Discussion #5 Chapter 10, Section 2 5/18 What are the obvious problems? We never know what production to try. It appears to be terribly inefficient—and it is. Are there grammars for which we can always know what rule to choose? Yes! Characteristics: Only single symbol look ahead Given a non-terminal and a current symbol, we always know which production rule to apply
Background image of page 5

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

View Full DocumentRight Arrow Icon
Discussion #5 Chapter 10, Section 2 6/18 LL(1) Parsers An LL parser parses the input from L eft to right, and constructs a L eftmost derivation of the sentence. An LL( k ) parser uses k tokens of look-ahead.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/02/2012 for the course C S 236 taught by Professor Michaelgoodrich during the Winter '12 term at BYU.

Page1 / 18

05-TopDownParseLL1 - Discussion #5 Top-Down Parsing, LL(1)...

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

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