lec14mod - CS415 Compilers LR(1 parsing(LR(1 SLR(1 LALR(1...

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: CS415 Compilers LR(1) parsing, (LR(1), SLR(1), LALR(1)) These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 14 2 cs415, spring 10 Review - LR(1) Parsers • LR(1) parsers are table-driven, shift-reduce parsers that use a limited right context (1 token) for handle recognition • LR(1) parsers recognize languages that have an LR(1 ) grammar Informal definition: A grammar is LR(1) if, given a rightmost derivation S ⇒ γ ⇒ γ 1 ⇒ γ 2 ⇒ … ⇒ γ n–1 ⇒ γ n ⇒ sentence We can 1. isolate the handle of each right-sentential form γ i , and 2. determine the production by which to reduce, by scanning γ i from left-to-right, going at most 1 symbol beyond the right end of the handle of γ i Lecture 14 3 cs415, spring 10 Review - LR(1) Parsers A table-driven LR(1) parser looks like Tables can be built by hand However, this is a perfect task to automate Scanner Table-driven Parser A CTION & G OTO Tables Parser Generator source code grammar IR Lecture 14 4 cs415, spring 10 Building LR(1) Parsers How do we generate the A CTION and G OTO tables? • Use the grammar to build a model of the DFA • Use the model to build A CTION & G OTO tables • If construction succeeds, the grammar is LR(1) The Big Picture • Model the state of the parser • Use two functions goto( s, X ) and closure( s ) → goto() is analogous to move() in the subset construction → closure() adds information to round out a state • Build up the states and transition functions of the DFA • Use this information to fill in the A CTION and G OTO tables Terminal or non-terminal Lecture 14 5 cs415, spring 10 LR(k) items The LR(1) table construction algorithm uses LR(1) items to...
View Full 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 / 13

lec14mod - CS415 Compilers LR(1 parsing(LR(1 SLR(1 LALR(1...

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