This preview shows page 1. Sign up to view the full content.
Unformatted text preview: the be Grossman Fall 2011
F
set of symbols tall 2011 follow A in any possible hat can deriva]on – i.e., t is in FOLLOW(A) if any deriva]on contains At – To compute this, we need to compute FIRST(γ) for strings γ that can follow A Winter 2013 UW CSE 401 (Michael Ringenburg) 5 Calcula]ng FIRST(γ) CSE341: Programming
CSE341: Programming Languages Languages • Sounds easy… If γ = X Y Z , then FIRST(γ) is Lecture 1 Lecture 1
FIRST(X), right? Course
Course Mechanics Mechanics – But what iVariable Bindings X ::= ε? f we have tL Variable Bindings
M he rule ML
– In that case, FIRST(γ) includes FIRST(Y) … and Dan Grossman
FIRST(Z) if YDcan derive ε. Fall 2011 an Grossman
Fall 2011
– So, compu]ng FIRST and FOLLOW requires knowledge of other symbols FIRST and FOLLOW, as well as which symbols can derive ε. Winter 2013 UW CSE 401 (Michael Ringenburg) 6 2/4/13 So How Do We Calculate FIRST/FOLLOW? CSE341: Programming
CSE341: Programming Languages FOLLOW, and • Actually calculate three equa]ons: FIRST, Languages
nullable Lecture 1 Lecture 1
• nullable(X) is true if X can doursetMechanicstring C erive he empty s
Course Mechanics
• Given a string γ of terminals and non terminals, FIRST(γ) is ML Variable Bindings
ML Variable Bindings
the set of terminals that can begin strings derived from γ. – Actually, for SLR construc]on, jDanneed to calculate FIRST(X), ust Grossman
Dan Grossman
where X is a single symbol (terminal or nonterminal) Fall 2011 • FOLLOW(X) is the Fall 2011erminals that can immediately set of t
follow X in some deriva]on – We only really need this for nonterminals, but we’ll compute it for everything for illustra]on. • All three of these are computed together Winter 2013 UW CSE 401 (Michael Ringenburg) 7 Compu]ng FIRST, FOLLOW, and nullable CSE341: Programming
CSE341: Programming Languages Languages • We use another ﬁxed point algorithm Lecture 1
Course Mechanics
• Basically, FIRST(a) =Ma} for all terminals a { L Variable Bindings
ML Variable Bindings 1
– Start with a Limple ini]al state s ecture Course Mechanics – Repeatedly apply four simple observa]ons to modify the Dtate s an Grossman Dan Grossman
Fall 2011
Fall 2011
– Stop when the state no longer changes Winte...
View
Full
Document
This document was uploaded on 04/04/2014.
 Winter '09

Click to edit the document details