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: 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 tabledriven, shiftreduce 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 rightsentential form γ i , and 2. determine the production by which to reduce, by scanning γ i from lefttoright, 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 tabledriven LR(1) parser looks like Tables can be built by hand However, this is a perfect task to automate Scanner Tabledriven 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 nonterminal 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.
 Spring '10
 Kremer,U.

Click to edit the document details