Top-down parsing Module 06.3 COP4020 – Programming Language Concepts 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.
-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.
Syntax and Semantics Structure of programming languages.
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.
Top-Down Parsing CS 671 January 29, CS 671 – Spring Where Are We? Source code: if (b==0) a = “Hi”; Token Stream: if (b == 0) a = “Hi”; Abstract.
Top-down Parsing. 2 Parsing Techniques Top-down parsers (LL(1), recursive descent) Start at the root of the parse tree and grow toward leaves Pick a production.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Top-Down Parsing.
Parsing methods: –Top-down parsing –Bottom-up parsing –Universal.
Syntax and Semantics Structure of programming languages.
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
Fixing non-ll(1) grammars
Compiler Construction
Top-down parsing cannot be performed on left recursive grammars.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Compiler design Bottom-up parsing: Canonical LR and LALR
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.
Parsing Techniques.
Subject Name:COMPILER DESIGN Subject Code:10CS63
Top-Down Parsing CS 671 January 29, 2008.
Recursive Descent Parsing
Bottom-up AST, original grammar
Top-down derivation tree generation
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
Bottom-up derivation tree, original grammar
Bottom-up derivation tree, original grammar
TaBle-driven LL(1) Parsing
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.
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.
Compiler design Bottom-up parsing: Canonical LR and LALR
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

top-down parsing Module 06.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

The Game of Syntactic Dominoes Top-Down Parsing Topics The Game of Syntactic Dominoes Top-Down Parsing

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