COP4620 – Programming Language Translators Dr. Manuel E. Bermudez

Slides:



Advertisements
Similar presentations
AST Generation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 9.
Advertisements

Top-Down Parsing.
1 Predictive parsing Recall the main idea of top-down parsing: Start at the root, grow towards leaves Pick a production and try to match input May need.
Top-Down parsing LL(1) parsing. Overview of Top-Down  There are only two actions 1.Replace 2.Match.
Professor Yihjia Tsai Tamkang University
Compiler Construction Sohail Aslam Lecture LL(1) Table Construction For each production A →  1.for each terminal a in FIRST(  ), add A →  to.
COP4020 Programming Languages Computing LL(1) parsing table Prof. Xin Yuan.
Top-Down Parsing - recursive descent - predictive parsing
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 3.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 6, 10/02/2003 Prof. Roy Levow.
COP4020 Programming Languages Parsing Prof. Xin Yuan.
1 Nonrecursive Predictive Parsing  It is possible to build a nonrecursive predictive parser  This is done by maintaining an explicit stack.
Top-Down Parsing.
Parsing methods: –Top-down parsing –Bottom-up parsing –Universal.
LL(1) Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 7.
UMBC  CSEE   1 Chapter 4 Chapter 4 (b) parsing.
COMP 3438 – Part II-Lecture 6 Syntax Analysis III Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
9/30/2014IT 3271 How to construct an LL(1) parsing table ? 1.S  A S b 2.S  C 3.A  a 4.C  c C 5.C  abc$ S1222 A3 C545 LL(1) Parsing Table What is the.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Context-free grammars
Context-free grammars, derivation trees, and ambiguity
LL(1) grammars Module 07.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 5, 09/25/2003 Prof. Roy Levow.
Writing a scanner Module 05.5 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Grammars Module 03.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Recursive Descent Parsing
Fixing non-ll(1) grammars
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Compiler Construction
Parsing with Context Free Grammars
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Top-down derivation tree generation
4 (c) parsing.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Regular grammars Module 04.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Parsing Techniques.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Top-Down Parsing.
CS 540 George Mason University
Recursive Descent Parsing
Bottom-up AST, original grammar
Top-down derivation tree generation
Top-down parsing Module 06.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Bottom-up derivation tree, original grammar
Bottom-up derivation tree, original grammar
TaBle-driven LL(1) Parsing
Replacing recursion with iteration
Compiler Design 7. Top-Down Table-Driven Parsing
Bottom-up AST, original grammar
Chapter 2: A Simple One Pass Compiler
Bottom-up derivation tree generation
Ambiguity, Precedence, Associativity & Top-Down Parsing
TaBle-driven LL(1) Parsing
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Fixing non-ll(1) grammars
First, Follow and Select sets
Regular Expression to NFA
Replacing recursion with iteration
Theory of Computation Lecture #
Programming Language Principles
CFGs: Formal Definition
COP46– Programming Language Translators Dr. Manuel E. Bermudez
Operator precedence and AST’s
Nonrecursive Predictive Parsing
Compiler Construction
Paradigms and paradigm shifts
Operator Precedence and Associativity
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003 Prof. Roy Levow.
Presentation transcript:

COP4620 – Programming Language Translators Dr. Manuel E. Bermudez LL(1) grammars COP4620 – Programming Language Translators Dr. Manuel E. Bermudez

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

LL(1) grammars 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 γ, β} We’ll describe First, Follow, Select sets in the next Lecture)

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

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

LL(1) grammars 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 Not LL(1)

Non-LL(1) grammars 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

Model grammar Problems: → id := E; {id} SL is left recursive. 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} 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.

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