Shift. Reduce. Review: Shift-Reduce Parsing. Bottom-up parsing uses two actions: Bottom-Up Parsing II. ABC xyz ABCx yz. Lecture 8.
|
|
- Bertram Dean
- 6 years ago
- Views:
Transcription
1 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
2 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
3 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
4 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
5 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 * * * *.. *. 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 Prof. Aikn CS 13 Lctur
6 NFA for Viabl Prfixs in Dtail 5 NFA for Viabl Prfixs in Dtail 6. S. S S. S * *. Prof. Aikn CS 13 Lctur 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 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 Prof. Aikn CS 13 Lctur
7 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 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
8 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
9 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 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
10 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 * $ S.. 5 *.. * S *. *.. *. *.. * * 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
11 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * 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 * $ S.. 5 *.. * S *. *.. *. *.. * * Prof. Aikn CS 13 Lctur 8 63 Prof. Aikn CS 13 Lctur 8 6 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Prof. Aikn CS 13 Lctur 8 65 Prof. Aikn CS 13 Lctur 8 66
12 SLR xampl Configuration DFA Halt Stat Action * $ 1 shift * $ 3 * not in Follow shift * $ shift * $ 3 $ Follow rd. Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Prof. Aikn CS 13 Lctur 8 6 Prof. Aikn CS 13 Lctur 8 68 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Prof. Aikn CS 13 Lctur 8 69 Prof. Aikn CS 13 Lctur 8 0 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * 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
13 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Prof. Aikn CS 13 Lctur 8 3 Prof. Aikn CS 13 Lctur 8 Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * Configuration * $ S.. 5 *.. * S *. *.. *. *.. * * 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 * S *. *. *. * * * * Prof. Aikn CS 13 Lctur 8 Prof. Aikn CS 13 Lctur
14 Configuration $ 2 S * S *. *. *. * * * * 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
15 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
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
Review: Shift-Reduce Parsing Bottom-up parsing uses two actions: Bottom-Up Parsing II Lecture 8 Shift ABC xyz ABCx yz Reduce Cbxy ijk CbA ijk Prof. Aiken CS 13 Lecture 8 1 Prof. Aiken CS 13 Lecture 8 2
More informationBottom-Up Parsing II (Different types of Shift-Reduce Conflicts) Lecture 10. Prof. Aiken (Modified by Professor Vijay Ganesh.
Bottom-Up Parsing II Different types of Shift-Reduce Conflicts) Lecture 10 Ganesh. Lecture 10) 1 Review: Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient Doesn
More informationBottom-Up Parsing II. Lecture 8
Bottom-Up Parsing II Lecture 8 1 Review: Shift-Reduce Parsing Bottom-up parsing uses two actions: Shift ABC xyz ABCx yz Reduce Cbxy ijk CbA ijk 2 Recall: he Stack Left string can be implemented by a stack
More informationPrinciples of Programming Languages Topic: Formal Languages II
Principls of Programming Languags Topic: Formal Languags II CS 34,LS, LTM, BR: Formal Languags II Rviw A grammar can b ambiguous i.. mor than on pars tr for sam string of trminals in a PL w want to bas
More informationMidterm 2 - Solutions 1
COS 26 Gnral Computr Scinc Spring 999 Midtrm 2 - Solutions. Writ a C function int count(char s[ ]) that taks as input a \ trminatd string and outputs th numbr of charactrs in th string (not including th
More informationA bottom-up parser traces a rightmost derivation in reverse. Bottom-Up Parsing. Bottom-up parsing is more general than topdown.
Bottom-Up Parsing Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient Builds on ideas in top-down parsing Bottom-up is the preferred method Originated from Prof.
More informationBottom-Up Parsing LR Parsing
Bottom-Up Parsing LR Parsing Maryam Siahbani 2/19/2016 1 What we need for LR parsing LR0) states: Describe all possible states in which parser can be Parsing table ransition between LR0) states Actions
More informationOutline. The strategy: shift-reduce parsing. Introduction to Bottom-Up Parsing. A key concept: handles
Outline Introduction to Bottom-Up Parsing Lecture Notes by Profs. Alex Aiken and George Necula (UCB) he strategy: -reduce parsing A key concept: handles Ambiguity and precedence declarations CS780(Prasad)
More informationIntroduction to Bottom-Up Parsing
Introduction to Bottom-Up Parsing Lecture 11 CS 536 Spring 2001 1 Outline he strategy: shift-reduce parsing Ambiguity and precedence declarations Next lecture: bottom-up parsing algorithms CS 536 Spring
More informationRegister Allocation. Register Allocation
Rgistr Allocation Jingk Li Portlan Stat Univrsity Jingk Li (Portlan Stat Univrsity) CS322 Rgistr Allocation 1 / 28 Rgistr Allocation Assign an unboun numbr of tmporaris to a fix numbr of rgistrs. Exampl:
More informationSummary: Semantic Analysis
Summary: Smantic Analysis Chck rrors not dtctd by lxical or syntax analysis Intrmdiat Cod Scop rrors: Variabls not dfind Multipl dclarations Typ rrors: Assignmnt of valus of diffrnt typs Invocation of
More informationReview of CFGs and Parsing II Bottom-up Parsers. Lecture 5. Review slides 1
Review of CFGs and Parsing II Bottom-up Parsers Lecture 5 1 Outline Parser Overview op-down Parsers (Covered largely through labs) Bottom-up Parsers 2 he Functionality of the Parser Input: sequence of
More information" dx v(x) $ % You may also have seen this written in shorthand form as. & ' v(x) + u(x) '# % ! d
Calculus II MAT 146 Mthods of Intgration: Intgration by Parts Just as th mthod of substitution is an intgration tchniqu that rvrss th drivativ procss calld th chain rul, Intgration by parts is a mthod
More informationThe Network Layer: Routing Algorithms. The Network Layer: Routing & Addressing Outline
PS 6 Ntwork Programming Th Ntwork Layr: Routing lgorithms Michl Wigl partmnt of omputr Scinc lmson Univrsity mwigl@cs.clmson.du http://www.cs.clmson.du/~mwigl/courss/cpsc6 Th Ntwork Layr: Routing & ddrssing
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS164 Lecture 11 1 Administrivia Test I during class on 10 March. 2/20/08 Prof. Hilfinger CS164 Lecture 11
More informationCPSC 826 Internetworking. The Network Layer: Routing & Addressing Outline. The Network Layer: Routing Algorithms. Routing Algorithms Taxonomy
PS Intrntworking Th Ntwork Layr: Routing & ddrssing Outlin Th Ntwork Layr: Routing lgorithms Michl Wigl partmnt of omputr Scinc lmson Univrsity mwigl@cs.clmson.du Novmbr, Ntwork layr functions Routr architctur
More informationProblem Set 1 (Due: Friday, Sept. 29, 2017)
Elctrical and Computr Enginring Mmorial Univrsity of Nwfoundland ENGI 9876 - Advancd Data Ntworks Fall 2017 Problm St 1 (Du: Friday, Spt. 29, 2017) Qustion 1 Considr a communications path through a packt
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 9/22/06 Prof. Hilfinger CS164 Lecture 11 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient
More informationSystems in Three Variables. No solution No point lies in all three planes. One solution The planes intersect at one point.
3-5 Systms in Thr Variabls TEKS FOCUS VOCABULARY TEKS (3)(B) Solv systms of thr linar quations in thr variabls by using Gaussian limination, tchnology with matrics, and substitution. Rprsntation a way
More informationLR Parsing Techniques
LR Parsing Techniques Introduction Bottom-Up Parsing LR Parsing as Handle Pruning Shift-Reduce Parser LR(k) Parsing Model Parsing Table Construction: SLR, LR, LALR 1 Bottom-UP Parsing A bottom-up parser
More informationGreedy Algorithms. Interval Scheduling. Greedy Algorithm. Optimality. Greedy Algorithm (cntd) Greed is good. Greed is right. Greed works.
Algorithm Grdy Algorithm 5- Grdy Algorithm Grd i good. Grd i right. Grd work. Wall Strt Data Structur and Algorithm Andri Bulatov Algorithm Grdy Algorithm 5- Algorithm Grdy Algorithm 5- Intrval Schduling
More informationAbout Notes And Symbols
About Nots And Symbols by Batric Wildr Contnts Sht 1 Sht 2 Sht 3 Sht 4 Sht 5 Sht 6 Sht 7 Sht 8 Sht 9 Sht 10 Sht 11 Sht 12 Sht 13 Sht 14 Sht 15 Sht 16 Sht 17 Sht 18 Sht 19 Sht 20 Sht 21 Sht 22 Sht 23 Sht
More information8.3 INTEGRATION BY PARTS
8.3 Intgration By Parts Contmporary Calculus 8.3 INTEGRATION BY PARTS Intgration by parts is an intgration mthod which nabls us to find antidrivativs of som nw functions such as ln(x) and arctan(x) as
More informationIntro to Bottom-up Parsing. Lecture 9
Intro to Bottom-up Parsing Lecture 9 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient Builds on ideas in top-down parsing Bottom-up is the preferred method
More informationLR Parsing LALR Parser Generators
Outline LR Parsing LALR Parser Generators Review of bottom-up parsing Computing the parsing DFA Using parser generators 2 Bottom-up Parsing (Review) A bottom-up parser rewrites the input string to the
More informationA Brief Summary of Draw Tools in MS Word with Examples! ( Page 1 )
A Brif Summary of Draw Tools in MS Word with Exampls! ( Pag 1 ) Click Viw command at top of pag thn Click Toolbars thn Click Drawing! A chckmark appars in front of Drawing! A toolbar appars at bottom of
More informationBuilding a Scanner, Part I
COMP 506 Ric Univrsity Spring 2018 Building a Scannr, Part I sourc cod IR Front End Optimizr Back End IR targt cod Copyright 2018, Kith D. Coopr & Linda Torczon, all rights rsrvd. Studnts nrolld in Comp
More informationSLR parsers. LR(0) items
SLR parsers LR(0) items As we have seen, in order to make shift-reduce parsing practical, we need a reasonable way to identify viable prefixes (and so, possible handles). Up to now, it has not been clear
More informationFormal Languages and Compilers Lecture VII Part 3: Syntactic A
Formal Languages and Compilers Lecture VII Part 3: Syntactic Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More information2018 How to Apply. Application Guide. BrandAdvantage
2018 How to Apply Application Guid BrandAdvantag Contnts Accssing th Grant Sit... 3 Wlcom pag... 3 Logging in To Pub Charity... 4 Rgistration for Nw Applicants ( rgistr now )... 5 Organisation Rgistration...
More informationUNIT-III BOTTOM-UP PARSING
UNIT-III BOTTOM-UP PARSING Constructing a parse tree for an input string beginning at the leaves and going towards the root is called bottom-up parsing. A general type of bottom-up parser is a shift-reduce
More informationIntersection-free Dual Contouring on Uniform Grids: An Approach Based on Convex/Concave Analysis
Intrsction-fr Dual Contouring on Uniform Grids: An Approach Basd on Convx/Concav Analysis Charli C. L. Wang Dpartmnt of Mchanical and Automation Enginring, Th Chins Univrsity of Hong Kong E-mail: cwang@ma.cuhk.du.hk
More informationEE 231 Fall EE 231 Homework 10 Due November 5, 2010
EE 23 Fall 2 EE 23 Homwork Du Novmbr 5, 2. Dsign a synhronous squntial iruit whih gnrats th following squn. (Th squn should rpat itslf.) (a) Draw a stat transition diagram for th iruit. This is a systm
More informationCSE 272 Assignment 1
CSE 7 Assignmnt 1 Kui-Chun Hsu Task 1: Comput th irradianc at A analytically (point light) For point light, first th nrgy rachd A was calculatd, thn th nrgy was rducd by a factor according to th angl btwn
More informationBottom 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.
Bottom up parsing Construct a parse tree for an input string beginning at leaves and going towards root OR Reduce a string w of input to start symbol of grammar Consider a grammar S aabe A Abc b B d And
More informationS Y N T A X A N A L Y S I S LR
LR parsing There are three commonly used algorithms to build tables for an LR parser: 1. SLR(1) = LR(0) plus use of FOLLOW set to select between actions smallest class of grammars smallest tables (number
More informationObjectives. Two Ways to Implement Lists. Lists. Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Chaptr 24 Implmnting Lists, Stacks, Quus, and Priority Quus CS2: Data Structurs and Algorithms Colorado Stat Univrsity Original slids by Danil Liang Modifid slids by Chris Wilcox Objctivs q To dsign common
More informationCompiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6
Compiler Design 1 Bottom-UP Parsing Compiler Design 2 The Process The parse tree is built starting from the leaf nodes labeled by the terminals (tokens). The parser tries to discover appropriate reductions,
More informationCS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG) Objectives Introduce Pushdown Automaton (PDA) Show that PDA = CFG In terms of descriptive power Pushdown Automaton (PDA) Roughly
More informationA left-sentential form is a sentential form that occurs in the leftmost derivation of some sentence.
Bottom-up parsing Recall For a grammar G, with start symbol S, any string α such that S α is a sentential form If α V t, then α is a sentence in L(G) A left-sentential form is a sentential form that occurs
More informationLecture 7: Deterministic Bottom-Up Parsing
Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationMODULE 14 SLR PARSER LR(0) ITEMS
MODULE 14 SLR PARSER LR(0) ITEMS In this module we shall discuss one of the LR type parser namely SLR parser. The various steps involved in the SLR parser will be discussed with a focus on the construction
More informationTop-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7
Top-Down Parsing and Intro to Bottom-Up Parsing Lecture 7 1 Predictive Parsers Like recursive-descent but parser can predict which production to use Predictive parsers are never wrong Always able to guess
More informationLR Parsing LALR Parser Generators
LR Parsing LALR Parser Generators Outline Review of bottom-up parsing Computing the parsing DFA Using parser generators 2 Bottom-up Parsing (Review) A bottom-up parser rewrites the input string to the
More informationLecture 8: Deterministic Bottom-Up Parsing
Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general
More informationMIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology
MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure
More informationMIT Specifying Languages with Regular Expressions and Context-Free Grammars
MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely
More informationR10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?
R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that
More informationDO NOW Geometry Regents Lomac Date. due. Similar by Transformation 6.1 J'' J''' J'''
DO NOW Gomtry Rgnts Lomac 2014-2015 Dat. du. Similar by Transformation 6.1 (DN) Nam th thr rigid transformations and sktch an xampl that illustrats ach on. Nam Pr LO: I can dscrib a similarity transformation,
More informationTCP Congestion Control. Congestion Avoidance
TCP Congstion Control TCP sourcs chang th snding rat by modifying th window siz: Window = min {Advrtisd window, Congstion Window} Rcivr Transmittr ( cwnd ) In othr words, snd at th rat of th slowst componnt:
More informationshift-reduce parsing
Parsing #2 Bottom-up Parsing Rightmost derivations; use of rules from right to left Uses a stack to push symbols the concatenation of the stack symbols with the rest of the input forms a valid bottom-up
More informationTop-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7
Top-Down Parsing and Intro to Bottom-Up Parsing Lecture 7 1 Predictive Parsers Like recursive-descent but parser can predict which production to use Predictive parsers are never wrong Always able to guess
More informationMIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Parse Table Construction Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Parse Tables (Review) ACTION Goto State ( ) $ X s0 shift to s2 error error goto s1
More informationOutline. Tasks for Exercise Six. Exercise Six Goals. Task One: Kinetic Energy Table. Nested for Loops. Laboratory VI Program Control Using Loops
Ercis 6 -- Loopig March 9, 6 Laboratory VI Program Cotrol Usig Loops Larry Cartto Computr Scic 6 Computig i Egirig ad Scic Outli Ercis si goals Outli tasks for rcis si Itroduc ida of std loops ad tabl
More informationMotivation. Synthetic OOD concepts and reuse Lecture 4: Separation of concerns. Problem. Solution. Deleting composites that share parts. Or is it?
Synthtic OOD concpts and rus Lctur 4: Sparation of concrns Topics: Complx concrn: Mmory managmnt Exampl: Complx oprations on composit structurs Problm: Mmory laks Solution: Rfrnc counting Motivation Suppos
More informationBottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing
Also known as Shift-Reduce parsing More powerful than top down Don t need left factored grammars Can handle left recursion Attempt to construct parse tree from an input string eginning at leaves and working
More informationCSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1
CSE P 501 Compilers LR Parsing Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts UW CSE P 501 Spring 2018
More informationWorkbook for Designing Distributed Control Applications using Rockwell Automation s HOLOBLOC Prototyping Software John Fischer and Thomas O.
Workbook for Dsigning Distributd Control Applications using Rockwll Automation s HOLOBLOC Prototyping Softwar John Fischr and Thomas O. Bouchr Working Papr No. 05-017 Introduction A nw paradigm for crating
More informationReimbursement Requests in WORKS
Rimbursmnt Rqusts in WORKS Important points about Rimbursmnts in Works Rimbursmnt Rqust is th procss by which UD mploys will b rimbursd for businss xpnss paid using prsonal funds. Rimbursmnt Rqust can
More informationParsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)
TD parsing - LL(1) Parsing First and Follow sets Parse table construction BU Parsing Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1) Problems with SLR Aho, Sethi, Ullman, Compilers
More informationCS 164 Programming Languages and Compilers Handout 9. Midterm I Solution
Midterm I Solution Please read all instructions (including these) carefully. There are 5 questions on the exam, some with multiple parts. You have 1 hour and 20 minutes to work on the exam. The exam is
More informationLexical and Syntax Analysis. Bottom-Up Parsing
Lexical and Syntax Analysis Bottom-Up Parsing Parsing There are two ways to construct derivation of a grammar. Top-Down: begin with start symbol; repeatedly replace an instance of a production s LHS with
More information3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino
3. Syntax Analysis Andrea Polini Formal Languages and Compilers Master in Computer Science University of Camerino (Formal Languages and Compilers) 3. Syntax Analysis CS@UNICAM 1 / 54 Syntax Analysis: the
More informationCS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables by Wim Bohm and Michelle Strout. CS453 Shift-reduce Parsing 1
CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables by Wim Bohm and Michelle Strout CS453 Shift-reduce Parsing 1 Plan for Today Finish PA1 this week Friday recitation: help with
More informationLesson Focus: Finding Equivalent Fractions
Lsson Plans: Wk of 1-26-15 M o n Bindrs: /Math;; complt on own, thn chck togthr Basic Fact Practic Topic #10 Lsson #5 Lsson Focus: Finding Equivalnt Fractions *Intractiv Larning/Guidd Practic-togthr in
More informationLecture Bottom-Up Parsing
Lecture 14+15 Bottom-Up Parsing CS 241: Foundations of Sequential Programs Winter 2018 Troy Vasiga et al University of Waterloo 1 Example CFG 1. S S 2. S AyB 3. A ab 4. A cd 5. B z 6. B wz 2 Stacks in
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 8! Bo;om- Up Parsing Shi?- Reduce LR(0) automata and
More informationCompilers. Bottom-up Parsing. (original slides by Sam
Compilers Bottom-up Parsing Yannis Smaragdakis U Athens Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Bottom-Up Parsing More general than top-down parsing And just as efficient Builds
More informationLR Parsers. Aditi Raste, CCOEW
LR Parsers Aditi Raste, CCOEW 1 LR Parsers Most powerful shift-reduce parsers and yet efficient. LR(k) parsing L : left to right scanning of input R : constructing rightmost derivation in reverse k : number
More informationCS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).
CS 2210 Sample Midterm 1. Determine if each of the following claims is true (T) or false (F). F A language consists of a set of strings, its grammar structure, and a set of operations. (Note: a language
More informationDownloaded from Page 1. LR Parsing
Downloaded from http://himadri.cmsdu.org Page 1 LR Parsing We first understand Context Free Grammars. Consider the input string: x+2*y When scanned by a scanner, it produces the following stream of tokens:
More informationMidterm I (Solutions) CS164, Spring 2002
Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions
More informationPresentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Directed Graphs BOS SFO
Prsntation for us with th txtbook, Algorithm Dsign and Applications, by M. T. Goodrich and R. Tamassia, Wily, 2015 Dirctd Graphs BOS ORD JFK SFO LAX DFW MIA 2015 Goodrich and Tamassia Dirctd Graphs 1 Digraphs
More informationBottom Up Parsing Handout. 1 Introduction. 2 Example illustrating bottom-up parsing
Bottom Up Parsing Handout Compiled by: Nomair. Naeem dditional Material by: driel Dean-Hall and Brad Lushman his handout is intended to accompany material covered during lectures and is not consered a
More informationCSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1
CSE 401 Compilers LR Parsing Hal Perkins Autumn 2011 10/10/2011 2002-11 Hal Perkins & UW CSE D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts 10/10/2011
More informationUNIT III & IV. Bottom up parsing
UNIT III & IV Bottom up parsing 5.0 Introduction Given a grammar and a sentence belonging to that grammar, if we have to show that the given sentence belongs to the given grammar, there are two methods.
More informationCS 4120 Introduction to Compilers
CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 6: Bottom-Up Parsing 9/9/09 Bottom-up parsing A more powerful parsing technology LR grammars -- more expressive than LL can handle
More informationThe semantic WEB Roles of XML & RDF
Th smantic WEB Rols of XML & RDF STEFAN DECKER AND SERGEY MELNIK FRANK VAN HARMELEN, DIETER FENSEL, AND MICHEL KLEIN JEEN BROEKSTRA MICHAEL ERDMANN IAN HORROCKS Prsntd by: Iniyai Thiruvalluvan CSCI586
More informationSection A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.
Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or
More informationLR Parsing Techniques
LR Parsing Techniques Bottom-Up Parsing - LR: a special form of BU Parser LR Parsing as Handle Pruning Shift-Reduce Parser (LR Implementation) LR(k) Parsing Model - k lookaheads to determine next action
More informationPART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309
PART 3 - SYNTAX ANALYSIS F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 64 / 309 Goals Definition of the syntax of a programming language using context free grammars Methods for parsing
More informationLALR Parsing. What Yacc and most compilers employ.
LALR Parsing Canonical sets of LR(1) items Number of states much larger than in the SLR construction LR(1) = Order of thousands for a standard prog. Lang. SLR(1) = order of hundreds for a standard prog.
More informationIntroduction to Data Mining
Introduction to Data Mining Lctur #15: Clustring-2 Soul National Univrsity 1 In Tis Lctur Larn t motivation and advantag of BFR, an xtnsion of K-mans to vry larg data Larn t motivation and advantag of
More informationTo Do. Mesh Data Structures. Mesh Data Structures. Motivation. Outline. Advanced Computer Graphics (Fall 2010) Desirable Characteristics 1
Advancd Computr Graphics (Fall 200) CS 283, Lctur 5: Msh Data Structurs Ravi Ramamoorthi http://inst.cs.brkly.du/~cs283/fa0 To Do Assignmnt, Du Oct 7. Start rading and working on it now. Som parts you
More informationMaxwell s unification: From Last Time. Energy of light. Modern Physics. Unusual experimental results. The photoelectric effect
From Last Tim Enrgy and powr in an EM wav Maxwll s unification: 1873 Intimat connction btwn lctricity and magntism Exprimntally vrifid by Hlmholtz and othrs, 1888 Polarization of an EM wav: oscillation
More informationLR Parsing E T + E T 1 T
LR Parsing 1 Introduction Before reading this quick JFLAP tutorial on parsing please make sure to look at a reference on LL parsing to get an understanding of how the First and Follow sets are defined.
More informationOn Some Maximum Area Problems I
On Som Maximum Ara Problms I 1. Introdution Whn th lngths of th thr sids of a triangl ar givn as I 1, I and I 3, thn its ara A is uniquly dtrmind, and A=s(s-I 1 )(s-i )(s-i 3 ), whr sis th smi-primtr t{i
More informationBottom-Up Parsing. Parser Generation. LR Parsing. Constructing LR Parser
Parser Generation Main Problem: given a grammar G, how to build a top-down parser or a bottom-up parser for it? parser : a program that, given a sentence, reconstructs a derivation for that sentence ----
More informationCompilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University
Compilation 2012 Parsers and Scanners Jan Midtgaard Michael I. Schwartzbach Aarhus University Context-Free Grammars Example: sentence subject verb object subject person person John Joe Zacharias verb asked
More informationWWW.STUDENTSFOCUS.COM UNIT -3 SYNTAX ANALYSIS 3.1 ROLE OF THE PARSER Parser obtains a string of tokens from the lexical analyzer and verifies that it can be generated by the language for the source program.
More informationParser Self-Training for Syntax-Based Machine Translation
arsr Slf-Training for Syntax-Basd Machin Translation Makoto Morishita, Koichi Akab, Yuto Hatakoshi Graham ubig, Koichiro Yoshino, Satoshi akamrua Graduat School of Information Scinc ara Institut of Scinc
More informationAmbiguity, Precedence, Associativity & Top-Down Parsing. Lecture 9-10
Ambiguity, Precedence, Associativity & Top-Down Parsing Lecture 9-10 (From slides by G. Necula & R. Bodik) 9/18/06 Prof. Hilfinger CS164 Lecture 9 1 Administrivia Please let me know if there are continued
More informationCS453 : JavaCUP and error recovery. CS453 Shift-reduce Parsing 1
CS453 : JavaCUP and error recovery CS453 Shift-reduce Parsing 1 Shift-reduce parsing in an LR parser LR(k) parser Left-to-right parse Right-most derivation K-token look ahead LR parsing algorithm using
More informationJNTUWORLD. Code No: R
Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five
More informationTo Do. Advanced Computer Graphics. Motivation. Mesh Data Structures. Outline. Mesh Data Structures. Desirable Characteristics 1
Advancd Computr Graphics CSE 63 [Spring 208], Lctur 7 Ravi Ramamoorthi http://www.cs.ucsd.du/~ravir To Do Assignmnt, Du Apr 27 Any last minut issus or difficultis? Starting Gomtry Procssing Assignmnt 2
More informationSYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram
CS6660 COMPILER DESIGN Question Bank UNIT I-INTRODUCTION TO COMPILERS 1. Define compiler. 2. Differentiate compiler and interpreter. 3. What is a language processing system? 4. List four software tools
More informationOutline. Parser overview Context-free grammars (CFG s) Derivations Syntax-Directed Translation
Outline Introduction to Parsing (adapted from CS 164 at Berkeley) Parser overview Context-free grammars (CFG s) Derivations Syntax-Directed ranslation he Functionality of the Parser Input: sequence of
More informationCS606- compiler instruction Solved MCQS From Midterm Papers
CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a
More informationProbabilistic inference
robabilistic infrnc Suppos th agnt has to mak a dcision about th valu of an unobsrvd qury variabl X givn som obsrvd vidnc E = artially obsrvabl, stochastic, pisodic nvironmnt Eampls: X = {spam, not spam},
More informationEfficient Obstacle-Avoiding Rectilinear Steiner Tree Construction
Efficint Obstacl-Avoiding Rctilinar Stinr Tr Construction Chung-Wi Lin, Szu-Yu Chn, Chi-Fng Li, Yao-Wn Chang, and Chia-Lin Yang Graduat Institut of Elctronics Enginring Dpartmnt of Elctrical Enginring
More information