Add firstyi to firstx winter 2013 uw cse 401 michael

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: r 2013 UW CSE 401 (Michael Ringenburg) 8 2/4/13 Observa]on 1 CSE341: Programming CSE341: Programming Languages Languages •  Given a produc]on X ::= Y1 Y2 … Yk Lecture 1 Lecture 1 –  If every symbol on the right iMechanics(or if there s nullable Course Course Mechanics then X is nullable. are 0 symbols on the Light), M r Variable Bindings ML Variable Bindings Dan Grossman if Y1 … Yk Dan Grossman ullable (or k == 0)! are all n Fall 2011 Fall 2011 set nullable[X] = true! Winter 2013 UW CSE 401 (Michael Ringenburg) 9 Observa]on 2 CSE341: Programming CSE341: Programming Languages Languages •  Given a produc]on X ::= Y1 Y2 … Yk and 1 ≤ i ≤ k Lecture 1 L symbols on the right are a 1 –  If the first i- 1 ecture Course Mechanics ll nullable, Course Mechanics then a string derived Lrom X could begin with any M f Variable Bindings ML Variable Bindings terminal that could begin a string derived from Yi. Dan Grossman F re all aall 2011 Dan Grossman Fall 2011 if Y1 … Yi-1 nullable (or i == 1)! add FIRST[Yi] to FIRST[X]! Winter 2013 UW CSE 401 (Michael Ringenburg) 10 2/4/13 Observa]on 3 CSE341: Programming CSE341: Programming Languages Languages •  Given a produc]on X ::= Y1 Y2 … Yk and 1 ≤ i ≤ k Lecture 1 Lecture 1 is nullable, then –  If every symbol a[er Yourse Mechanics anything Ci Course Mechanicslso f that could follow X ML Variableollow Yi. could a Bindings ML Variable Bindings Dan Grossman Grossman if Yi+1 … YDan re all nullable (or i == k )! ka Fall 2011 Fall 2011 add FOLLOW[X] to FOLLOW[Yi]! Winter 2013 UW CSE 401 (Michael Ringenburg) 11 Observa]on 4 CSE341: Programming CSE341: Programming Languages Languages •  Given a produc]on X ::= Y1 Y2 … Yk and 1 ≤ i ≤ j ≤ k Lecture 1 Lecture 1 –  If every symbol between Yi aMechanics nd Yj is nullable, then Course ould sCoursecould follow Y . Mechanics anything that c Mtart Yj L Variable Bindings i ML Variable Bindings Dan Grossman if Yi+1 … YDan Grossman nFall 2011 ullable (or i+1==j)! j-1 are all Fall] to FOLLOW[Y ]! 2011 add FIRST[Yj i Winter 2013 UW CSE 401 (Michael Ringenburg) 12 2/4/13 Puong it all together CSE341: Programming CSE341: Programming Languages Languages •  Ini]aliza]on Lecture 1 Land FOLLOWs o be empty 1 set all FIRSTs ecture Course tMechanics sets Course Mechanics set nullable to false for all symbols ML Variable Bindings ML Variable Bindings set FIRST[a] to a for all terminal symbols a Dan Grossman Fall 2011 Winter 2013 Dan Grossman Fall 2011 UW CSE 401 (Michael Ringenburg) 13 Puong it all together CSE341: Programming CSE341: Programming Languages Languages repeat for each produc]on X := Y1 Y2Lecture 1 Lecture 1 … Yk if Y1 … Yk are all nMechanicsk = 0, i.e., empty string) C or if Course ullable (ourse Mechanics set nullable[X]...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online