1 / 12

NAMAN DASOT 11CS10031 21 Aug 2013

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 )

simone
Download Presentation

NAMAN DASOT 11CS10031 21 Aug 2013

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NAMAN DASOT11CS1003121 Aug 2013

  2. First() and Follow() • If X is terminal, then a є First(X)

  3. First() and Follow() • If X is terminal, then a є First(X) • If X is Non-terminal, X derives epsilon production, then (є) є First(X)

  4. 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.)

  5. Some Examples • A -> αBβ => Follow (B) = First (β)

  6. Some Examples • A -> αBβ => Follow (B) = First (β) • A -> αβ => Follow(β) = Follow(A)

  7. Some Examples • A -> αBβ => Follow (B) = First (β) • A -> αβ => Follow(β) = Follow(A) • s -> xAa A -> αβ => Follow(β) = ‘a’ = Follow(A)

  8. 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

  9. SOLUTION • FIRSTS are: • First(F) = { (, id } • First(T) = { є, id } • First(E) = { є, id } • First(T’) = { є, *} • First(E’) = { є,+}

  10. SOLUTION (Cont.) • FOLLOWS are: • FOLLOW(E) = { ),$ } • FOLLOW(E’) = { ),$ } • FOLLOW(T) = { +,),$ } • FOLLOW(T’) = { +,),$ } • FOLLOW(F) = { *,+,),$ }

  11. PROPERTIES • A -> α | β • First (α) • First (β ) • At most one of α, β is ε • If β -> ε then, First (α) First (β ) DISJOINT DISJOINT

  12. THANK YOU -Naman Dasot 11CS10031

More Related