Abstract Parsing for Two-staged Language. Soonho Kong May 1, 2009
|
|
- Osborne Butler
- 5 years ago
- Views:
Transcription
1 Astract arsing for Two-staged Language May 1, 009
2 Contents Motivation Language - Syntax & Semantics LR arsing Concrete arsing Astraction Instantiation / 5
3 Motivation rogram generates another program. How can we make sure that the generated program is syntactically correct? 3 / 5
4 Language: Syntax We design a small & simple language to focus on the property we want to verify e Exp :: x let xe 1 e or e 1 e re xe 1 e e 3 `f f F rag :: x let or re f 1.f,e 4 / 5
5 Language: Example code let x `a let y ` or x y let x `a let y ` `x.y.,y re x `a ` x > `a ` > `x y > `a ` re x `a `a.,x re x `a `,x.,x > `a `a a `a a a `a a a a... > `a `a a `a a a a `a a a a a a a a... 5 / 5
6 Language: Collecting Semantics σ Env : ar Code 0 : Exp Env Code 1 : F rag Env Code 0 x Σ {σ(x) σ Σ} 0 (let xe 1 e )Σ 0 e {σ[x c] σ Σ} c 0 e 1 Σ 0 (or e 1 e )Σ 0 e 1 Σ 0 e Σ 0 (re xe 1 e e 3 )Σ 0 e 3 {σ[x c] c fix λc. 0 e 1 {σ} 0 e {σ[x c ] c C}} σ Σ 0 (`f)σ 1 fσ 1 (f 1.f )Σ {xy x 1 f 1 Σ,y 1 f Σ} 1 (,e)σ 0 eσ 1 or Σ { or } 1 let Σ { let } 1 re Σ { re } 1 xσ { x } 6 / 5
7 Language: Astract Collecting Semantics α Env d Env λσ.λx.{σ(x) σ Σ} σ Ênv : ar Code 0 : Exp Ênv Code 1 : F rag Ênv Code 0 x σ σ(x) 0 (or e 1 e ) σ 0 e 1 σ 0 e σ 0 (let xe 1 e ) σ 0 e ( σ[x 0 e 1 σ]) 0 (re xe 1 e e 3 ) σ 0 e 3 ( σ[x fix λk. 0 e 1 σ 0 e ( σ[x k])]) 0 (`f) σ 1 f σ 1 (f 1.f ) σ {xy x 1 f 1 σ y 1 f σ} 1 (,e) σ 0 e σ 1 or σ { or } 1 let σ { let } 1 re σ { re } 1 x σ { x } 7 / 5
8 LR arsing arsing determines whether the string conforms to the grammar or not Grammar String arser O/X 8 / 5
9 LR arsing Scan Left-to-right, derive Rightmost derivation tree. Uses parsing stack and parse_action function Token parse_action parse action : T oken 9 / 5
10 LR arsing Algorithm 1 parse action algorithm 1: procedure parse action(p, a) : t the state on top of stack p 3: if ACT ION[t, a] shift s then 4: push s onto the stack p 5: return p 6: else if ACT ION[t, a] reduce A β then 7: pop β symol off the stack p 8: t the state on top of stack p 9: push GOT O[t, A] onto the stack p 10: return parse action(p, a) 11: end if 1: end procedure Shift Reduce t s s GOTO[t,A] 10 / 5
11 LR arsing arsing is composition of parse_action. Code parse Token Token Token parse_action parse_action parse_action parse : Code 11 / 5
12 Astract arsing: Idea Instead of executing the program and parsing the result, 0 eσ {c 1,c,..., c n } parse(c i )O/X Execute the program on astract semantics. 0 e Σ {O, X} 1 / 5
13 Concrete arsing: alue What should e the one corresponding with Code in parsing domain? It is easy to think that it is (parse c p init ): Code c s 0 p init parse 13 / 5
14 Concrete arsing: alue rolem: Code Concatenation : Easy c1 + c c1 c arse Stack Concatenation : Hard +? 14 / 5
15 Concrete arsing: alue Solution Let it e the function (parse c) : Code c parse 15 / 5
16 Concrete arsing: alue Then the concatenation is handled as function composition c1 c + 16 / 5
17 Astraction Concrete arsing α Code λc.{λp.parse(p, c) c C} Semantics { σ Env : ar 0 : Exp Env 1 : F rag Env 0 xσ σ (x) 0 (or e 1 e )σ 0 e 1 σ 0 e σ 0 (let xe 1 e )σ 0 e (σ [x 0 e 1 σ ]) 0 (re xe 1 e e 3 )σ 0 e 3 (σ [x fix λk. 0 e 1 σ 0 e (σ [x k])]) 0 (`f)σ 1 fσ 1 (f 1.f )σ {p p 1 p 1 1 f 1 σ p 1 f σ } 1 (,e)σ 0 eσ 1 a σ {λp.parse action a p} 17 / 5
18 Astraction First, we astract to y, Semantics is α ( ) λf λ.{f(p) f F p } { ( ) σ Env : ar ( ) 0 : Exp Env ( ) 1 : F rag Env ( ) 0 xσ σ (x) 0 (or e 1 e )σ 0 e 1 σ 0 e σ 0 (let xe 1 e )σ 0 e (σ [x 0 e 1 σ ]) 0 (re xe 1 e e 3 )σ 0 e 3 (σ [x fix λk. 0 e 1 σ 0 e (σ [x k])]) 0 (`f)σ 1 fσ 1 (f 1.f )σ 1 f σ 1 f 1 σ 1 (,e)σ 0 eσ 1 a σ λ.{parse action a p p } 18 / 5
19 Some astract domainsarsing are naturally derived from. Theorem 1. Astract Framework 4. Framework Theorem 1. Astract arsing Framework Let : : May 1, 009 ROAS Let : 1. Astract arsing Framework Theorem Env : ar Let : Astraction,, ) e CO. 1. ( ",. and e", galois via α and γ. (,, ) e CO. connected 4. 1.Framework Galois connections etween derived domains and derived astract domains are 1. Some (,, ", ) e CO. astract domains are naturally derived from. Some astract domains are naturally derived from. We can astract to and γframework Theorem 1. from Astract. derived α arsing Let : Some astractdomains are naturally derived from. : : if satisfies the following conditions. α (F (γ )) λf.λ.α : ar ar )) γ λfenv.λ.γ (: F (α Env Env : ar 1.1. (,, ", ) e is CO. CO αenv Env λσ.λx.α (σ(x)) Some astract domains are naturally derived from. and e galois connected via α. and (... and galois connected via α and γ. and galois connected via α and γ σ σ.γ. and eeare connected via γgalois λ.λx.γ (x)) Env Env derived : domains and domains Galois connections etween derived derived astract doma Galois connections etween and derived ast Galois connections etween derived domains and derived as is a sound astraction of parse derived of action. Fo action : T oken e a sound astraction parse Env : ar. from α and γ. derived from α and γ derived from α. and γ.α a T oken. action(p, a) (γ p }) ({parse α is, λf.λ.α (F )) parse action : T oken. That. and e galois connected via α and γ. α (F (γ(γ λf.λ.α α (F λf.λ.α parse action (α ( ), a) Galois domains and derived astract domains.λ.γ λ F (F (α )) a Tconnections oken. etween. γderived.λ.γ (F(α γ λ F defined. from α and γof 4. derived astract counterpart, as elow. e a γ λ F.λ.γ ( F (α parse α ({parse action p p }) # action a α ( ) αenva Env λσ.λx.α (σ(x)) α λσ.λx.α (σ(x)) Env )) Env α (F (γ λf.λ.α αenv λσ.λx.α (σ(x) Env γenv λ σ.λx.γ ( σ (x)) Env σ Env γ λ σ.λx.γ ( σ (x)).λ.γ (F(α Env )) γenv λ F γ λ σ.λx.γ ( σ (x) Env Env : gm Env T Env oken eλσ.λx.α a sound astraction of parse acti 3. parse action : αenv (σ(x)) Tell 1 May, 009 Show & ROAS Weekly 19 / 5
20 We define 0 and 1. elow σ Env Astraction 0 : Exp Env ( ) 1 : F rag Env ( ) 0 xσ σ (x) 0 (or e 1 e )σ 0 e 1 σ 0 e σ 0 (let xe 1 e )σ 0 e (σ [x 0 e 1 σ ]) 0 (re xe 1 e e 3 )σ 0 e 3 (σ [x fix λk. 0 e 1 σ 0 e (σ [x k])]) 0 `fσ 1 fσ 1 (f 1 f )σ 1 f σ 1 f 1 σ 1 (,e)σ 0 eσ 1 a σ λ.parse action a Then is a sound approximation of. 0 elow e Exp. σ Env. α ( ) ( )( 0 e σ ) 0 e α Env Env (σ ) / 5
21 Instantiation of : Astract arsing Stack with k-cutting IEA : limit the length of parsing stack with k s1 s s3 s4 3-cutting s1 s _ : { p p } α id γ λ. ( ) d (if d then {d} else ) 1 / 5
22 Instantiation of : Astract arsing Stack with k-cutting Algorithm parse action algorithm 1: procedure parse action( p, a) : if p then 3: return p 4: end if 5: t the state on top of stack p 6: if ACT ION[t, a] shift s then 7: push s onto the stack p 8: return p 9: else if ACT ION[t, a] reduce A β then 10: pop β symol off the stack p 11: t the state on top of stack p 1: if t then 13: return p 14: end if 15: push GOT O[t, A] onto the stack p 16: return parse action(a, p) 17: end if 18: end procedure s1 s s3 pop _ / 5
23 Instantiation of : Astract arsing Stack with k-cutting We only perform k-cutting at loop head y defining widening operator A. A B : A B {cut k ( p) p A B} Algorithm 3 cut k algorithm 1: procedure cut k ( p s 1... s n ) : if n k then 3: return p 4: else 5: return s 1... s k : end if 7: end procedure s1 s s1 s s3 s4 3-cutting 3-cutting s1 s s1 s _ 3 / 5
24 Reference Kyung-Goo oh, Hyunha Kim and avid Schmidt. Astract parsing: static analysis of dynamically generated string output using LR-parsing technology. SAS 009: The 16th International Static Analysis Symposium, LA, August 7-9, 009. (to appear) 4 / 5
25 Thank you 5 / 5
Abstract Parsing for Two-staged Language. ROPAS Weekly Show&Tell Soonho Kong 9 February 2009
Abstract Parsing for Two-staged Language ROPAS Weekly Show&Tell Soonho Kong 9 February 2009 Motivation & Goal Motivation In multi-staged programming, program generates another program. Goal Check syntax
More informationProf. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan
Language Processing Systems Prof. Mohamed Hamada Software Engineering La. The University of izu Japan Syntax nalysis (Parsing) 1. Uses Regular Expressions to define tokens 2. Uses Finite utomata to recognize
More informationCMSC 330: Organization of Programming Languages. Pushdown Automata Parsing
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing Chomsky Hierarchy Categorization of various languages and grammars Each is strictly more restrictive than the previous First described
More informationBottom-Up Parsing. Ÿ rm E + F *idÿ rm E +id*idÿ rm T +id*id. Ÿ rm F +id*id Ÿ rm id + id * id
Bottom-Up Parsing Attempts to traverse a parse tree bottom up (post-order traversal) Reduces a sequence of tokens to the start symbol At each reduction step, the RHS of a production is replaced with LHS
More informationSyntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van ngelen, Flora State University, 2007 Position of a Parser in the Compiler Model 2 Source Program Lexical Analyzer Lexical
More informationCS 406: Bottom-Up Parsing
CS 406: Bottom-Up Parsing Stefan D. Bruda Winter 2016 BOTTOM-UP PUSH-DOWN AUTOMATA A different way to construct a push-down automaton equivalent to a given grammar = shift-reduce parser: Given G = (N,
More informationSyntax Analysis Part I
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer
More informationSyntax Analysis Part I
1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer
More informationLecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS Berkley University 1
Lecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS 164 -- Berkley University 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient
More informationAbstract parsing: static analysis of dynamically generated string output using LR-parsing technology
Abstract parsing: static analysis of dynamically generated string output using LR-parsing technology Kyung-Goo Doh 1, Hyunha Kim 1, David A. Schmidt 2 1. Hanyang University, Ansan, South Korea 2. Kansas
More informationCA Compiler Construction
CA4003 - Compiler Construction Bottom Up Parsing David Sinclair Bottom Up Parsing LL(1) parsers have enjoyed a bit of a revival thanks to JavaCC. LL(k) parsers must predict which production rule to use
More informationTop-Down Parsing and Intro to Bottom-Up Parsing
Predictive Parsers op-down Parsing and Intro to Bottom-Up Parsing Lecture 7 Like recursive-descent but parser can predict which production to use By looking at the next few tokens No backtracking Predictive
More informationCompiling Techniques
Lecture 6: 9 October 2015 Announcement New tutorial session: Friday 2pm check ct course webpage to find your allocated group Table of contents 1 2 Ambiguity s Bottom-Up Parser A bottom-up parser builds
More informationShift-Reduce parser E + (E + (E) E [a-z] In each stage, we shift a symbol from the input to the stack, or reduce according to one of the rules.
Bottom-up Parsing Bottom-up Parsing Until now we started with the starting nonterminal S and tried to derive the input from it. In a way, this isn t the natural thing to do. It s much more logical to start
More informationTheory of Computation (IV) Yijia Chen Fudan University
Theory of Computation (IV) Yijia Chen Fudan University Review language regular context-free machine DFA/ NFA PDA syntax regular expression context-free grammar Pushdown automata Definition A pushdown automaton
More informationn Top-down parsing vs. bottom-up parsing n Top-down parsing n Introduction n A top-down depth-first parser (with backtracking)
Announcements n Quiz 1 n Hold on to paper, bring over at the end n HW1 due today n HW2 will be posted tonight n Due Tue, Sep 18 at 2pm in Submitty! n Team assignment. Form teams in Submitty! n Top-down
More informationLecture Notes on Inductive Definitions
Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 August 28, 2003 These supplementary notes review the notion of an inductive definition and give
More informationIntroduction to Bottom-Up Parsing
Outline Introduction to Bottom-Up Parsing Review LL parsing Shift-reduce parsing he LR parsing algorithm Constructing LR parsing tables 2 op-down Parsing: Review op-down parsing expands a parse tree from
More information1. For the following sub-problems, consider the following context-free grammar: S AA$ (1) A xa (2) A B (3) B yb (4)
ECE 468 & 573 Problem Set 2: Contet-free Grammars, Parsers 1. For the following sub-problems, consider the following contet-free grammar: S $ (1) (2) (3) (4) λ (5) (a) What are the terminals and non-terminals
More informationSyntax Analysis - Part 1. Syntax Analysis
Syntax Analysis Outline Context-Free Grammars (CFGs) Parsing Top-Down Recursive Descent Table-Driven Bottom-Up LR Parsing Algorithm How to Build LR Tables Parser Generators Grammar Issues for Programming
More informationA Linear Encoding of Pushdown Control-Flow Analysis
A Linear Encoding of Pushdown Control-Flow Analysis Steven Lyde Thomas Gilray Matthew Might University of Utah {lyde,tgilray,might}@cs.utah.edu Abstract We describe a linear-algebraic encoding for pushdown
More informationComputational Models - Lecture 4
Computational Models - Lecture 4 Regular languages: The Myhill-Nerode Theorem Context-free Grammars Chomsky Normal Form Pumping Lemma for context free languages Non context-free languages: Examples Push
More informationCMSC 631 Program Analysis and Understanding Fall Abstract Interpretation
Program Analysis and Understanding Fall 2017 Abstract Interpretation Based on lectures by David Schmidt, Alex Aiken, Tom Ball, and Cousot & Cousot What is an Abstraction? A property from some domain Blue
More informationCONTEXT FREE GRAMMAR AND
CONTEXT FREE GRAMMAR AND PARSING STATIC ANALYSIS - PARSING Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntatic structure Semantic Analysis (IC generator) Syntatic/sema ntic
More informationHarvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs
Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton
More informationIntroduction to Kleene Algebras
Introduction to Kleene Algebras Riccardo Pucella Basic Notions Seminar December 1, 2005 Introduction to Kleene Algebras p.1 Idempotent Semirings An idempotent semiring is a structure S = (S, +,, 1, 0)
More informationTheory of Computation
Theory of Computation Lecture #10 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 43 Lecture 10: Overview Linear Bounded Automata Acceptance Problem for LBAs
More informationSyntax Directed Transla1on
Syntax Directed Transla1on Syntax Directed Transla1on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Syntax directed Translation Models for translation from parse trees
More informationParsing Algorithms. CS 4447/CS Stephen Watt University of Western Ontario
Parsing Algorithms CS 4447/CS 9545 -- Stephen Watt University of Western Ontario The Big Picture Develop parsers based on grammars Figure out properties of the grammars Make tables that drive parsing engines
More informationSCHEME FOR INTERNAL ASSESSMENT TEST 3
SCHEME FOR INTERNAL ASSESSMENT TEST 3 Max Marks: 40 Subject& Code: Automata Theory & Computability (15CS54) Sem: V ISE (A & B) Note: Answer any FIVE full questions, choosing one full question from each
More informationTheory of Computation (VI) Yijia Chen Fudan University
Theory of Computation (VI) Yijia Chen Fudan University Review Forced handles Definition A handle h of a valid string v = xhy is a forced handle if h is the unique handle in every valid string xhŷ where
More information2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a
. Solution E T F a E E + T T + T F + T a + T a + F a + a E E + T E + T + T T + T + T F + T + T a + T + T a + F + T a + a + T a + a + F a + a + a E T F ( E) ( T ) ( F) (( E)) (( T )) (( F)) (( a)) . Solution
More informationIntro to Theory of Computation
Intro to Theory of Computation LECTURE 7 Last time: Proving a language is not regular Pushdown automata (PDAs) Today: Context-free grammars (CFG) Equivalence of CFGs and PDAs Sofya Raskhodnikova 1/31/2016
More informationCFLs and Regular Languages. CFLs and Regular Languages. CFLs and Regular Languages. Will show that all Regular Languages are CFLs. Union.
We can show that every RL is also a CFL Since a regular grammar is certainly context free. We can also show by only using Regular Expressions and Context Free Grammars That is what we will do in this half.
More informationCompiler Principles, PS4
Top-Down Parsing Compiler Principles, PS4 Parsing problem definition: The general parsing problem is - given set of rules and input stream (in our case scheme token input stream), how to find the parse
More informationEverything You Always Wanted to Know About Parsing
Everything You Always Wanted to Know About Parsing Part V : LR Parsing University of Padua, Italy ESSLLI, August 2013 Introduction Parsing strategies classified by the time the associated PDA commits to
More informationLogic. proof and truth syntacs and semantics. Peter Antal
Logic proof and truth syntacs and semantics Peter Antal antal@mit.bme.hu 10/9/2015 1 Knowledge-based agents Wumpus world Logic in general Syntacs transformational grammars Semantics Truth, meaning, models
More informationCSC 4181Compiler Construction. Context-Free Grammars Using grammars in parsers. Parsing Process. Context-Free Grammar
CSC 4181Compiler Construction Context-ree Grammars Using grammars in parsers CG 1 Parsing Process Call the scanner to get tokens Build a parse tree from the stream of tokens A parse tree shows the syntactic
More informationContext-Free Grammars and Languages. We have seen that many languages cannot be regular. Thus we need to consider larger classes of langs.
Context-Free Grammars and Languages We have seen that many languages cannot be regular. Thus we need to consider larger classes of langs. Contex-Free Languages (CFL s) played a central role natural languages
More informationHarvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata
Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Salil Vadhan October 4, 2012 Reading: Sipser, 2.2. Another example of a CFG (with proof) L = {x {a, b} : x has the same # of a s and
More informationHandout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0
Massachusetts Institute of Technology 6.863J/9.611J, Natural Language Processing, Spring, 2001 Department of Electrical Engineering and Computer Science Department of Brain and Cognitive Sciences Handout
More informationEXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully
EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write
More informationParsing -3. A View During TD Parsing
Parsing -3 Deterministic table-driven parsing techniques Pictorial view of TD and BU parsing BU (shift-reduce) Parsing Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1) Problems with
More informationChapter 4: Bottom-up Analysis 106 / 338
Syntactic Analysis Chapter 4: Bottom-up Analysis 106 / 338 Bottom-up Analysis Attention: Many grammars are not LL(k)! A reason for that is: Definition Grammar G is called left-recursive, if A + A β for
More informationTHEORY OF COMPILATION
Lecture 04 Syntax analysis: top-down and bottom-up parsing THEORY OF COMPILATION EranYahav 1 You are here Compiler txt Source Lexical Analysis Syntax Analysis Parsing Semantic Analysis Inter. Rep. (IR)
More informationHomework 5: Parallelism and Control Flow : Types and Programming Languages Fall 2015 TA: Evan Cavallo
Homework 5: Parallelism and Control Flow 15-814: Types and Programming Languages Fall 2015 TA: Evan Cavallo (ecavallo@cs.cmu.edu) Out: 11/5/15 Due: 11/17/15, 10:30am 1 Cost Dynamics In this section, we
More informationIntroduction to Bottom-Up Parsing
Introduction to Bottom-Up Parsing Outline Review LL parsing Shift-reduce parsing The LR parsing algorithm Constructing LR parsing tables 2 Top-Down Parsing: Review Top-down parsing expands a parse tree
More informationContext-Free and Noncontext-Free Languages
Examples: Context-Free and Noncontext-Free Languages a*b* is regular. A n B n = {a n b n : n 0} is context-free but not regular. A n B n C n = {a n b n c n : n 0} is not context-free The Regular and the
More informationIntroduction to Bottom-Up Parsing
Introduction to Bottom-Up Parsing Outline Review LL parsing Shift-reduce parsing The LR parsing algorithm Constructing LR parsing tables Compiler Design 1 (2011) 2 Top-Down Parsing: Review Top-down parsing
More informationCompiling Techniques
Lecture 7: Abstract Syntax 13 October 2015 Table of contents Syntax Tree 1 Syntax Tree Semantic Actions Examples Abstract Grammar 2 Internal Representation AST Builder 3 Visitor Processing Semantic Actions
More informationBringing machine learning & compositional semantics together: central concepts
Bringing machine learning & compositional semantics together: central concepts https://githubcom/cgpotts/annualreview-complearning Chris Potts Stanford Linguistics CS 244U: Natural language understanding
More informationAdministrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example
Administrivia Test I during class on 10 March. Bottom-Up Parsing Lecture 11-12 From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS14 Lecture 11 1 2/20/08 Prof. Hilfinger CS14 Lecture 11 2 Bottom-Up
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 27, 2007 Outline Recap
More informationLR(1) Parsers Part III Last Parsing Lecture. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved.
LR(1) Parsers Part III Last Parsing Lecture Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. LR(1) Parsers A table-driven LR(1) parser looks like source code Scanner Table-driven Parser
More informationSyntax Analysis Part III
Syntax Analysis Part III Chapter 4: Top-Down Parsing Slides adapted from : Robert van Engelen, Florida State University Eliminating Ambiguity stmt if expr then stmt if expr then stmt else stmt other The
More informationHomework 8. a b b a b a b. two-way, read/write
Homework 8 309 Homework 8 1. Describe a TM that accepts the set {a n n is a power of 2}. Your description should be at the level of the descriptions in Lecture 29 of the TM that accepts {ww w Σ } and the
More informationCS481F01 Prelim 2 Solutions
CS481F01 Prelim 2 Solutions A. Demers 7 Nov 2001 1 (30 pts = 4 pts each part + 2 free points). For this question we use the following notation: x y means x is a prefix of y m k n means m n k For each of
More informationComputer Science 160 Translation of Programming Languages
Computer Science 160 Translation of Programming Languages Instructor: Christopher Kruegel Building a Handle Recognizing Machine: [now, with a look-ahead token, which is LR(1) ] LR(k) items An LR(k) item
More informationThis lecture covers Chapter 6 of HMU: Pushdown Automata
This lecture covers Chapter 6 of HMU: ushdown Automata ushdown Automata (DA) Language accepted by a DA Equivalence of CFs and the languages accepted by DAs Deterministic DAs Additional Reading: Chapter
More informationSyntax Analysis (Part 2)
Syntax Analysis (Part 2) Martin Sulzmann Martin Sulzmann Syntax Analysis (Part 2) 1 / 42 Bottom-Up Parsing Idea Build right-most derivation. Scan input and seek for matching right hand sides. Terminology
More informationIntroduction to Bottom-Up Parsing
Outline Introduction to Bottom-Up Parsing Review LL parsing Shift-reduce parsing he LR parsing algorithm Constructing LR parsing tables Compiler Design 1 (2011) 2 op-down Parsing: Review op-down parsing
More informationComputer Science 160 Translation of Programming Languages
Computer Science 160 Translation of Programming Languages Instructor: Christopher Kruegel Top-Down Parsing Top-down Parsing Algorithm Construct the root node of the parse tree, label it with the start
More informationContext-free Languages and Pushdown Automata
Context-free Languages and Pushdown Automata Finite Automata vs CFLs E.g., {a n b n } CFLs Regular From earlier results: Languages every regular language is a CFL but there are CFLs that are not regular
More informationSyntactic Analysis. Top-Down Parsing
Syntactic Analysis Top-Down Parsing Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make
More informationITI Introduction to Computing II
ITI 1121. Intoduction to Computing II Macel Tucotte School of Electical Engineeing and Compute Science Abstact data type: Stack Stack-based algoithms Vesion of Febuay 2, 2013 Abstact These lectue notes
More informationLanguages. Languages. An Example Grammar. Grammars. Suppose we have an alphabet V. Then we can write:
Languages A language is a set (usually infinite) of strings, also known as sentences Each string consists of a sequence of symbols taken from some alphabet An alphabet, V, is a finite set of symbols, e.g.
More informationDefinition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where
Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the
More informationNote: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).
Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 7: LL(1) Parsing Zheng (Eddy) Zhang Rutgers University February 7, 2018 Class Information Homework 3 will be posted this coming Monday. 2 Review: Top-Down
More informationTHEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET
THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET Regular Languages and FA A language is a set of strings over a finite alphabet Σ. All languages are finite or countably infinite. The set of all languages
More information[4203] Compiler Theory Sheet # 3-Answers
El-Shourouk cademy cad. Year : 2012 / 2013 Higher Institute for Computer & Term : Second Information Technology Year : Fourth Department of Computer Science [4203] Compiler Theory Sheet # 3-nswers 1- Write
More information1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,
1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u, v, x, y, z as per the pumping theorem. 3. Prove that
More informationBottom up parsing. General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing);
Bottom up parsing General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing); 1 Top-down vs Bottom-up Bottom-up more powerful than top-down; Can process
More informationAxiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE
Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE 6341 1 Outline Introduction What are axiomatic semantics? First-order logic & assertions about states Results (triples)
More information5 Context-Free Languages
CA320: COMPUTABILITY AND COMPLEXITY 1 5 Context-Free Languages 5.1 Context-Free Grammars Context-Free Grammars Context-free languages are specified with a context-free grammar (CFG). Formally, a CFG G
More informationCurs 8. LR(k) parsing. S.Motogna - FL&CD
Curs 8 LR(k) parsing Terms Reminder: rhp = right handside of production lhp = left handside of production Prediction see LL(1) Handle = symbols from the head of the working stack that form (in order) a
More informationBottom-Up Syntax Analysis
Bottom-Up Syntax Analysis Mooly Sagiv http://www.cs.tau.ac.il/~msagiv/courses/wcc13.html Textbook:Modern Compiler Design Chapter 2.2.5 (modified) 1 Pushdown automata Deterministic fficient Parsers Report
More information1. For the following sub-problems, consider the following context-free grammar: S AB$ (1) A xax (2) A B (3) B yby (5) B A (6)
ECE 468 & 573 Problem Set 2: Contet-free Grammars, Parsers 1. For the following sub-problems, consider the following contet-free grammar: S AB$ (1) A A (2) A B (3) A λ (4) B B (5) B A (6) B λ (7) (a) What
More informationPushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.
Pushdown Automata We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Next we consider a more powerful computation model, called a
More informationMTH401A Theory of Computation. Lecture 17
MTH401A Theory of Computation Lecture 17 Chomsky Normal Form for CFG s Chomsky Normal Form for CFG s For every context free language, L, the language L {ε} has a grammar in which every production looks
More informationCompiler Principles, PS7
Top-Down Parsing Compiler Principles, PS7 Parsing problem definition: The general parsing problem is - given set of rules and input stream (in our case scheme token input stream), how to find the parse
More informationTheory of Computation Turing Machine and Pushdown Automata
Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type
More informationLecture 11 Sections 4.5, 4.7. Wed, Feb 18, 2009
The s s The s Lecture 11 Sections 4.5, 4.7 Hampden-Sydney College Wed, Feb 18, 2009 Outline The s s 1 s 2 3 4 5 6 The LR(0) Parsing s The s s There are two tables that we will construct. The action table
More informationCS415 Compilers Syntax Analysis Bottom-up Parsing
CS415 Compilers Syntax Analysis Bottom-up Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review: LR(k) Shift-reduce Parsing Shift reduce
More informationCSC 7101: Programming Language Structures 1. Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11.
Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 1 Overview We ll develop proof rules, such as: { I b } S { I } { I } while b do S end { I b } That allow us to verify
More information07 Equational Logic and Algebraic Reasoning
CAS 701 Fall 2004 07 Equational Logic and Algebraic Reasoning Instructor: W. M. Farmer Revised: 17 November 2004 1 What is Equational Logic? Equational logic is first-order logic restricted to languages
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 3.4 Bottom-up parsing Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation 1 Bottom up parsing Goal: Obtain rightmost derivation in reverse w S Reduce
More informationContext free languages
Context free languages Syntatic parsers and parse trees E! E! *! E! (! E! )! E + E! id! id! id! 2 Context Free Grammars The CF grammar production rules have the following structure X α being X N and α
More informationRecitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages
Recitation 2: Binding, Semantics, and Safety 15-312: Foundations of Programming Languages Charles Yuan, Jeanne Luning Prak September 5, 2018 1 Abstract Binding Trees The abstract syntax trees we saw previously
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 7a Syntax Analysis Elias Athanasopoulos
ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 7a Syntax Analysis Elias Athanasopoulos eliasathan@cs.ucy.ac.cy Operator-precedence Parsing A class of shiq-reduce parsers that can be writen by hand
More informationPushdown Automata: Introduction (2)
Pushdown Automata: Introduction Pushdown automaton (PDA) M = (K, Σ, Γ,, s, A) where K is a set of states Σ is an input alphabet Γ is a set of stack symbols s K is the start state A K is a set of accepting
More informationInter-procedural Data Flow Analysis
Flow insensitive analysis Context insensitive analysis Context sensitive analysis Inter-procedural Data Flow Analysis Hanne Riis Nielson and Flemming Nielson email: {riis,nielson}@imm.dtu.dk Informatics
More informationPushdown Automata (Pre Lecture)
Pushdown Automata (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2017 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 1 / 41 Outline Pushdown Automata Pushdown
More informationAutomata and Computability. Solutions to Exercises
Automata and Computability Solutions to Exercises Spring 27 Alexis Maciel Department of Computer Science Clarkson University Copyright c 27 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata
More informationCoalgebra, lecture 10: Algebra and Coalgebra for Regular Expressions
Coalgebra, lecture 10: Algebra and Coalgebra for Regular Expressions Jurriaan Rot November 19, 2018 By now we ve been talking a lot about coalgebras and coinduction, as well as algebras and induction.
More informationMA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation Bottom-up parsing Pumping Theorem for CFLs Recap: Going One Way Lemma: Each context-free language is accepted by some PDA. Proof (by construction): The idea: Let the stack
More informationCS 4120 Lecture 3 Automating lexical analysis 29 August 2011 Lecturer: Andrew Myers. 1 DFAs
CS 42 Lecture 3 Automating lexical analysis 29 August 2 Lecturer: Andrew Myers A lexer generator converts a lexical specification consisting of a list of regular expressions and corresponding actions into
More informationLecture Notes on Inductive Definitions
Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 September 2, 2004 These supplementary notes review the notion of an inductive definition and
More informationIntroduction to Theory of Computing
CSCI 2670, Fall 2012 Introduction to Theory of Computing Department of Computer Science University of Georgia Athens, GA 30602 Instructor: Liming Cai www.cs.uga.edu/ cai 0 Lecture Note 3 Context-Free Languages
More informationAutomata and Computability. Solutions to Exercises
Automata and Computability Solutions to Exercises Fall 28 Alexis Maciel Department of Computer Science Clarkson University Copyright c 28 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata
More information