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

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.
Pushdown Automata Consists of –Pushdown stack (can have terminals and nonterminals) –Finite state automaton control Can do one of three actions (based.
Top-Down Parsing.
CS 330 Programming Languages 09 / 23 / 2008 Instructor: Michael Eckmann.
COP4020 Programming Languages Computing LL(1) parsing table Prof. Xin Yuan.
Syntax and Semantics Structure of programming languages.
Parsing Chapter 4 Parsing2 Outline Top-down v.s. Bottom-up Top-down parsing Recursive-descent parsing LL(1) parsing LL(1) parsing algorithm First.
Top-Down Parsing - recursive descent - predictive parsing
Chapter 5 Top-Down Parsing.
LANGUAGE TRANSLATORS: WEEK 3 LECTURE: Grammar Theory Introduction to Parsing Parser - Generators TUTORIAL: Questions on grammar theory WEEKLY WORK: Read.
-Mandakinee Singh (11CS10026).  What is parsing? ◦ Discovering the derivation of a string: If one exists. ◦ Harder than generating strings.  Two major.
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.
LANGUAGE TRANSLATORS: WEEK 17 scom.hud.ac.uk/scomtlm/cis2380/ See Appel’s book chapter 3 for support reading Last Week: Top-down, Table driven parsers.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Syntax and Semantics Structure of programming languages.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 6, 10/02/2003 Prof. Roy Levow.
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.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Top-Down Parsing.
Parsing methods: –Top-down parsing –Bottom-up parsing –Universal.
Error recovery in predictive parsing An error is detected during the predictive parsing when the terminal on top of the stack does not match the next input.
Context-free grammars
Parsing #1 Leonidas Fegaras.
Parsing Bottom Up CMPS 450 J. Moloney CMPS 450.
Programming Languages Translator
Bottom-up parsing Goal of parser : build a derivation
Context-free grammars, derivation trees, and ambiguity
Lecture #12 Parsing Types.
LL(1) grammars Module 07.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Overview of Compilation The Compiler Front End
Recursive Descent Parsing
Top-down parsing cannot be performed on left recursive 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.
Top-Down Parsing CS 671 January 29, 2008.
Syntax-Directed Definition
Recursive Descent Parsing
Bottom-up AST, original grammar
Top-down derivation tree generation
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
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
Bottom-up derivation tree generation
TaBle-driven LL(1) Parsing
Predictive Parsing Lecture 9 Wed, Feb 9, 2005.
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
Operator precedence and AST’s
Bottom-up derivation tree generation
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Predictive Parsing Program
Operator Precedence and Associativity
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003 Prof. Roy Levow.
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

COP4620 – Programming Language Translators Dr. Manuel E. Bermudez top-down parsing COP4620 – Programming Language Translators Dr. Manuel E. Bermudez

topics The Game of Syntactic Dominoes Top-Down Parsing Strategies for parsing Top-Down Parsing Define OPF

The Game of Syntactic Dominoes The grammar: E → E+T T → P*T P → (E) → T → P → i The playing pieces: An arbitrary supply of each piece (one per grammar rule). The game board: Start domino at the top. Bottom dominoes are the "input."

Syntactic dominoes The Game Board

The Game of Syntactic Dominoes Game rules: Add game pieces to the board. Match the flat parts and the symbols. Lines are infinitely elastic (and cannot cross). Object of the game: Connect start domino with the input dominoes. Leave no unmatched flat parts.

Parsing Strategies Same as for the game of syntactic dominoes. “Top-down” parsing: start at the start symbol, work toward the input string. “Bottom-up” parsing: start at the input string, work towards the goal symbol. In either strategy, can process the input left-to-right  or right-to-left 

Top-Down Parsing Attempt a left-most derivation, by predicting the re-write that will match the remaining input. Use a string (a stack, really) from which the input can be derived. Start with S on the stack. At every step, two alternatives:  (the stack) begins with a terminal t: match t against input.  begins with a nonterminal A: Consult an OPF (Omniscient Parsing Function) to determine which production for A to use.

Sample top-down parse E → E+T → T T → P*T → P P → (E) → i

Classic Top-Down Parsing Algorithm Push (Stack, S); while not Empty (Stack) do if Top(Stack) ∊  then if Top(Stack) = Head(input) then input := tail(input) Pop(Stack) else error (Stack, input) else P:= OPF (Stack, input) Push (Pop(Stack), RHS(P)) od

top-down parsing: general scheme

Top-Down Parsing Most parsing methods (for PL’s) impose bounds: input lookahead: 1. We define OPF (A,t), where A: top element of the stack, and t: first symbol on the input. Storage requirements: O(n2), where n is the size of the grammar vocabulary (a few hundred).

Sample opf Stack Input OPF S → A A → bAd → S bdd S bbdd  OPF d b S

summary The Game of Syntactic Dominoes Top-Down Parsing Strategies for parsing Top-Down Parsing Define OPF