CS 31003: Compilers  Difference between SLR and LR(1)  Construction of LR(1) parsing table  LALR parser Bandi Sumanth 11CS30006 Date : 9/10/2013.

Slides:



Advertisements
Similar presentations
Bottom-up Parser Table Construction David Walker COS 320.
Advertisements

A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Lesson 8 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Compiler Designs and Constructions
Compiler construction in4020 – lecture 4 Koen Langendoen Delft University of Technology The Netherlands.
Compilation (Semester A, 2013/14) Lecture 6a: Syntax (Bottom–up parsing) Noam Rinetzky 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
Compiler Principles Fall Compiler Principles Lecture 4: Parsing part 3 Roman Manevich Ben-Gurion University.
Joey Paquet, 2000, 2002, 2008, Lecture 7 Bottom-Up Parsing II.
Pushdown Automata Consists of –Pushdown stack (can have terminals and nonterminals) –Finite state automaton control Can do one of three actions (based.
Compiler Construction Sohail Aslam Lecture Finite Automaton of Items Then for every item A →  X  we must add an  -transition for every production.
1 May 22, May 22, 2015May 22, 2015May 22, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
LR Parsing Table Costruction
Bhaskar Bagchi (11CS10058) Lecture Slides( 9 th Sept. 2013)
Compiler Construction LR Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
1 LR parsing techniques SLR (not in the book) –Simple LR parsing –Easy to implement, not strong enough –Uses LR(0) items Canonical LR –Larger parser but.
Table-driven parsing Parsing performed by a finite state machine. Parsing algorithm is language-independent. FSM driven by table (s) generated automatically.
1 Bottom-up parsing Goal of parser : build a derivation –top-down parser : build a derivation by working from the start symbol towards the input. builds.
Parsing Wrap-up. from Cooper and Torczon2 Filling in the A CTION and G OTO Tables The algorithm Many items generate no table entry  Closure( ) instantiates.
Bottom-up parsing Goal of parser : build a derivation
LESSON 24.
SLR PARSING TECHNIQUES Submitted By: Abhijeet Mohapatra 04CS1019.
11 Outline  6.0 Introduction  6.1 Shift-Reduce Parsers  6.2 LR Parsers  6.3 LR(1) Parsing  6.4 SLR(1)Parsing  6.5 LALR(1)  6.6 Calling Semantic.
Chapter 3-3 Chang Chi-Chung Bottom-Up Parsing LR methods (Left-to-right, Rightmost derivation)  LR(0), SLR, Canonical LR = LR(1), LALR 
–Exercise: construct the SLR parsing table for grammar: S->L=R, S->R L->*R L->id R->L –The grammar can have shift/reduce conflict or reduce/reduce conflict.
4. Bottom-up Parsing Chih-Hung Wang
Syntax Analysis (chapter 4) SLR, LR1, LALR: Improving the parser From the previous examples: => LR0 parsing is rather weak. Cannot handle many languages.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Bottom Up Parsing CS 671 January 31, CS 671 – Spring Where Are We? Finished Top-Down Parsing Starting Bottom-Up Parsing Lexical Analysis.
Three kinds of bottom-up LR parser SLR “Simple LR” –most restrictions on eligible grammars –built quite directly from items as just shown LR “Canonical.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 6: LR grammars and automatic parser generators.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
March 1, 2009 Dr. Muhammed Al-Mulhem 1 ICS 482 Natural Language Processing SLR Parsing Muhammed Al-Mulhem March 1, 2009.
Conflicts in Simple LR parsers A SLR Parser does not use any lookahead The SLR parsing method fails if knowing the stack’s top state and next input token.
Chapter 8. LR Syntactic Analysis Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
COMPILER CONSTRUCTION
2016/7/9Page 1 Lecture 11: Semester Review COMP3100 Dept. Computer Science and Technology United International College.
Announcements/Reading
SLR Parser Problems.
Unit-3 Bottom-Up-Parsing.
CS 488 Spring 2012 Lecture 4 Bapa Rao Cal State L.A.
Table-driven parsing Parsing performed by a finite state machine.
Compiler Construction
Compiler design Bottom-up parsing: Canonical LR and LALR
Fall Compiler Principles Lecture 4: Parsing part 3
LALR Parsing Canonical sets of LR(1) items
Bottom-Up Syntax Analysis
Canonical LR Parsing Tables
Michael Santacroce EECE 6083 Compiler Theory University of Cincinnati
Prepared By: NITIN GOYAL - 04CS1026 JITENDRA BINDAL - 04CS1027
Syntax Analysis - LR(1) and LALR(1) Parsing
LR Parsing – The Tables Lecture 11 Wed, Feb 16, 2005.
Parsing #2 Leonidas Fegaras.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
LALR Parsing Adapted from Notes by Profs Aiken and Necula (UCB) and
Compiler Construction
Chapter 4. Syntax Analysis (2)
Parsing #2 Leonidas Fegaras.
Prepared by VISHWA DEEPAK 04CS1029
5. Bottom-Up Parsing Chih-Hung Wang
Syntax Analysis - 3 Chapter 4.
Kanat Bolazar February 16, 2010
Compiler Construction
Chapter 4. Syntax Analysis (2)
Parsing Bottom-Up LR Table Construction.
Parsing Bottom-Up LR Table Construction.
Lecture 11 LR Parse Table Construction
Lecture 11 LR Parse Table Construction
Review for the Midterm. Overview (Chapter 1):
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003 Prof. Roy Levow.
Compiler design Bottom-up parsing: Canonical LR and LALR
Presentation transcript:

CS 31003: Compilers  Difference between SLR and LR(1)  Construction of LR(1) parsing table  LALR parser Bandi Sumanth 11CS30006 Date : 9/10/2013

Differences between SLR and LR(1) ●

SLR, Non SLR and LR(1) grammar ● SLR grammar ● A grammar is said to be an SLR grammar if the SLR parsing table for the grammar has no conflicting entries

SLR, Non SLR and LR(1) grammar ● A → B +. C A → B. + C A → B. + SiSi SjSj

SLR, Non SLR and LR(1) grammar ● LR(1) grammar  If the current state is S i and + is the next token, a shift is made leading to the state Sj  Reduction cannot be made because the lookahead symbol * and the next token + does not match A → B +. C A → B. + C, = A → B., * + SiSi SjSj

● Construction of LR(1) parsing table

Constructing LR(1) parsing table ● Consider the following augmented grammar Ś → S S → C C C → c C | d

LR(1) sets of items

LR(1) parsing table for the grammar

LR(1) vs SLR parser ● LR(1) parser is better than SLR parser because LR(1) accepts more languages than SLR ● SLR(1) is weak because it has no lookahead information ● But the cost is LR(1) has more states than SLR and thus it consumes more space ● LR(1) is impractical because its lookahead information makes the automaton too big

Can we retain the LR(1) automaton's lookahead information without all its states?

Review of LR(1) ● Each state in an LR(1) automaton is a combination of an LR(0) state and lookahead information. ● Two LR(1) items have the same core if they are identical except for lookahead.

A Surprisingly Powerful Idea ● In an LR(1) automaton, we have multiple states with the same core but different Lookahead ● What if we merge all these states together?  This is called LALR parser Lookahead LR parser

Advantages of LALR(1) ● Maintains lookahead information ● Keeps automaton small ● Resulting automaton has same size as LR(0) automaton

The End