1 / 9

LL(1) grammars

LL(1) grammars. Module 07.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez. Define LL(1) Grammar Examples. Select sets. Parse Tables. “Model” PL grammar: Not LL(1). Problems: Left recursion Common prefices. Topics. Definition: A CFG G is LL(1)

lgorman
Télécharger la présentation

LL(1) grammars

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. LL(1) grammars Module 07.1COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

  2. Define LL(1) Grammar Examples. Select sets. Parse Tables. “Model” PL grammar: Not LL(1). Problems: Left recursion Common prefices. Topics

  3. Definition: A CFG G is LL(1) (Left-to-right, Left-most, 1-symbol lookahead) iff for all A∊ , and for all A→, A→,   , Select (A → ) ∩ Select (A → ) =  Select(A → ) = First() ∪ Follow(A) if  ⇒* ℇ First () = {t /  =>* tβ, for some β} Follow (A) = {t / S =>* γAtβ, for some γ, β} Yikes: We’ll treat First, Follow informally (Translators course) LL(1) grammars

  4. S → A {b,} A → bAd {b} → { d,} LL(1) grammars Example: Disjoint ! Grammar is LL(1) PT (not OPF): At most ONE entry in each table slot.

  5. S → A {b} A → bAd {b} → b {b} LL(1) grammars Example: { bn+1dn / n ≥ 0 } Not Disjoint ! Grammar is not LL(1) PT: More than one entry in at least one table slot.

  6. S →begin SL end {begin} T → P*T {(, id} → id := E; {id} → P {(, id} SL → SL S {begin,id} P → (E) {(} →S {begin,id} → id {id} E → E+T {(, id} → T {(, id} Select sets not disjoint LL(1) grammars Not LL(1)

  7. Left recursion always produces a non-LL(1) grammar, e.g. SL → SL S →S Common prefices always produce a non-LL(1) grammar, e.g T → P*T → P Non-LL(1) grammars

  8. S →begin SL end {begin} → id := E; {id} SL → SL S {begin,id} →S {begin,id} E → E+T {(, id} → T {(, id} T → P*T {(, id} → P {(, id} P → (E) {(} → id {id} Model grammar Problems: • SL is left recursive. • E is left recursive. • T → P * T have common → P prefices. Showing a grammar is not LL(1): easy. PL grammars: “mostly” LL(1). This is our “model” PL sample grammar. We’ll use it throughout.

  9. summary • Defined LL(1) Grammar • Examples. • Select sets. • Parse Tables. • “Model” PL grammar: • Not LL(1) • Problems w/grammar.

More Related