Shift. Reduce. Review: Shift-Reduce Parsing. Bottom-up parsing uses two actions: Bottom-Up Parsing II. ABC xyz ABCx yz. Lecture 8.

Similar documents
Review: Shift-Reduce Parsing. Bottom-up parsing uses two actions: Bottom-Up Parsing II. Shift ABC xyz ABCx yz. Lecture 8. Reduce Cbxy ijk CbA ijk

Bottom-Up Parsing II (Different types of Shift-Reduce Conflicts) Lecture 10. Prof. Aiken (Modified by Professor Vijay Ganesh.

Bottom-Up Parsing II. Lecture 8

Principles of Programming Languages Topic: Formal Languages II

Midterm 2 - Solutions 1

A bottom-up parser traces a rightmost derivation in reverse. Bottom-Up Parsing. Bottom-up parsing is more general than topdown.

Bottom-Up Parsing LR Parsing

Outline. The strategy: shift-reduce parsing. Introduction to Bottom-Up Parsing. A key concept: handles

Introduction to Bottom-Up Parsing

Register Allocation. Register Allocation

Summary: Semantic Analysis

Review of CFGs and Parsing II Bottom-up Parsers. Lecture 5. Review slides 1

" dx v(x) $ % You may also have seen this written in shorthand form as. & ' v(x) + u(x) '# % ! d

The Network Layer: Routing Algorithms. The Network Layer: Routing & Addressing Outline

Bottom-Up Parsing. Lecture 11-12

CPSC 826 Internetworking. The Network Layer: Routing & Addressing Outline. The Network Layer: Routing Algorithms. Routing Algorithms Taxonomy

Problem Set 1 (Due: Friday, Sept. 29, 2017)

Bottom-Up Parsing. Lecture 11-12

Systems in Three Variables. No solution No point lies in all three planes. One solution The planes intersect at one point.

LR Parsing Techniques

Greedy Algorithms. Interval Scheduling. Greedy Algorithm. Optimality. Greedy Algorithm (cntd) Greed is good. Greed is right. Greed works.

About Notes And Symbols

8.3 INTEGRATION BY PARTS

Intro to Bottom-up Parsing. Lecture 9

LR Parsing LALR Parser Generators

A Brief Summary of Draw Tools in MS Word with Examples! ( Page 1 )

Building a Scanner, Part I

SLR parsers. LR(0) items

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

2018 How to Apply. Application Guide. BrandAdvantage

UNIT-III BOTTOM-UP PARSING

Intersection-free Dual Contouring on Uniform Grids: An Approach Based on Convex/Concave Analysis

EE 231 Fall EE 231 Homework 10 Due November 5, 2010

CSE 272 Assignment 1

Bottom up parsing. The sentential forms happen to be a right most derivation in the reverse order. S a A B e a A d e. a A d e a A B e S.

S Y N T A X A N A L Y S I S LR

Objectives. Two Ways to Implement Lists. Lists. Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

A left-sentential form is a sentential form that occurs in the leftmost derivation of some sentence.

Lecture 7: Deterministic Bottom-Up Parsing

MODULE 14 SLR PARSER LR(0) ITEMS

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

LR Parsing LALR Parser Generators

Lecture 8: Deterministic Bottom-Up Parsing

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

DO NOW Geometry Regents Lomac Date. due. Similar by Transformation 6.1 J'' J''' J'''

TCP Congestion Control. Congestion Avoidance

shift-reduce parsing

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

MIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

Outline. Tasks for Exercise Six. Exercise Six Goals. Task One: Kinetic Energy Table. Nested for Loops. Laboratory VI Program Control Using Loops

Motivation. Synthetic OOD concepts and reuse Lecture 4: Separation of concerns. Problem. Solution. Deleting composites that share parts. Or is it?

Bottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

Workbook for Designing Distributed Control Applications using Rockwell Automation s HOLOBLOC Prototyping Software John Fischer and Thomas O.

Reimbursement Requests in WORKS

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

Lexical and Syntax Analysis. Bottom-Up Parsing

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables by Wim Bohm and Michelle Strout. CS453 Shift-reduce Parsing 1

Lesson Focus: Finding Equivalent Fractions

Lecture Bottom-Up Parsing

Principles of Programming Languages

Compilers. Bottom-up Parsing. (original slides by Sam

LR Parsers. Aditi Raste, CCOEW

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Downloaded from Page 1. LR Parsing

Midterm I (Solutions) CS164, Spring 2002

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Directed Graphs BOS SFO

Bottom Up Parsing Handout. 1 Introduction. 2 Example illustrating bottom-up parsing

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

UNIT III & IV. Bottom up parsing

CS 4120 Introduction to Compilers

The semantic WEB Roles of XML & RDF

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

LR Parsing Techniques

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

LALR Parsing. What Yacc and most compilers employ.

Introduction to Data Mining

To Do. Mesh Data Structures. Mesh Data Structures. Motivation. Outline. Advanced Computer Graphics (Fall 2010) Desirable Characteristics 1

Maxwell s unification: From Last Time. Energy of light. Modern Physics. Unusual experimental results. The photoelectric effect

LR Parsing E T + E T 1 T

On Some Maximum Area Problems I

Bottom-Up Parsing. Parser Generation. LR Parsing. Constructing LR Parser

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University


Parser Self-Training for Syntax-Based Machine Translation

Ambiguity, Precedence, Associativity & Top-Down Parsing. Lecture 9-10

CS453 : JavaCUP and error recovery. CS453 Shift-reduce Parsing 1

JNTUWORLD. Code No: R

To Do. Advanced Computer Graphics. Motivation. Mesh Data Structures. Outline. Mesh Data Structures. Desirable Characteristics 1

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

Outline. Parser overview Context-free grammars (CFG s) Derivations Syntax-Directed Translation

CS606- compiler instruction Solved MCQS From Midterm Papers

Probabilistic inference

Efficient Obstacle-Avoiding Rectilinear Steiner Tree Construction

Transcription:

Rviw: Shift-Rduc Parsing Bottom-up parsing uss two actions: Bottom-Up Parsing II Lctur 8 Shift ABC xyz ABCx yz Rduc Cbxy ijk CbA ijk Prof. Aikn CS 13 Lctur 8 1 Prof. Aikn CS 13 Lctur 8 2 Rcall: h Stack Lft string can b implmntd by a stack op of th stack is th Shift pushs a trminal on th stack Rduc pops 0 or mor symbols off of th stack production rhs pushs a non-trminal on th stack production lhs Ky Issu How do w dcid whn to shift or rduc? xampl grammar: * Considr stp * W could rduc by giving * A fatal mistak! No way to rduc to th start symbol Prof. Aikn CS 13 Lctur 8 3 Prof. Aikn CS 13 Lctur 8 Handls Intuition: Want to rduc only if th rsult can still b rducd to th start symbol Assum a rightmost drivation S * X hn is a handl of Handls Cont. Handls formaliz th uition A handl is a string that can b rducd and also allows furthr rductions back to th start symbol W only want to rduc at handls Not: W hav said what a handl is, not how to find handls Prof. Aikn CS 13 Lctur 8 5 Prof. Aikn CS 13 Lctur 8 6 1

Important Fact #2 Important Fact #2 about bottom-up parsing: In shift-rduc parsing, handls appar only at th top of th stack, nvr insid Why? Informal induction on # of rduc movs: ru initially, stack is mpty Immdiatly aftr rducing a handl right-most non-trminal on top of th stack nxt handl must b to right of right-most nontrminal, bcaus this is a right-most drivation Squnc of shift movs rachs nxt handl Prof. Aikn CS 13 Lctur 8 Prof. Aikn CS 13 Lctur 8 8 Summary of Handls In shift-rduc parsing, handls always appar at th top of th stack Handls ar nvr to th lft of th rightmost non-trminal hrfor, shift-rduc movs ar suffic; th nd nvr mov lft Bottom-up parsing algorithms ar basd on rcognizing handls Rcognizing Handls hr ar no known ffic algorithms to rcogniz handls Solution: us huristics to guss which stacks ar handls On som CFGs, th huristics always guss corrctly For th huristics w us hr, ths ar th SLR grammars Othr huristics work for othr grammars Prof. Aikn CS 13 Lctur 8 9 Prof. Aikn CS 13 Lctur 8 10 Grammars All CFGs Viabl Prfixs It is not obvious how to dtct handls Unambiguous CFGs SLR CFGs will gnrat conflicts At ach stp th parsr ss only th stack, not th ntir input; start with that... a is a viabl prfix if thr is an w such that a w is a stat of a shift-rduc parsr Prof. Aikn CS 13 Lctur 8 Prof. Aikn CS 13 Lctur 8 12 2

Huh? What dos this man? A fw things: A viabl prfix dos not xtnd past th right nd of th handl It s a viabl prfix bcaus it is a prfix of th handl As long as a parsr has viabl prfixs on th stack no parsing rror has bn dtctd Important Fact #3 Important Fact #3 about bottom-up parsing: For any grammar, th st of viabl prfixs is a rgular languag Prof. Aikn CS 13 Lctur 8 13 Prof. Aikn CS 13 Lctur 8 1 Important Fact #3 Cont. Important Fact #3 is non-obvious W show how to comput automata that accpt viabl prfixs Itms An itm is a production with a. somwhr on th rhs h itms for ar.... Prof. Aikn CS 13 Lctur 8 15 Prof. Aikn CS 13 Lctur 8 16 Itms Cont. h only itm for X is X. Itms ar oftn calld LR0 itms Intuition h problm in rcognizing viabl prfixs is that th stack has only bits and pics of th rhs of productions If it had a complt rhs, w could rduc hs bits and pics ar always prfixs of rhs of productions Prof. Aikn CS 13 Lctur 8 1 Prof. Aikn CS 13 Lctur 8 18 3

xampl Considr th input hn is a stat of a shift-rduc pars is a prfix of th rhs of Will b rducd aftr th nxt shift Itm. says that so far w hav sn of this production and hop to s Gnralization h stack may hav many prfixs of rhs s Prfix 1 Prfix 2... Prfix n-1 Prfix n Lt Prfix i b a prfix of rhs of X i a i Prfix i will vntually rduc to X i h missing part of a i-1 starts with X i i.. thr is a X i-1 Prfix i-1 X i b for som b Rcursivly, Prfix k1 Prfix n vntually rducs to th missing part of a k Prof. Aikn CS 13 Lctur 8 19 Prof. Aikn CS 13 Lctur 8 20 An xampl Considr th string * : * is a stat of a shift-rduc pars is a prfix of th rhs of is a prfix of th rhs of * is a prfix of th rhs of * An xampl Cont. h stack of itms.. *. Says W v sn of W v sn of W v sn * of * Prof. Aikn CS 13 Lctur 8 21 Prof. Aikn CS 13 Lctur 8 22 Rcognizing Viabl Prfixs Ida: o rcogniz viabl prfixs, w must Rcogniz a squnc of partial rhs s of productions, whr ach squnc can vntually rduc to part of th missing suffix of its prdcssor An NFA Rcognizing Viabl Prfixs 1. Add a dummy production S S to G 2. h NFA stats ar th itms of G Including th xtra production 3. For itm a.xb add transition a.xb X ax.b. For itm a.xb and production X g add a.xb X.g Prof. Aikn CS 13 Lctur 8 23 Prof. Aikn CS 13 Lctur 8 2

An NFA Rcognizing Viabl Prfixs Cont. 5. vry stat is an accpting stat 6. Start stat is S.S NFA for Viabl Prfixs of th xampl.... S..... S... Prof. Aikn CS 13 Lctur 8 25..* * * *.. *. Prof. Aikn CS 13 Lctur 8 26 NFA for Viabl Prfixs in Dtail 1 NFA for Viabl Prfixs in Dtail 2 S. S. S... Prof. Aikn CS 13 Lctur 8 2 Prof. Aikn CS 13 Lctur 8 28 NFA for Viabl Prfixs in Dtail 3 NFA for Viabl Prfixs in Dtail.. S. S... S. S...... * *. Prof. Aikn CS 13 Lctur 8 29. Prof. Aikn CS 13 Lctur 8 30 5

NFA for Viabl Prfixs in Dtail 5 NFA for Viabl Prfixs in Dtail 6. S. S...... S. S........ * *. Prof. Aikn CS 13 Lctur 8 31. Prof. Aikn CS 13 Lctur 8 32 NFA for Viabl Prfixs in Dtail NFA for Viabl Prfixs in Dtail 8. S. S........ S. S.......... * *. Prof. Aikn CS 13 Lctur 8 33. Prof. Aikn CS 13 Lctur 8 3 NFA for Viabl Prfixs in Dtail 9 NFA for Viabl Prfixs in Dtail 10. S. S.......... S. S............ * *. Prof. Aikn CS 13 Lctur 8 35. Prof. Aikn CS 13 Lctur 8 36 6

NFA for Viabl Prfixs in Dtail NFA for Viabl Prfixs in Dtail 12. S. S........... S. S............* *. Prof. Aikn CS 13 Lctur 8 3..* * *. *. Prof. Aikn CS 13 Lctur 8 38 NFA for Viabl Prfixs in Dtail 13.... S..... S.... *..* *. Prof. Aikn CS 13 Lctur 8 39 * *. ranslation to th DFA..... S.. *... *. S..... *. *. *. *. *.. *. Prof. Aikn CS 13 Lctur 8 0 Lingo h stats of th DFA ar canonical collctions of itms or canonical collctions of LR0 itms h Dragon book givs anothr way of constructing LR0 itms Valid Itms Itm X b.g is valid for a viabl prfix ab if S * axw abgw by a right-most drivation Aftr parsing ab, th valid itms ar th possibl tops of th stack of itms Prof. Aikn CS 13 Lctur 8 1 Prof. Aikn CS 13 Lctur 8 2

Itms Valid for a Prfix An itm I is valid for a viabl prfix a if th DFA rcognizing viabl prfixs trminats on input a in a stat s containing I h itms in s dscrib what th top of th itm stack might b aftr rading input a Valid Itms xampl An itm is oftn valid for many prfixs xampl: h itm. is valid for prfixs... Prof. Aikn CS 13 Lctur 8 3 Prof. Aikn CS 13 Lctur 8. Valid Itms for S.... * S.... *. * *.. *... * *........ * LR0 Parsing Ida: Assum stack contains a nxt input is t DFA on input a trminats in stat s Rduc by X b if s contains itm X b. Shift if s contains itm X b.tw quivalnt to saying s has a transition labld t Prof. Aikn CS 13 Lctur 8 5 Prof. Aikn CS 13 Lctur 8 6. LR0 Conflicts LR0 has a rduc/rduc conflict if: Any stat has two rduc itms: X b. and Y w. LR0 has a shift/rduc conflict if: Any stat has a rduc itm and a shift itm: X b. and Y w.td LR0 Conflicts S... S... *.. *. * *.. *.... *.... wo *. shift/rduc * conflicts with. LR0 ruls. Prof. Aikn CS 13 Lctur 8 Prof. Aikn CS 13 Lctur 8 8 8

SLR LR = Lft-to-right scan SLR = Simpl LR SLR improvs on LR0 shift/rduc huristics Fwr stats hav conflicts SLR Parsing Ida: Assum stack contains a nxt input is t DFA on input a trminats in stat s Rduc by X b if s contains itm X b. t FollowX Shift if s contains itm X b.tw Prof. Aikn CS 13 Lctur 8 9 Prof. Aikn CS 13 Lctur 8 50. SLR Parsing Cont. If thr ar conflicts undr ths ruls, th grammar is not SLR h ruls amount to a huristic for dtcting handls h SLR grammars ar thos whr th huristics dtct xactly th handls SLR Conflicts S... S... *.. *. * *.. *.... *... Follow = {, $ }. Follow *. = {,, $ } * No. conflicts with SLR ruls!. Prof. Aikn CS 13 Lctur 8 51 Prof. Aikn CS 13 Lctur 8 52 Prcdnc Dclarations Digrssion Lots of grammars arn t SLR including all ambiguous grammars W can pars mor grammars by using prcdnc dclarations Instructions for rsolving conflicts Prcdnc Dclarations Cont. Considr our favorit ambiguous grammar: * h DFA for this grammar contains a stat with th following itms: *.. shift/rduc conflict! Dclaring * has highr prcdnc than rsolvs this conflict in favor of rducing Prof. Aikn CS 13 Lctur 8 53 Prof. Aikn CS 13 Lctur 8 5 9

Prcdnc Dclarations Cont. h trm prcdnc dclaration is mislading hs dclarations do not dfin prcdnc; thy dfin conflict rsolutions Not quit th sam thing! Naïv SLR Parsing Algorithm 1. Lt M b DFA for viabl prfixs of G 2. Lt x 1 x n $ b initial configuration 3. Rpat until configuration is S $ Lt a w b currnt configuration Run M on currnt stack a If M rjcts a, rport parsing rror Stack a is not a viabl prfix If M accpts a with itms I, lt a b nxt input Shift if X b. a g I Rduc if X b. I and a FollowX Rport parsing rror if nithr applis Prof. Aikn CS 13 Lctur 8 55 Prof. Aikn CS 13 Lctur 8 56 Nots If thr is a conflict in th last stp, grammar is not SLRk SLR xampl Configuration DFA Halt Stat Action * $ 1 shift k is th amount of lookahad In practic k = 1 Prof. Aikn CS 13 Lctur 8 5 Prof. Aikn CS 13 Lctur 8 58 Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift Prof. Aikn CS 13 Lctur 8 59 Prof. Aikn CS 13 Lctur 8 60 10

Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 61 Prof. Aikn CS 13 Lctur 8 62 SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 63 Prof. Aikn CS 13 Lctur 8 6 Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 65 Prof. Aikn CS 13 Lctur 8 66

SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift * $ 3 $ Follow rd. Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 6 Prof. Aikn CS 13 Lctur 8 68 Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 69 Prof. Aikn CS 13 Lctur 8 0 Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift * $ 3 $ Follow rd. * $ $ Follow rd. * Prof. Aikn CS 13 Lctur 8 1 Prof. Aikn CS 13 Lctur 8 2 12

Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 3 Prof. Aikn CS 13 Lctur 8 Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Configuration * $.... 6 2 S.. 5 *.. * S.. 3. 1 *. *.. *. *.. *. 10... 8.. * Prof. Aikn CS 13 Lctur 8 5 Prof. Aikn CS 13 Lctur 8 6 SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift * $ 3 $ Follow rd. * $ $ Follow rd. * $ 5 $ Follow rd. Configuration $ 2 S... 5. * S.. 3. 1. *. *. *. *.... 6 * *... 10... 8.. * Prof. Aikn CS 13 Lctur 8 Prof. Aikn CS 13 Lctur 8 8 13

Configuration $ 2 S... 5. * S.. 3. 1. *. *. *. *.... 6 * *... 10... 8.. * SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift * $ 3 $ Follow rd. * $ $ Follow rd. * $ 5 $ Follow rd. $ accpt Prof. Aikn CS 13 Lctur 8 9 Prof. Aikn CS 13 Lctur 8 80 Nots Skippd using xtra start stat S in this xampl to sav spac on slids Rrunning th automaton at ach stp is wastful Most of th work is rpatd An Improvmnt Rmmbr th stat of th automaton on ach prfix of th stack Chang stack to contain pairs Symbol, DFA Stat Prof. Aikn CS 13 Lctur 8 81 Prof. Aikn CS 13 Lctur 8 82 An Improvmnt Cont. For a stack sym 1, stat 1... sym n, stat n stat n is th final stat of th DFA on sym 1 sym n Goto abl Dfin goto[i,a] = j if stat i A stat j goto is just th transition function of th DFA On of two parsing tabls Dtail: h bottom of th stack is any,start whr any is any dummy symbol start is th start stat of th DFA Prof. Aikn CS 13 Lctur 8 83 Prof. Aikn CS 13 Lctur 8 8 1

Rfind Parsr Movs Shift x Push a, x on th stack a is currnt input x is a DFA stat Rduc X a As bfor Accpt rror Prof. Aikn CS 13 Lctur 8 85 Action abl For ach stat s i and trminal a If s i has itm X a.ab and goto[i,a] = j thn action[i,a] = shift j If s i has itm X a. and a FollowX and X S thn action[i,a] = rduc X a If s i has itm S S. thn action[i,$] = accpt Othrwis, action[i,a] = rror Prof. Aikn CS 13 Lctur 8 86 SLR Parsing Algorithm Lt I = w$ b initial input Lt j = 0 Lt DFA stat 1 hav itm S.S Lt stack = dummy, 1 rpat cas action[top_statstack,i[j]] of shift k: push I[j], k rduc X A: pop A pairs, push X, goto[top_statstack,x] accpt: halt normally rror: halt and rport rror Prof. Aikn CS 13 Lctur 8 8 Nots on SLR Parsing Algorithm Not that th algorithm uss only th DFA stats and th input h stack symbols ar nvr usd! Howvr, w still nd th symbols for smantic actions Prof. Aikn CS 13 Lctur 8 88 Mor Nots Som common constructs ar not SLR1 LR1 is mor powrful Build lookahad o th itms An LR1 itm is a pair: LR0 itm x lookahad [ *, $] mans Aftr sing * rduc if lookahad is $ Mor accurat than just using follow sts ak a look at th LR1 automaton for your parsr! Prof. Aikn CS 13 Lctur 8 89 15