Lecture 9

Grossman fall initializefall 2011 empty 2011 r to for

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: = true L Variable Bindings ML from 1 to Mnd each for each i VariablekBindingsj from i +1 to k a if Y1 … Yi- 1 are all nullable (or if i = 1) Dan Grossman Dan Grossman add FIRST[Yi ] to FIRST[X ] Fall 2011 Fall nullable if Yi+1 … Yk are all 2011 (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 Winter 2013 UW CSE 401 (Michael Ringenburg) 14 2/4/13 Example Z ::= d Z ::= X Y Z Y ::= ε Y ::= c X ::= Y X ::= a repeat for each produc]on X := Y1 Y2 … Yk if Y1 … Yk are all nullable (or if k = 0, i.e., empty 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 LR(0) Reduce Ac]ons (review) CSE341: Programming Languages CSE341: •  In a LR(0) pProgramming Languages a reduc]on, it arser, if a state contains Lecture 1 L of the n is uncondi]onal regardless ecture 1 ext input Course Mechanics symbol Course Mechanics ML Variable Bindings ML Variable Bindings •  Algorithm, where R is the set of reduc]on ac]ons: Dan Grossman Dan Grossman Fall InitializeFall 2011 empty! 2011 R to for each state I in T ! for each item [A ::= α .] in I ! add (I, A ::= α) to R ! Winter 2013 UW CSE 401 (Michael Ringenburg) 17 2/4/13 SLR Construc]on CSE341: Programming CSE341: Programming Languages Languages •  This is iden]cal to LR(0) – states, etc., except Lecture 1 Lecture 1 for the calcula]on of reduce ac]ons. Course Mechanics Course Mechanics:= α •  Algorithm, where (I, a, Variable) means reduce ML A : Bindings ML Variable α to A in state I if tBindings he lookahead is ‘a’: Dan Grossman Dan Grossman Fall InitializeFall 2011 empty! 2011 R to for each state I in T ! for each item [A ::= α .] in I ! for each terminal a in FOLLOW(A) ! !add (I, a, A ::= α) to R ! Winter 2013 18 UW CSE 401 (Michael Ringenburg) S ::= E \$ E ::= T + E E ::= T T ::= x CSE341: Programming CSE341: Programming Languages Languages FIRST/FOLLOW for 0. 1. 2. 3. Lecture 1 Lecture 1 Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Dan Grossman repeat Fall 2011 for each produc]on X := Y1 Y2 … Yk Fall 2011 if Y1 … Yk are all nullable (or if k = 0, i.e., empty...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online