{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 9

# Items cse341 a is c lr1 item a programming

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: string) set nullable[X] = true for each i from 1 to k and each j from i +1 to k if Y1 … Yi- 1 are all nullable (or if i = 1) add FIRST[Yi ] to FIRST[X ] if Yi+1 … Yk are all nullable (or if i = k ) add FOLLOW[X ] to FOLLOW[Yi ] if Yi+1 … Yj- 1 are all nullable (or if i+1=j) add FIRST[Yj ] to FOLLOW[Yi ] Un]l FIRST, FOLLOW, and nullable do not change 2/4/13 S ::= E \$ E ::= T + E E ::= T T ::= x CSE341: Programming CSE341: Programming Languages Languages LR(0) Parser for 0. 1. 2. 3. x \$ Lecture 1 Lecture 1 + 1 s5 S ::= E . \$ Course S ::= . E \$ Course Mechanics Mechanics 2 acc E ::= . T + E ML Variable Bindings 3 E ::= . T ML Variable Bindings r2 3 s4,r2 r2 1 2 T ::= . x x 5 T ::= x . 6 E ::= T + E. T E ::= T . + E DE ::= T . an Grossman Fall 2011T + x E 4 E E E E Winter 2013 ::= ::= ::= ::= 4 s5 Dan Grossman 5 r3 Fall 2011 r3 6 T+.E .T+E .T .x r1 r1 E T g2 g3 g6 E g3 r3 r1 FOLLOW(T) = { +, \$ } FOLLOW(E) = { \$ } 21 UW CSE 401 (Michael Ringenburg) S ::= E \$ E ::= T + E E ::= T T ::= x CSE341: Programming CSE341: Programming Languages Languages SLR Parser for 0. 1. 2. 3. x \$ Lecture 1 Lecture 1 + 1 s5 S ::= E . \$ Course S ::= . E \$ Course Mechanics Mechanics 2 acc E ::= . T + E ML Variable Bindings 3 E ::= . T ML Variable Bindings r2 3 s4,r2 r2 1 2 T ::= . x x 5 T ::= x . 6 E ::= T + E. Winter 2013 T E ::= T . + E DE ::= T . an Grossman Fall 2011T + x E 4 E E E E ::= ::= ::= ::= T+.E .T+E .T .x 4 s5 Dan Grossman 5 r3 Fall 2011 r3 6 r1 r1 E T g2 g3 g6 E g3 r3 r1 FOLLOW(T) = { +, \$ } FOLLOW(E) = { \$ } UW CSE 401 (Michael Ringenburg) 22 2/4/13 LR(1) grammars CSE341: Programming CSE341: Programming Languages Languages •  Many prac]cal grammars are SLR Lecture 1 Lecture 1 •  LR(1) is more powerful yet Mechanics Course Course Mechanics ML ut no]on of an item is •  Similar construc]on, bVariable Bindings ML Variable Bindings more complex, incorpora]ng lookahead Dan Grossman Dan Grossman Fall 2011 informa]on Fall 2011 Winter 2013 UW CSE 401 (Michael Ringenburg) 23 LR(1) Items CSE341: β, a] is C LR(1) item [A ::= α . Programming •  An SE341: Programming Languages Languages –  A grammar pLecture 1(A ::= αβ) 1 roduc]on Lecture –  A right hand side posi]on (the Mechanics Course dot) Course Mechanics –  A lookahead symbol ML Variable Bindings (a) M i Variable Bindings •  Idea: This Ltem indicates that an A followed by an a would be consistent with the input the parser Dan Grossman has seen up tDanhis point. Fall 2011 o t Grossman •  Item [A ::= α . , Fall means reduce to A if the next a] 2011 symbol (...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern