## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

:

S → XaY | Y X → bY | c Y → X

I0: {S ′ → ·S, S → ·XaY, S → ·Y, X → ·bY, X → ·c, Y → ·X} I1: {S ′ → S·} I2: {S → X · aY, Y → X·} I3: {S → Y ·} I4: {X → b · Y, Y → ·X, X → ·bY, X → ·c} I5: {X → c·} I6: {S → Xa · Y, Y → ·X, X → ·bY, X → ·c} I7: {X → bY ·} I8: {Y → X·} I9: {S → XaY ·}

1

2

2 3. X → ·bY. Y → ·X. X → ·c. S → ·Y. S → ·XaY. Y → X·} I3: {S → Y ·} I4: {X → b · Y. Y → X·} I0: {S → ·S. Y → ·X} I3: {S → Y ·} I4: {X → b · Y. S → ·XaY. X → ·c} I7: {X → bY ·} FOLLOW(S) = {$} FOLLOW(Y ) = {a. 2 3. X → ·bY.0 1. 4 5 I1: {S ′ → S·} S′ → S S → XaY | Y X → bY | c Y →X I2: {S → X · aY. X → ·c. Y → ·X. X → ·c} I5: {X → c·} I6: {S → Xa·Y. Y → ·X. X → ·bY. X → ·bY. $} STATE 0 1 2 3 4 5 6 7 8 9 a action b c $ S goto X Y STATE a 0 1 2 s6.r5? 3 4 s4 5 r4 6 s4 7 r3 8 r5 9 action b c s4 s5 $ acc r5 r2 S 1 goto X 2 Y 3 s5 r4 s5 r3 r5 r1 4 8 8 7 9 3 . X → ·bY. X → ·bY. S → ·Y. Y → ·X} I1: {S → S·} ′ I0: {S → ·S. $} I8: {Y → X·} I9: {S → XaY ·} FOLLOW(X) = {a. 4 5 ′ S′ → S S → XaY | Y X → bY | c Y →X ′ 0 1. X → ·c} I5: {X → c·} I6: {S → Xa·Y. X → ·c} I7: {X → bY ·} FOLLOW(S) = {$} FOLLOW(Y ) = {a. $} I8: {Y → X·} I9: {S → XaY ·} FOLLOW(X) = {a. $} I2: {S → X · aY. Y → ·X.

. 2 3. 4 5 S′ → S S → XaY | Y X → bY | c Y →X goto X 2 action b c s4 s5 STATE 0 1 2 3 4 5 6 7 8 9 a action b c s4 s5 $ acc r5 r2 S 1 Y 3 s6. ACTION s5 r4 s6. not r5! s5 r4 r5 r1 acc STACK 0 0c5 0X2 0Y3 0S1 INPUT cac$ ac$ ac$ ac$ ac$ ACTION s5 r4 try r5. Otherwise the parse will fail. . the stack should always contain a viable preﬁx. 2 3. .0 1. instead of s6 r2 error In LR parsing. 6 . and the stack plus lookahead (unless it’s $) should be a preﬁx of a right-sentential form.r5? r2 r4 r3 r5 s6. 4 5 STATE 0 1 2 3 4 5 6 7 8 9 a S′ → S S → XaY | Y X → bY | c Y →X $ acc r5 r2 s4 s5 r4 s4 s5 r3 r5 r1 8 9 8 7 S 1 goto X 2 Y 3 0 1. .r5? r2 s4 r4 s4 r3 r5 s5 s5 8 r4 8 r3 r5 r1 7 9 Let’s try a parse: STACK 0 0c5 0X2 0X2a6 0X2a6c5 0X2a6X8 0X2a6Y9 0S1 INPUT cac$ ac$ ac$ c$ $ $ $ $ 5 Let’s try the alternative.

. S ⇒ XaY ⇒ bY aY To get an a we must use production S → XaY . we had better not reduce X to Y : Y a is not a preﬁx of a right-sentential form. X → ·bY. and reduction by 5 leaves us with stack Y (that is. the stack contains X (that is.0 S′ → S S → XaY | Y X → bY | c Y →X 0 1. Y → ·X} I1: {S ′ → S·} I3: {S → Y ·} I5: {X → c·} I7: {X → bY ·} I2: {S → X · aY. what viable preﬁxes take the parser to state 2? X only! Whenever the parser is in state 2 with lookahead a. X → ·bY. X → ·c} I8: {Y → X·} I9: {S → XaY ·} If we have X on the stack. 7 8 . . Y → ·X. So in state 2. X → ·bY. the parser should reduce with production 5. Y → ·X. The problem is with the use of FOLLOW sets to decide when to reduce. with lookahead a. Y → X·} I4: {X → b · Y. 2 3. 0X2). 2 3. The SLR parsing table isn’t adequate.) So. $} 1. . X → ·c. X → ·c} I6 : {S → Xa · Y. 0Y 3) — in which case the stack plus lookahead is not a preﬁx of any right-sentential form. (So we can’t get substring Y a without a leading b. . 4 5 S′ → S S → XaY | Y X → bY | c Y →X FOLLOW(Y ) = {a. S → ·Y. which we can do only with production X → bY . we must produce a Y from the X. 4 5 I0: {S ′ → ·S. with lookahead a. Then to get a Y in front of that a. in state 2 on lookahed a. we should always shift and go to state 6.) (Notice that in this case we showed that Ba is not a preﬁx of any sentential form — of course it follows that it is not a preﬁx of any right-sentential form. But maybe there are still cases in which. S → ·XaY. despite the fact that a ∈ FOLLOW(Y ).

If [X → α · Y β. LR(1) closure function Deﬁnition Given a set I of LR(1) items from an augmented grammar. then [X → α · β. a] . which are smaller and weaker (and are what yacc builds!). Deﬁnition An LR(1) item is a pair of an LR(0) item and a token or $. I suspect this is not true. Both methods can handle the previous examples.t. a] calls for reduction by X → αβ if the lookahead token is a.) . and can be parsed by the LR method. Why not true? Because the deﬁnition of FOLLOW is about existence of sentential forms. but this deﬁnition is not. we will reduce by a production X → α only on those lookaheads a for which there is an item [X → α·. the lookahead a has no eﬀect if β = ǫ. closure(I) is the least set of items satisfying the following two conditions: 1. The set of such a’s is always a subset of FOLLOW(X). Intuitively. We’ll look ﬁrst at canonical LR parsing tables. LR(1) items The grammar in the previous example is not ambiguous. but it is suggestive. a] ∈ closure(I) and there is an LR(1) item [Y → ·γ. if only we can construct a more adequate parsing table.Canonical LR parsing tables. 9 10 Claim: FIRST(βa) ⊆ FOLLOW(Y ). then s. b] ∈ closure(I) . to better take into account lookahead tokens. but if β = ǫ. I ⊆ closure(I) 2. Then LALR parsing tables. Thus. (As elsewhere. b] b ∈ FIRST(βa) [Y → ·γ. typically written [X → α · β. We begin by enriching the notion of an item. a].

Now consider X → ·bY and X → ·c. 4 5 S′ → S S → XaY | Y X → bY | c Y →X 1. 0 1. I ⊆ closure(I) 2. a]. 0 1. I ⊆ closure(I) 2. $]. a] ∈ closure(I) and there is an LR(1) item [Y → ·γ. a] and [X → ·c. so FIRST(β$) = {a}. Since FIRST(β$) = {$}. Now consider X → ·bY and X → ·c. $]. Here again β = ǫ.t.t. we add item [Y → ·X. [Y → X·. we add [Y → ·X. b ∈ FIRST(βa). Now consider Y → ·X. 2 3. $]})? So we consider LR(1) items with ﬁrst components S → ·XaY and S → ·Y . so FIRST(β$) = {$}. $] and [X → ·c. If [X → α · Y β. In this case. $]})? What is closure({[X → b · Y. with β = ǫ. Now consider X → ·bY and X → ·c. Since FIRST(β$) = {$}. a|$] and [X → ·c. 11 12 closure({[S → X · aY . so FIRST(β$) = {$} and FIRST(βa) = {a}. then [Y → ·γ. Thus we add [X → ·bY. $]. 2 3. $]})? . In this case. If [X → α · Y β. b] ∈ closure(I) . $] and [S → ·Y. What is closure({[S → Xa · Y. b ∈ FIRST(βa). then [Y → ·γ. Here β = aY . and since FIRST(βa) = {a}. a|$]})? (stands for 2 LR(1) items) Consider LR(1) items with ﬁrst component Y → ·X. β = ǫ. we add [Y → ·X. b] s. a]. Thus we add items [X → ·bY. So we add LR(1) items [S → ·XaY .1. with β = ǫ. β = ǫ. Since FIRST(β$) = {$}. $]. we add items [X → ·bY. b] s. a|$]. b] ∈ closure(I) . a] ∈ closure(I) and there is an LR(1) item [Y → ·γ. $]. 4 5 Example What is S′ → S S → XaY | Y X → bY | c Y →X Example What is closure({[S ′ → ·S.

$]}) }. a|$]. [X → ·c. with the LR(1) versions of closure and goto. [Y → ·X. a|$]}) = {[X → b · Y. $]. goto(I. X) is the closure of the set of all LR(1) items s. goto(I. repeat for each set of LR(1) items I ∈ C and each grammar symbol X s. S) = closure({[S → S·. $]} goto(I0. [A → αX · β. Example I0: {[S ′ → ·S. a|$]. 14 . a|$]. [S → ·Y.LR(1) goto function Deﬁnition For any set I of LR(1) items and grammar symbol X. [Y → X·. [X → ·c. $]}) = {[S → Y · . [Y → X·. a] ∈ I . [Y → ·X. $]. $]}) = {[S → X · aY . $]} goto(I0. $] [X → ·bY. c) = closure({[X → c · . a|$]} 13 ′ ′ Construction of sets of LR(1) items Here is the algorithm for construction of the canonical collection of sets of LR(1) items for an augmented grammar: C := { closure({[S ′ → ·S.t. $]}) goto(I0. a|$]}) = {[X → c · . $]. X) is not empty and is not already in C do add goto(I. b) = closure({[X → b · Y. $]} goto(I0. X) = closure({[S → X · aY . a|$]} goto(I0. a|$]. a|$]. $]. a] [A → α · Xβ. $]}) = {[S → S·. X) to C until no more sets of items can be added to C in this way So this is the same construction we used for LR(0) items — but now for LR(1) items. and the initial LR(1) item. [S → ·XaY .t. [X → ·bY. Y ) = closure({[S → Y ·.

15 . If Ik = closure({[S ′ → ·S. If any conﬂicting actions are generated in step 2. . the grammar is “not LR(1)”. then goto(k. A) is the corresponding goto entry. and we’ll often write k to refer to the state Ik . 5. Each element of C is a “state”. For all states k and variables A. All remaining undeﬁned entries have action “error”. $] ∈ k and a = $. . a] ∈ k and B is not S ′ . In } of sets of LR(0) items. .Construction of canonical LR(1) parsing table 1. then k is the initial state of the parser. A) is nonempty. then “accept” is applicable. a) = j. 2. c) If [S ′ → S·. $]}). if goto(k. 4. The applicable parsing actions for state k and lookahead a are determined as follows: a) If goto(k. then “shift and go to state j” is applicable. b) If [B → α·. . then “reduce by production B → α” is applicable. 3. Construct the canonical collection C = {I0.

- Correction_TD-3-C++
- Project Plan - Resources Req and Risk Analysis - KP
- Simple Past Tense
- Nesting Statement With And
- 1 e Grammar Avere Revised June 2014
- 12mgu Btech2010 It
- Eduardo
- Override
- Elliptic Structure
- cse_5_8sem
- Slides Mooshak 2011
- b1 Lan Text and Voice Chat
- Embedded Seminar
- CS654
- cs671-04-topdown
- English Exam
- Test Za Cetvrto-posleden
- Kids Box 3 Exam Summer 2010
- Formatting Different Types of Writing
- Turbo BM
- Cho Ms Key Normal Form
- Regular and Irregular Verb List
- Advanced English Grammar
- chapter 8 study guide
- Yearly Scheme of Work Year 3 2010
- How to Statspack
- Practice to English
- Example Europass Curriculum Vitae_2
- BS CS Curriculum (2010)
- FT19981_5 - Play Tricks on Your Memory

- Object Oriented Programming 2011
- UT Dallas Syllabus for cs4337.001.09f taught by Shyam Karrah (skarrah)
- UT Dallas Syllabus for se3376.002.10f taught by Jeyakesavan Veerasamy (veerasam)
- UT Dallas Syllabus for se3376.5e3.11s taught by Mark Nelson (mrn017000)
- UT Dallas Syllabus for ba4318.0u1.09u taught by Abhijeet Ghoshal (axg053200)
- UT Dallas Syllabus for cs1136.002 05f taught by George Steinhorst (csteinh)
- UT Dallas Syllabus for cs1336.001 05s taught by Martha Sanchez (mxs015000)
- System Analysis and Design MCQ'S
- UT Dallas Syllabus for cs3v95.001 05s taught by Greg Ozbirn (ozbirn)
- UT Dallas Syllabus for cs1336.002 06s taught by Laurie Thompson (lthomp)
- GEARS January-February 2016
- UT Dallas Syllabus for mis6323.001.09s taught by Jayatirtha Asundi (jxa027000)
- UT Dallas Syllabus for cs4v95.001.09f taught by Xiaohu Guo (xxg061000)
- The Tower Undergraduate Research Journal Volume II
- UT Dallas Syllabus for mis6323.501 05f taught by Jayatirtha Asundi (jxa027000)
- UT Dallas Syllabus for cs3375.001 05s taught by Rafael Lacambra (rml021000)
- UT Dallas Syllabus for cs1337.003.07s taught by Timothy Farage (tfarage)
- UT Dallas Syllabus for cs1336.003 06s taught by Shyam Karrah (skarrah)
- UT Dallas Syllabus for cs4337.001 06s taught by Shyam Karrah (skarrah)
- UT Dallas Syllabus for cs1136.002 06s taught by George Steinhorst (csteinh)
- UT Dallas Syllabus for cs1336.003 05s taught by George Steinhorst (csteinh)
- Implementation OF irrigation Process using embedded PLC
- School of Computer Technology - Sunway University College 2011
- UT Dallas Syllabus for cs5375.502 05s taught by Rafael Lacambra (rml021000)
- UT Dallas Syllabus for se4376.001.08s taught by Yuke Wang (yuke)
- UT Dallas Syllabus for cs1336.501.11f taught by Feliks Kluzniak (fxk083000)
- UT Dallas Syllabus for cs4337.501 06s taught by Shyam Karrah (skarrah)
- UT Dallas Syllabus for cs4337.001.10f taught by Shyam Karrah (skarrah)
- SCT 2011
- UT Dallas Syllabus for cs1337.521 05u taught by George Steinhorst (csteinh)

Sign up to vote on this title

UsefulNot usefulClose Dialog## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

Close Dialog## This title now requires a credit

Use one of your book credits to continue reading from where you left off, or restart the preview.

Loading