120 likes | 205 Views
NAMAN DASOT 11CS10031 21 Aug 2013. First() and Follow(). If X is terminal, then a є First(X ). First() and Follow(). If X is terminal, then a є First(X ) If X is Non-terminal, X derives epsilon production , then (є) є First(X ). First() and Follow(). If X is terminal, then a є First(X )
E N D
First() and Follow() • If X is terminal, then a є First(X)
First() and Follow() • If X is terminal, then a є First(X) • If X is Non-terminal, X derives epsilon production, then (є) є First(X)
First() and Follow() • If X is terminal, then a є First(X) • If X is Non-terminal, X derives epsilon production, then (є) є First(X) • If X is Non-terminal and X -> Y1Y2..Yi, where Yi may be Terminal or Non-Terminal, then, First(X) = First(Yi), i = 1, 2,…, n. ( If Yi is not a epsilon production.)
Some Examples • A -> αBβ => Follow (B) = First (β)
Some Examples • A -> αBβ => Follow (B) = First (β) • A -> αβ => Follow(β) = Follow(A)
Some Examples • A -> αBβ => Follow (B) = First (β) • A -> αβ => Follow(β) = Follow(A) • s -> xAa A -> αβ => Follow(β) = ‘a’ = Follow(A)
A Complete Example Example: Given a Grammar, find Follows and Firsts of E , E’ , T , T’ , F. E -> TE’ E’ -> +TE’ | є T -> FT’ T’ -> *FT’ | є F -> (E) | id
SOLUTION • FIRSTS are: • First(F) = { (, id } • First(T) = { є, id } • First(E) = { є, id } • First(T’) = { є, *} • First(E’) = { є,+}
SOLUTION (Cont.) • FOLLOWS are: • FOLLOW(E) = { ),$ } • FOLLOW(E’) = { ),$ } • FOLLOW(T) = { +,),$ } • FOLLOW(T’) = { +,),$ } • FOLLOW(F) = { *,+,),$ }
PROPERTIES • A -> α | β • First (α) • First (β ) • At most one of α, β is ε • If β -> ε then, First (α) First (β ) DISJOINT DISJOINT
THANK YOU -Naman Dasot 11CS10031