lec13mod - CS415 Compilers Bottom-up parsing, LR(1) parsing...

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

View Full Document Right Arrow Icon
CS415 Compilers Bottom-up parsing, LR(1) parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 13 2 cs415, spring 10 Parsing (Syntax Analysis) EAC Chapters 3.4 – 3.5
Background image of page 2
Lecture 13 3 cs415, spring 10 Parsing Techniques: Bottom-up parsers LR(1), operator precedence input: read left-to-right construct rightmost deriviation (backwards) 1 input symbol lookahead x y S B α γ S * rm α B y rm αγ y * rm x y rule B ::= γ
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lecture 13 4 cs415, spring 10 Parsing Techniques: Bottom-up parsers input: read left-to-right construct rightmost deriviation (backwards) 1 input symbol lookahead x y S B α S * rm α B y rm αγ y * rm x y rule B ::= γ LR(1), operator precedence upper fringe
Background image of page 4
Lecture 13 5 cs415, spring 10 Finding Reductions Consider the simple grammar And the input string abbcde The trick is scanning the input and finding the next reduction The mechanism for doing this must be efficient 1 Goal a AB e 2 A b c 3| b 4 B d Sentential Next Reduction Form Prod’n Pos’n abbcde 32 a A bcde 24 a A de 43 a A B e 14 ——
Background image of page 5

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

View Full DocumentRight Arrow Icon
Lecture 13 6 cs415, spring 10 Finding Reductions (Handles) The parser must find a substring β of the tree’s frontier that matches some production A that occurs as one step in the rightmost derivation Informally, we call this substring β a handle Formally, A of a right-sentential form γ is a pair < A β , k > where β P and k is the position in γ of β ’s rightmost symbol. If < β , k > is a handle, then replacing β at with A produces the right sentential form from which γ is derived in the rightmost derivation. Because γ is a right-sentential form, the substring to the right of a handle contains only terminal symbols the parser doesn’t need to scan past the handle (only lookahead) The right end of the handle will be on top of the stack, not within the stack. Need lookahead to determine whether we reached the handle.
Background image of page 6
Lecture 13 7 cs415, spring 10 Critical Insight (Theorem?) If G is unambiguous, then every right-sentential form has a unique handle. If we can find those handles, we can build a derivation ! Sketch of Proof: 1 Gis unambiguous rightmost derivation is unique 2 a unique production A β applied to derive γ i from γ i– 1 3 a unique position k at which A β is applied 4 a unique handle < A β , k > This all follows from the definitions Finding Reductions (Handles)
Background image of page 7

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

View Full DocumentRight Arrow Icon
Lecture 13 8 cs415, spring 10 Example (a very busy slide) 1 Goal Expr 2 Expr + Term 3| 4| 5 Term * Factor 6| / 7| 8 number 9| i d 10 | ( ) The expression grammar Prod’n. Sentential Form Handle 1 1,1 3 3,3 5 * 5,5 9 * <id,y> 9,5 7 * <id, y > 7,3 8 <num,2> * <id, y > 8,3 4 <num, 2 > * <id, y > 4,1 7 <num, 2 > * <id, y > 7,1 9 <id,x> <num, 2 > * <id, y > 9,1 Handles for rightmost derivation of x 2 * y This is the inverse of Figure 3.9 in EaC
Background image of page 8
Lecture 13 9 cs415, spring 10 Handle-pruning, Bottom-up Parsers The process of discovering a handle & reducing it to the appropriate left-hand side is called handle pruning
Background image of page 9

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

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

This note was uploaded on 10/29/2010 for the course CS 198:415 taught by Professor Kremer,u. during the Spring '10 term at Rutgers.

Page1 / 35

lec13mod - CS415 Compilers Bottom-up parsing, LR(1) parsing...

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

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