SLR Parser Problems.

Slides:



Advertisements
Similar presentations
Compiler Designs and Constructions
Advertisements

Compiler Principles Fall Compiler Principles Lecture 4: Parsing part 3 Roman Manevich Ben-Gurion University.
Bottom-up Parsing A general style of bottom-up syntax analysis, known as shift-reduce parsing. Two types of bottom-up parsing: Operator-Precedence parsing.
Joey Paquet, 2000, 2002, 2008, Lecture 7 Bottom-Up Parsing II.
Review: LR(k) parsers a1 … a2 … an $ LR parsing program Action goto Sm xm … s1 x1 s0 output input stack Parsing table.
CS 31003: Compilers  Difference between SLR and LR(1)  Construction of LR(1) parsing table  LALR parser Bandi Sumanth 11CS30006 Date : 9/10/2013.
LR Parsing – The Items Lecture 10 Mon, Feb 14, 2005.
Bhaskar Bagchi (11CS10058) Lecture Slides( 9 th Sept. 2013)
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #10, Feb. 14, 2007 Modified sets of item construction Rules for building LR parse tables.
6/12/2015Prof. Hilfinger CS164 Lecture 111 Bottom-Up Parsing Lecture (From slides by G. Necula & R. Bodik)
1 Chapter 5: Bottom-Up Parsing (Shift-Reduce). 2 - attempts to construct a parse tree for an input string beginning at the leaves (the bottom) and working.
Formal Aspects Term 2, Week4 LECTURE: LR “Shift-Reduce” Parsers: The JavaCup Parser-Generator CREATES LR “Shift-Reduce” Parsers, they are very commonly.
CS 536 Spring Bottom-Up Parsing: Algorithms, part 1 LR(0), SLR Lecture 12.
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.
Bottom-up parsing Goal of parser : build a derivation
LALR Parsing Canonical sets of LR(1) items
410/510 1 of 21 Week 2 – Lecture 1 Bottom Up (Shift reduce, LR parsing) SLR, LR(0) parsing SLR parsing table Compiler Construction.
CS 321 Programming Languages and Compilers Bottom Up Parsing.
Ambiguity in Grammar By Dipendra Pratap Singh 04CS1032.
Chapter 5: Bottom-Up Parsing (Shift-Reduce)
–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.
1 Syntax Analysis Part II Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Bottom-Up Parsing David Woolbright. The Parsing Problem Produce a parse tree starting at the leaves The order will be that of a rightmost derivation The.
Earley’s Algorithm J. Earley, "An efficient context-free parsing algorithm", Communications of the Association for Computing Machinery, 13:2:94-102, 1970."An.
COMPILERS 4 TH SEPTEMBER 2013 WEDNESDAY 11CS10045 SRAJAN GARG.
LR Parser: LR parsing is a bottom up syntax analysis technique that can be applied to a large class of context free grammars. L is for left –to –right.
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.
Bottom-Up Parsing Algorithms LR(k) parsing L: scan input Left to right R: produce Rightmost derivation k tokens of lookahead LR(0) zero tokens of look-ahead.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 6: LR grammars and automatic parser generators.
1 Syntax Analysis Part II Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007.
Lecture 5: LR Parsing CS 540 George Mason University.
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.
1 Chapter 6 Bottom-Up Parsing. 2 Bottom-up Parsing A bottom-up parsing corresponds to the construction of a parse tree for an input tokens beginning at.
Parsing Bottom Up CMPS 450 J. Moloney CMPS 450.
Programming Languages Translator
LR Parsing – The Items Lecture 10 Fri, Feb 13, 2004.
Compiler Baojian Hua LR Parsing Compiler Baojian Hua
Unit-3 Bottom-Up-Parsing.
UNIT - 3 SYNTAX ANALYSIS - II
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
Syntax Analysis Part II
Implementing a LR parser engine
Prepared By: NITIN GOYAL - 04CS1026 JITENDRA BINDAL - 04CS1027
Subject Name:COMPILER DESIGN Subject Code:10CS63
Regular Grammar - Finite Automaton
LR Parsing – The Tables Lecture 11 Wed, Feb 16, 2005.
Parsing #2 Leonidas Fegaras.
BOTTOM UP PARSING Lecture 16.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Bottom Up Parsing.
Ambiguity in Grammar, Error Recovery
Parsing #2 Leonidas Fegaras.
Bottom-Up Parsing “Shift-Reduce” Parsing
Prepared by VISHWA DEEPAK 04CS1029
5. Bottom-Up Parsing Chih-Hung Wang
Kanat Bolazar February 16, 2010
Announcements HW2 due on Tuesday Fall 18 CSCI 4430, A Milanova.
Compiler Construction
Compiler Construction
USING AMBIGUOUS GRAMMARS
Parsing Bottom-Up LR Table Construction.
Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing
Parsing Bottom-Up LR Table Construction.
Compiler design Bottom-up parsing: Canonical LR and LALR
Presentation transcript:

SLR Parser Problems

• Problems with SLR parser: The SLR parser discussed in the earlier class has certain flaws. 1. A state may include a final item (one in which the position marker is at the end) and a non- final item. This may result in a shift-reduce conflict . 2. A state may include two different final items. This might result in a reduce-reduce conflict . • Can we have reduce-reduce conflicts in unambiguous grammars? • Can we have a shift-shift conflict ? However SLR reduces only when the next token is in Follow of the left-hand side of the production. Proper choices may help to resolve reduce-reduce conflicts.However, still similar conflicts exist: ->Shift-reduce conflicts include the case in which Follow of the lhs nonterminal of any final item overlaps with first token after the dot in any of the remaining items in that item set. Reduce-reduce conflicts include the case Follow of left-hand-sides of more than one final items in an item set overlap. This grammar is called LR(0.5) or SLR.This is because when we reduce,we do not really consider the lookahead.The production is placed in the table corresponding to the entire follow set of the nonterminal.Hence this cannot strictly be referred to as LR(1).

Let us consider the grammar. 0. S’->S 1. S->E 2. E->L=R 3. E->R 4. L->*R 5. L->id 6. R->L Construcing the item set: Io={S’->.S, S->.E, E->.L=R, E->.R, L->.*R, L->.id, R->.L} I1= {S’->S.} I2 = {S  .E} I3 = {E L.=R , RL.} I4 = { E L=.R , R.L ,L  .*R , L.id} I5 = {E  L=R.} I6 = {E  R.} I7 = { L  *.R , R.L ,L  .*R , L.id} I8 = { L  *R. } I9 = {L id.}

So in the Parsing table we have the following conflict when the follow ‘=’ appears. |.…..…………………………………… | …. ….. ‘=’ ….. …… I3 …. ….. s4/r6 ….. ……. -> shift reduce conflict Hence our next approach is to try LR(1) parser. Ridhima Kedia 04CS1021