1 / 8

Tutorial-4

Tutorial-4. LL(1) Parsing. First Sets. Recall that we construct the first sets using the following algorithm Algorithm : If t is a terminal First (t) = { t } If X is non-terminal, then ξ ϵ First(X) If X → ξ

earnestinel
Télécharger la présentation

Tutorial-4

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. Tutorial-4 LL(1) Parsing

  2. First Sets • Recall that we construct the first sets using the following algorithm • Algorithm : • If t is a terminal First (t) = { t } • If X is non-terminal, then ξϵ First(X) • If X →ξ • Or if X → A1,…An and ξϵ First(Ai) for 1 ≤ i ≤ ni.e. if A1,…An can disappear by producing ξ • First (α) is a subset of First(X) if X → A1,…Anα and ξϵ First(Ai) for 1 ≤ i ≤ n (i.e. A1,…An can all disappear)

  3. Follow Sets • Recall that we construct the follow sets using this algorithm • $ ϵ Follow(S), where S is the start symbol • For each production A → α X β First(β) – { ξ } is a subset of Follow(X) (notice that we exclude ξ , because ξ is never in a follow set) 3. For each production A → α X β if ξ ϵ First(β) (i.e., β can completely disappear) then whatever is in Follow(A) is also in Follow(X) i.e., Follow(A) is a subset of Follow(X)

  4. Exercise • Consider the following grammar over the alphabet ∑ = {u; v; w; x; y; z}: S -> UVW U -> u | Wv | ξ V -> w | xU | ξ W -> y | z • Give the first sets of the non-terminals and the follow sets of the terminals and non-terminals.

  5. Solution

  6. Give the parsing table for this grammar. • Recall that the LL parsing table is constructed as follows • For each production A→ α in G do • For each terminal t ϵ First(α) do • T[A,t]= αbecause obviously would is useful here • If ξϵ First(α), for each t ϵ Follow(A) do • T[A,t]= αbecause α can completely disappear and consequently A disappears. • If ξϵ First(α) and $ ϵ Follow(A) do • T[A,$]= αThis is useful when we ran out of input because the only hope would be is to get rid of whatever is on the stack.

  7. Solution

  8. Soltion • Is this grammar LL(1)? Explain.

More Related