Bottom-up derivation tree, original grammar

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

A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Lesson 8 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
ANTLR with ASTs. Abstract Syntax Trees ANTLR can be instructed to produce ASTs for the output of the parser ANTLR uses a prefix notation for representing.
Syntax Directed Definitions Synthesized Attributes
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
10/13/2015IT 3271 Tow kinds of predictive parsers: Bottom-Up: The syntax tree is built up from the leaves Example: LR(1) parser Top-Down The syntax tree.
Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 3.
Lexical and Syntax Analysis
Parsing Lecture 5 Fri, Jan 28, Syntax Analysis The syntax of a language is described by a context-free grammar. Each grammar rule has the form A.
COP4020 Programming Languages Parsing Prof. Xin Yuan.
Bottom-Up Parsing David Woolbright. The Parsing Problem Produce a parse tree starting at the leaves The order will be that of a rightmost derivation The.
LL(1) Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 7.
Bottom Up Parsing CS 671 January 31, CS 671 – Spring Where Are We? Finished Top-Down Parsing Starting Bottom-Up Parsing Lexical Analysis.
Announcements/Reading
Context-free grammars
Chapter 4 - Parsing CSCE 343.
Programming Languages Translator
CS510 Compiler Lecture 4.
Lexical and Syntax Analysis
Context-free grammars, derivation trees, and ambiguity
Parsing and Parser Parsing methods: top-down & bottom-up
Unit-3 Bottom-Up-Parsing.
Lecture #12 Parsing Types.
LL(1) grammars Module 07.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Introduction to Parsing (adapted from CS 164 at Berkeley)
Writing a scanner Module 05.5 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Textbook:Modern Compiler Design
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
Table-driven parsing Parsing performed by a finite state machine.
Recursive Descent Parsing
Fixing non-ll(1) grammars
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Simplifications of Context-Free Grammars
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Bottom-Up Syntax Analysis
Top-down derivation tree generation
4 (c) parsing.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Regular grammars Module 04.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Top-Down Parsing CS 671 January 29, 2008.
Syntax-Directed Definition
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
TaBle-driven LL(1) Parsing
Replacing recursion with iteration
Compiler Design 7. Top-Down Table-Driven Parsing
Bottom-up AST, original grammar
Bottom-up derivation tree generation
TaBle-driven LL(1) Parsing
Programming Language Syntax 5
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Fixing non-ll(1) grammars
Building AST's for RPAL Programs
Regular Expression to NFA
Replacing recursion with iteration
Programming Language Principles
Recursion and Rpal’s synTax
Operator precedence and AST’s
Bottom-up derivation tree generation
Compiler Construction
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Paradigms and paradigm shifts
Operator Precedence and Associativity
Programming Language Principles
Programming Language Concepts
Presentation transcript:

Bottom-up derivation tree, original grammar Module 09.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

Topics Build Derivation Tree, for the original grammar, bottom-up. Will restore (finally!) left associativity of ``, `+` operators.

Tree generation Red: now Possibilities: Derivation tree, or Abstract Syntax Tree. Top-down, or bottom-up. For original, or modified grammar ! Leading up to: AST, bottom-up, for the original grammar (“the one”).

BU DT, original grammar S → begin SL end → id := E ; SL → SL S → S proc S; case Next_Token of T_begin : Read(T_begin); S(); Write (SL → S); while Next_Token ∊ {T_begin,T_id} do Write (SL → SL S); Read(T_end); Write (S → begin SL end); T_id : Read(T_id); Read (T_:=); E(); Read (T_;); Write (S → id :=E ;); otherwise Error; end; Left associativity of ‘’ restored !

BU DT, original grammar E → E+T → T T → P*T proc E; T(); Write (E → T); while Next_Token = T_+ do Read (T_+); T(); Write (E → E+T); od; end; proc T; P(); if Next_Token = T_* then Read (T_*); T(); Write (T → P*T); else Write (T → P); Left associativity of ‘+’ restored !

BU DT, original grammar We combined: Top-down parsing LL(1) grammar Pre-order process Bottom-up tree construction Original grammar Post-order process proc P; case Next Token of T_(: Read(T_(); E(); Read(T_)); Write (P → (E)); T_id: Read(T_id); Write (P → id); otherwise Error; end;

Parser output P → id T → P E → T E → E+T P → (E) T → P*T E → T Input String: begin id := (id + id) * id; end Output: P → id T → P E → T E → E+T P → (E) T → P*T E → T S → id:=E; SL→ S S → begin SL end

summary Built Derivation Tree, for the original grammar, bottom-up. Have restored (finally!) left associativity of ``, `+` operators. ONE MORE THING TO DO: BUILD the AST !