Syntactic Directed Translation

Size: px
Start display at page:

Download "Syntactic Directed Translation"

Transcription

1 Sntactic Directed Translation What is Sntax-Directed Translation? Translation Process guided b Context-Free Grammars Attach Attributes to Grammar Smbols Attribute Grammars & Sntax-Directed Definitions Values and Semantic Rules Associated with Productions Attributive Grammar Two Flavors: Sntax-Directed Definitions (order is implicit; more abstract) Translation Schemes (explicit order; more concrete) Wh Use This? Ver Powerful Mechanism Used to Build Parse Tree Copright 2, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the Universit of Southern California have explicit permission to make copies of these materials for their personal use. Perform Semantic Analsis such as Tpe Checking Generate Code 2 Attribute Grammars s What is an Attribute Grammar? A Context-Free Grammar Augmented with a Set of Rules Each Smbol in the derivation has a set of values, or Attributes The Rules specif How to Compute a value for each Attribute Grammar!! +!! This grammar describes signed binar numbers We would like to augment it with rules that compute the decimal value of each valid input string For For 3 4 Attribute Grammars Back to the s Add rules to compute the decimal value of a signed binar number Productions Attribution Rules!.pos " If.neg then.val ".val Smbol Attributes else.val ".val val! +.neg " false neg.neg " true pos, val!.pos ".pos +.pos ".pos.val ".val +.val pos, val.pos ".pos.val ".val!.val ".val " 2.pos For neg true.val.val.pos.val.val.pos.val 2.pos Possible data-flow model for Evaluation Independent Attributes First One possible evaluation order:.pos 2.neg 3.pos 4.val 5.val 6.val Other orders are possible Others in Order as Input Values become Available 5 6

2 Back to the s Rules + parse tree impl an attribute dependence graph Back to the s For neg true.val.val.pos.val.val.pos.val 2.pos Possible data-flow model for Evaluation Independent Attributes First One possible evaluation order:.pos 2.neg 3.pos 4.val 5.val 6.val Other orders are possible Others in Order as Input Values become Available Evaluation order must be consistent with the attribute dependence graph 5 neg: true For This is the complete attribute dependence graph for. It shows the flow of all attribute values in the example. Some flow downward Inherited Attributes Some flow upward Snthesized Attributes A rule ma use attributes in the parent, children, or siblings of a node 7 8 Using Attribute Grammars Using Attribute Grammars Attribute Grammars Can Specif Context-Sensitive Actions Take Values from Sntax Perform Computations with Values Insert Tests, Logic, Attribute Grammars Can Specif Context-Sensitive Actions Take Values from Sntax Perform Computations with Values Insert Tests, Logic, Snthesized Attributes Use values from self, children & from constants S-attributed grammars Evaluate in a single bottom-up pass Good match for LR parsing Inherited Attributes Use values from self, parent, siblings & constants Directl express context Can rewrite to avoid them Thought to be more natural Not easil done at parse time Snthesized Attributes Use values from self, children & from constants Good match for LR parsing Inherited Attributes Use values from self, parent, siblings & constants Not easil done at parse time 9 Attributes, Rules and Evaluation Order Evaluation Methods Attributes: Snthesized: Depend on Values from Children or Itself Inherited: Depend on Values from Parent, Siblings or Itself How to Determine the Evaluation Order of Rules? Construct the Parse Tree with Attributes Build an Attribute Dependence Graph Topological Sort It and Evaluate the Rules Dnamic, dependence-based methods Build the Parse Tree Build the Dependence Graph Topological Sort the Dependence Graph Evaluate Attributes in Topological Order Rule-based methods Analze Rules at Compiler-Generation Time Determine a Fixed (static) Ordering Evaluate Nodes in that Order (treewalk) Oblivious Methods Ignore Rules & Parse Tree Pick a Convenient Order (at design time) & Use It (passes, dataflow) 2 2

3 neg: For For 3 4 Inherited Attributes Snthesized Attributes neg: neg: true 4 For For Snthesized Attributes 5 If we show the computation... neg: true 5 neg: true & then peel awa the parse tree For For 7 8 3

4 neg: true For All that is left is the attribute dependence graph. The dependence graph must be acclic This succinctl represents the flow of values in the problem instance. The dnamic methods sort this graph to find independent values, then work along graph edges. The rule-based methods tr to discover good orders b analzing the rules. The oblivious methods ignore the structure of this graph. Circularit We can onl evaluate Acclic Instances We can prove that some grammars can onl generate instances with acclic dependence graphs Largest such class is strongl non-circular grammars (SNC ) SNC grammars can be tested in polnomial time Failing the SNC test is not conclusive Man evaluation methods discover circularit dnamicall Bad propert for a compiler to have SNC grammars were first defined b Kenned & Warren 9 2 A Circular Attribute Grammar Productions Attribution Rules!.a "!.a ".a +.b ".b.c ".b +.val.b ".a +.c +.val!.val ".val " 2.pos For.a.a +.b.b.c.b +.val.a.b.a +.c +.val.val.val 2.pos 2 22.a.a.a +.b.b.c.b +.val.b.a +.c +.val.a.a.a +.b.b.c.b +.val.b.a +.c +.val.val.val 2.pos.val.val 2.pos For For

5 .a.a +.b.b.c.b +.val.a.b.a +.c +.val.a.a +.b.b.c.b +.val.a.b.a +.c +.val.val.val 2.pos.val.val 2.pos For For Here is the circularit An : Estimating Ccle Counts For.a.a +.b.b.c.b +.val.a.b.a +.c +.val.val.val 2.pos Grammar for a Basic Block Block! Block "! Ident = Expr ; Expr! Expr + Term " Expr Term " Term Term! Term * Factor " Term / Factor " Factor Factor! ( Expr ) " " Identifier Assumptions: Each operation has a COST Add them, bottom up Assume a load per value Assume no reuse via registers Simple problem for an Attributive Grammar Here is the circularit An (continued)! Block Block Block.cost " Block.cost +.cost # Block.cost ".cost! Ident = Expr ;.cost " COST(store) + Expr.cost Expr! Expr + Term Expr.cost " Expr.cost + COST(add) + Term.cost # Expr Term Expr.cost " Expr.cost + COST(add) + Term.cost # Term Expr.cost " Term.cost Term! Term * Factor Term.cost " Term.cost + COST(mult ) + Factor.cost # Term / Factor Term.cost " Term.cost + COST(div) + Factor.cost # Factor Term.cost " Factor.cost Factor! ( Expr ) Factor.cost " Expr.cost # Factor.cost " COST(loadI) # Identifier Factor.cost " COST(load) These are all snthesized attributes! Values flow from RHS to LHS in prod ns x = + z = + z = x / 2 cost(loadi) = cost(load) = 2 cost(store) = 2 cost(add) = 3 cost(div) = 9 An (continued) Block Block Id = Expr Id = Expr Id = Expr z Expr / Term x Expr + Term Expr + Term Term Term Factor Term Factor Factor Factor num Factor Id Factor num Id 2 Id z Id x

6 An (continued) An (continued) Properties of the Grammar All Attributes are Snthesized S-Attributed Grammar Rules can be Evaluated Bottom-up in a Single Pass Good fit to bottom-up, shift/reduce parser Easil Understood Solution Seems to fit the Problem Well x = + z = + z = x / 2 cost(loadi) = cost(load) = 2 cost(store) = 2 cost(add) = 3 cost(div) = 9 Block 3 Block Id = Expr 2 Id = Expr Id = Expr 7 6 z Expr / Term 2 x Expr + Term Expr + Term Term Factor 2 Term Factor Term Factor Factor num 2 Factor Id Factor num 2 2 Id 2 Id z Id x 3 32 An Interesting - Tracking Loads A Better Execution Model Values are loaded onl once per block (not at each use) Need to track which values have been alread loaded Assumes an Infinite Register Set to Hold Variables Adding load tracking Need Sets Before and After for each production Must be initialized, updated, and passed around the tree Factor! ( Expr ) Factor.cost " Expr.cost ; Expr.Before " Factor.Before ; Factor.After " Expr.After # Factor.cost " COST(loadi) ; # Identifier If (Identifier.name $ Factor.Before) then Factor.cost " COST(load); % Identifier.name else Factor.cost " 33 This looks more complex! 34 An (continued) A Better Execution Model x = + z = + z = x / 2 cost(loadi) = cost(load) = 2 cost(store) = 2 cost(add) = 3 cost(div) = 9 { Block {,z { Block 5 {,z {,z 4 { 9 {,z 6 {x,,z {,z {,z Id = Expr 7 2 Id = Expr Id = Expr 4 {,z {,z {x,,z { {,z {,z z Expr / Term 2 x Expr + Term Expr + Term {,z {x,,z {x,,z 2 2 { Term Factor { { {,z {,z {,z {,z {,z 2 Term { Factor 2 Term Factor {x,,z 2 {,z Factor num { {,z {,z {,z 2 Factor Id Factor num {x,,z 2 Id { {,z 2 {,z Id z Id x 29 {x,,z Load tracking adds complexit But, most of it is in the cop rules Ever production needs rules to cop Before & After A sample production Expr! Expr + Term Expr.cost " Expr.cost + COST(add) + Term.cost ; Expr.Before " Expr.Before ; Term.Before " Expr.After; Expr.After " Term.After These cop rules multipl rapidl Each creates an instance of the set Lots of work, lots of space, lots of rules to write

7 An Even Better Model The Moral of the Stor What about accounting for Finite Register Sets? Before & After must be of Limited Size Adds complexit to Factor Identifier Requires more Complex Initialization Jump from Tracking Loads to Tracking Registers is small Cop rules are alread in place Some local code to perform the Allocation Non-local computation needed lots of supporting rules Complex local computation was relativel eas The Problems Cop rules increase cognitive overhead Cop rules increase space requirements Need copies of attributes Can use pointers, for even more cognitive overhead Result is an attributed tree (somewhat subtle points) Must build the parse tree Either search tree for answers or cop them to the root Addressing the Problem Reworking the (with load tracking) If ou gave this problem to a real programmer Introduce a central repositor for facts Table of names Field in table for loaded/not loaded state Avoids all the cop rules, allocation & storage headaches All inter-assignment attribute flow is through table Clean, efficient implementation Good techniques for implementing the table When its done, information is in the table! Cures most of the problems Unfortunatel, this design violates the functional paradigm Do we care? Block! Block " cost # ;! Ident = Expr ; cost# cost + COST(store); Expr! Expr + Term cost# cost + COST(add); " Expr Term cost# cost + COST(sub); " Term Term! Term * Factor cost# cost + COST(mult); " Term / Factor cost# cost + COST(div); " Factor Factor! ( Expr ) " cost# cost + COST(loadi); " Identifier { i# hash(identifier); if (Table[i].loaded = false ) then { cost # cost + COST(load); Table[i].loaded # true; This looks cleaner & simpler! 39 4 Reworking the (with load tracking Factor! ( Expr ) " cost# cost + COST(loadi); " Identifier { i# hash(identifier); if (Table[i].loaded = false) then { cost # cost + COST(load) ; Table[i].loaded # true;! Expr ) Factor.cost " Expr.cost ; Factor ( Expr.Before " Factor.Before ; Factor.After " Expr.After # Factor.cost " COST(loadi) ; # Identifier If (Identifier.name $ Factor.Before) then Factor.cost " COST(load); % Identifier.name else Factor.cost " Attribute Grammar Summar Augment CFG with Attributes and Rules Inherited and Snthesized Attributes Sntax-Directed Definitions Find Dependence Graph and Evaluation Order Useful for Semantic Analsis

Syntactic Directed Translation

Syntactic Directed Translation Syntactic Directed Translation Attribute Grammars & Syntax-Directed Definitions Copyright 206, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern

More information

Grammars. CS434 Lecture 15 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Grammars. CS434 Lecture 15 Spring 2005 Department of Computer Science University of Alabama Joel Jones Grammars CS434 Lecture 5 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled

More information

Context-sensitive Analysis Part II

Context-sensitive Analysis Part II Context-sensitive Analysis Part II Attribute Grammars Add rules to compute the decimal value of a signed binary number Back to the Examples For Symbol Attributes.neg Number val neg pos, val pos, val Back

More information

Context-sensitive Analysis

Context-sensitive Analysis Context-sensitive Analysis Beyond Syntax There is a level of correctness that is deeper than grammar fie(a,b,c,d) int a, b, c, d; { } What is wrong with this program? (let me count the ways ) fee() { int

More information

There is a level of correctness that is deeper than grammar. There is a level of correctness that is deeper than grammar

There is a level of correctness that is deeper than grammar. There is a level of correctness that is deeper than grammar Beyond Syntax There is a level of correctness that is deeper than grammar fie(a,b,c,d) int a, b, c, d; { } What is wrong with this program? (let me count the ways ) fee() { int f[3],g[0], h, i, j, k; char

More information

Context-sensitive Analysis Part II Chapter 4 (up to Section 4.3)

Context-sensitive Analysis Part II Chapter 4 (up to Section 4.3) Context-sensitive Analysis Part II Chapter 4 (up to Section 4.3) Attribute Grammars Add rules to compute the decimal value of a signed binary number Two kinds of Attributes Synthesized attribute Bottom-Up

More information

CS 406/534 Compiler Construction LR(1) Parsing and CSA

CS 406/534 Compiler Construction LR(1) Parsing and CSA CS 406/534 Compiler Construction LR(1) Parsing and CSA Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy and

More information

Context-sensitive Analysis. Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.

Context-sensitive Analysis. Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Context-sensitive Analysis Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Beyond Syntax There is a level of correctness that is deeper than grammar fie(a,b,c,d) int

More information

Context-sensitive Analysis

Context-sensitive Analysis Context-sensitive Analysis Beyond Syntax There is a level of correctness that is deeper than grammar fie(a,b,c,d) int a, b, c, d; { } fee() { int f[3],g[0], h, i, j, k; char *p; fie(h,i, ab,j, k); k =

More information

Syntax Directed Translation

Syntax Directed Translation Syntax Directed Translation Beyond syntax analysis An identifier named x has been recognized. Is x a scalar, array or function? How big is x? If x is a function, how many and what type of arguments does

More information

Register Allocation 3/16/11. What a Smart Allocator Needs to Do. Global Register Allocation. Global Register Allocation. Outline.

Register Allocation 3/16/11. What a Smart Allocator Needs to Do. Global Register Allocation. Global Register Allocation. Outline. What a Smart Allocator Needs to Do Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Determine ranges for each variable can benefit from using

More information

Syntactic Directed Translation

Syntactic Directed Translation Syntactic Directed Translation Translation Schemes Copyright 2016, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Parsing III (Top-down parsing: recursive descent & LL(1) ) (Bottom-up parsing) CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper,

More information

Syntax-Directed Translation. CS Compiler Design. SDD and SDT scheme. Example: SDD vs SDT scheme infix to postfix trans

Syntax-Directed Translation. CS Compiler Design. SDD and SDT scheme. Example: SDD vs SDT scheme infix to postfix trans Syntax-Directed Translation CS3300 - Compiler Design Syntax Directed Translation V. Krishna Nandivada IIT Madras Attach rules or program fragments to productions in a grammar. Syntax directed definition

More information

Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412

Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412 Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, V Bottom-up Parsing & The Magic of Handles Comp 412 COMP 412 FALL 2018 source code IR Front End Optimizer Back End IR target

More information

g(x) h(x) f (x) = Examples sin x +1 tan x!

g(x) h(x) f (x) = Examples sin x +1 tan x! Lecture 4-5A: An Introduction to Rational Functions A Rational Function f () is epressed as a fraction with a functiong() in the numerator and a function h() in the denominator. f () = g() h() Eamples

More information

CSCI Compiler Design

CSCI Compiler Design University of Southern California CSCI565 Compiler Design Midterm Exam - Fall 26 CSCI 565 - Compiler Design Fall 26 Midterm Exam Solution Problem : Context-Free-Grammars and Parsing Algorithms [4 points]

More information

Search Trees. Chapter 11

Search Trees. Chapter 11 Search Trees Chapter 6 4 8 9 Outline Binar Search Trees AVL Trees Spla Trees Outline Binar Search Trees AVL Trees Spla Trees Binar Search Trees A binar search tree is a proper binar tree storing ke-value

More information

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology Intermediate Algebra Gregg Waterman Oregon Institute of Technolog c 2017 Gregg Waterman This work is licensed under the Creative Commons Attribution 4.0 International license. The essence of the license

More information

Parsing II Top-down parsing. Comp 412

Parsing II Top-down parsing. Comp 412 COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields

Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields Classes Implementing Objects Components fields/instance variables values differ from to usuall mutable methods values shared b all s of a class usuall immutable component visibilit: public/private/protected

More information

Syntax-directed translation. Context-sensitive analysis. What context-sensitive questions might the compiler ask?

Syntax-directed translation. Context-sensitive analysis. What context-sensitive questions might the compiler ask? Syntax-directed translation Context-sensitive analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the

More information

CS415 Compilers Context-Sensitive Analysis Type checking Symbol tables

CS415 Compilers Context-Sensitive Analysis Type checking Symbol tables CS415 Compilers Context-Sensitive Analysis Type checking Symbol tables These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 18 1 Announcements

More information

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture CS 403 Compiler Construction Lecture 8 Snta Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] 1 This Lecture 2 1 Remember: Phases of a Compiler This lecture: Intermediate Code This lecture:

More information

1.3. Equations and Graphs of Polynomial Functions. What is the connection between the factored form of a polynomial function and its graph?

1.3. Equations and Graphs of Polynomial Functions. What is the connection between the factored form of a polynomial function and its graph? 1.3 Equations and Graphs of Polnomial Functions A rollercoaster is designed so that the shape of a section of the ride can be modelled b the function f(x). 4x(x 15)(x 25)(x 45) 2 (x 6) 9, x [, 6], where

More information

Semantic Analysis with Attribute Grammars Part 1

Semantic Analysis with Attribute Grammars Part 1 with Attribute Grammars Part 1 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture Introduction

More information

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Parsing Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

MiniTriangle. G52CMP: Lecture 6 Defining Programming Languages II. This Lecture. A MiniTriangle Program

MiniTriangle. G52CMP: Lecture 6 Defining Programming Languages II. This Lecture. A MiniTriangle Program MiniTriangle G52CMP: Lecture 6 Defining Programming Languages II Henrik Nilsson Universit of Nottingham, UK In part II of the coursework, we are going to use a language called MiniTriangle: Originates

More information

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code

Winter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code Winter 26-27 Compiler Construction T9 IR part 2 + Runtime organization Mool Sagiv and Roman Manevich School of Computer Science Tel-Aviv Universit Announcements What is epected in PA3 documentation (5

More information

Syntactic Analysis. Top-Down Parsing

Syntactic Analysis. Top-Down Parsing Syntactic Analysis Top-Down Parsing Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make

More information

Lexical Analysis. Introduction

Lexical Analysis. Introduction Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies

More information

Transformations of Functions. 1. Shifting, reflecting, and stretching graphs Symmetry of functions and equations

Transformations of Functions. 1. Shifting, reflecting, and stretching graphs Symmetry of functions and equations Chapter Transformations of Functions TOPICS.5.. Shifting, reflecting, and stretching graphs Smmetr of functions and equations TOPIC Horizontal Shifting/ Translation Horizontal Shifting/ Translation Shifting,

More information

Summary: Semantic Analysis

Summary: Semantic Analysis Summary: Semantic Analysis 1 Basic Concepts When SA is performed: Semantic Analysis may be performed: In a two-pass compiler: after syntactic analysis is finished, the semantic analyser if called with

More information

Context-sensitive analysis. Semantic Processing. Alternatives for semantic processing. Context-sensitive analysis

Context-sensitive analysis. Semantic Processing. Alternatives for semantic processing. Context-sensitive analysis Semantic Processing The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure

More information

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University Semantic Analysis CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Role of Semantic Analysis Syntax vs. Semantics: syntax concerns the form of a

More information

Syntax Directed Translation

Syntax Directed Translation Syntax Directed Translation Rupesh Nasre. CS3300 Compiler Design IIT Madras Aug 2015 Character stream Lexical Analyzer Machine-Independent Code Optimizer F r o n t e n d Token stream Syntax Analyzer Syntax

More information

Parsing Part II (Top-down parsing, left-recursion removal)

Parsing Part II (Top-down parsing, left-recursion removal) Parsing Part II (Top-down parsing, left-recursion removal) Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit

More information

Name Class Date. subtract 3 from each side. w 5z z 5 2 w p - 9 = = 15 + k = 10m. 10. n =

Name Class Date. subtract 3 from each side. w 5z z 5 2 w p - 9 = = 15 + k = 10m. 10. n = Reteaching Solving Equations To solve an equation that contains a variable, find all of the values of the variable that make the equation true. Use the equalit properties of real numbers and inverse operations

More information

Compiler Design Concepts. Syntax Analysis

Compiler Design Concepts. Syntax Analysis Compiler Design Concepts Syntax Analysis Introduction First task is to break up the text into meaningful words called tokens. newval=oldval+12 id = id + num Token Stream Lexical Analysis Source Code (High

More information

The Phases of a Compiler. Course Overview. In Chapter 4. Syntax Analysis. Syntax Analysis. Multi Pass Compiler. PART I: overview material

The Phases of a Compiler. Course Overview. In Chapter 4. Syntax Analysis. Syntax Analysis. Multi Pass Compiler. PART I: overview material Course Overview The Phases of a Compiler PART I: overview material Introduction 2 Language processors (tombstone diagrams, bootstrappg) 3 Architecture of a compiler PART II: side a compiler 4 Sntax analsis

More information

Exponential Functions. Christopher Thomas

Exponential Functions. Christopher Thomas Mathematics Learning Centre Eponential Functions Christopher Thomas c 1998 Universit of Sdne Mathematics Learning Centre, Universit of Sdne 1 1 Eponential Functions 1.1 The functions =2 and =2 From our

More information

Slope Fields & Differential Equations

Slope Fields & Differential Equations Slope Fields & Differential Equations Answers 7 8 9 10 11 1 TI-Nspire Investigation Student 45 min Introduction The purpose of this activit is to gain a conceptual understanding of slope fields and differential

More information

ECE 573 Midterm 1 September 29, 2009

ECE 573 Midterm 1 September 29, 2009 ECE 573 Midterm 1 September 29, 2009 Name: Purdue email: Please sign the following: I affirm that the answers given on this test are mine and mine alone. I did not receive help from an person or material

More information

What are the rules of elementary algebra

What are the rules of elementary algebra What are the rules of elementar algebra James Davenport & Chris Sangwin Universities of Bath & Birmingham 7 Jul 2010 Setting A relativel traditional mathematics course, at, sa first-ear undergraduate level.

More information

3.2 Polynomial Functions of Higher Degree

3.2 Polynomial Functions of Higher Degree 71_00.qp 1/7/06 1: PM Page 6 Section. Polnomial Functions of Higher Degree 6. Polnomial Functions of Higher Degree What ou should learn Graphs of Polnomial Functions You should be able to sketch accurate

More information

COMP 181. Prelude. Prelude. Summary of parsing. A Hierarchy of Grammar Classes. More power? Syntax-directed translation. Analysis

COMP 181. Prelude. Prelude. Summary of parsing. A Hierarchy of Grammar Classes. More power? Syntax-directed translation. Analysis Prelude COMP 8 October, 9 What is triskaidekaphobia? Fear of the number s? No aisle in airplanes, no th floor in buildings Fear of Friday the th? Paraskevidedekatriaphobia or friggatriskaidekaphobia Why

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the

More information

Register Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations

Register Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the

More information

MIT Top-Down Parsing. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

MIT Top-Down Parsing. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology MIT 6.035 Top-Down Parsing Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Orientation Language specification Lexical structure regular expressions Syntactic structure

More information

Roberto s Notes on Differential Calculus Chapter 8: Graphical analysis Section 5. Graph sketching

Roberto s Notes on Differential Calculus Chapter 8: Graphical analysis Section 5. Graph sketching Roberto s Notes on Differential Calculus Chapter 8: Graphical analsis Section 5 Graph sketching What ou need to know alread: How to compute and interpret limits How to perform first and second derivative

More information

Semantic Analysis with Attribute Grammars Part 3

Semantic Analysis with Attribute Grammars Part 3 with Attribute Grammars Part 3 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture Introduction

More information

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

EXAM. 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 information

Special Products on Factoring

Special Products on Factoring Special Products on Factoring What Is This Module About? This module is a continuation of the module on polnomials. In the module entitled Studing Polnomials, ou learned what polnomials are as well as

More information

5. Semantic Analysis!

5. Semantic Analysis! 5. Semantic Analysis! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/! http://www.cs.purdue.edu/homes/hosking/!

More information

Syntax Analysis, III Comp 412

Syntax Analysis, III Comp 412 Updated algorithm for removal of indirect left recursion to match EaC3e (3/2018) COMP 412 FALL 2018 Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, III Comp 412 source code

More information

10/18/18. Outline. Semantic Analysis. Two types of semantic rules. Syntax vs. Semantics. Static Semantics. Static Semantics.

10/18/18. Outline. Semantic Analysis. Two types of semantic rules. Syntax vs. Semantics. Static Semantics. Static Semantics. Outline Semantic Analysis In Text: Chapter 3 Static semantics Attribute grammars Dynamic semantics Operational semantics Denotational semantics N. Meng, S. Arthur 2 Syntax vs. Semantics Syntax concerns

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation 1 Syntax-Directed Translation 1. We associate information with the programming language constructs by attaching attributes to grammar symbols. 2. Values of these attributes

More information

Polynomial and Rational Functions

Polynomial and Rational Functions Polnomial and Rational Functions Figure -mm film, once the standard for capturing photographic images, has been made largel obsolete b digital photograph. (credit film : modification of work b Horia Varlan;

More information

Lecture Notes on AVL Trees

Lecture Notes on AVL Trees Lecture Notes on AVL Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 19 March 28, 2013 1 Introduction Binar search trees are an ecellent data structure to implement associative

More information

CMPT 379 Compilers. Parse trees

CMPT 379 Compilers. Parse trees CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 10/25/07 1 Parse trees Given an input program, we convert the text into a parse tree Moving to the backend of the compiler: we will produce intermediate

More information

COP5621 Exam 3 - Spring 2005

COP5621 Exam 3 - Spring 2005 COP5621 Exam 3 - Spring 2005 Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full cred

More information

Implicit differentiation

Implicit differentiation Roberto s Notes on Differential Calculus Chapter 4: Basic differentiation rules Section 5 Implicit differentiation What ou need to know alread: Basic rules of differentiation, including the chain rule.

More information

Semantic analysis. Syntax tree is decorated with typing- and other context dependent

Semantic analysis. Syntax tree is decorated with typing- and other context dependent Semantic analysis Semantic analysis Semantic analysis checks for the correctness of contextual dependences: { nds correspondence between declarations and usage of identiers, { performs type checking/inference,

More information

Syntax Analysis, III Comp 412

Syntax Analysis, III Comp 412 COMP 412 FALL 2017 Syntax Analysis, III Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp

More information

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++ Announcements CSCI 4: Principles of Programming Languages Lecture 19: C++ HW8 pro tip: the HW7 solutions have a complete, correct implementation of the CPS version of bubble sort in SML. All ou need to

More information

9. p(x) = x 3 8x 2 5x p(x) = x 3 + 3x 2 33x p(x) = x x p(x) = x 3 + 5x x p(x) = x 4 50x

9. p(x) = x 3 8x 2 5x p(x) = x 3 + 3x 2 33x p(x) = x x p(x) = x 3 + 5x x p(x) = x 4 50x Section 6.3 Etrema and Models 593 6.3 Eercises In Eercises 1-8, perform each of the following tasks for the given polnomial. i. Without the aid of a calculator, use an algebraic technique to identif the

More information

CSCI Compiler Design

CSCI Compiler Design University of Southern California CSCI565 Compiler Design Midterm Exam - Spring 26 CSCI 565 - Compiler Design Spring 26 Midterm Exam March, 26 at : PM in class (KAP 47) Duration: 2h 3 min. Please label

More information

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8] Code No: R05311201 Set No. 1 1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8] 2. Compute the FIRST and FOLLOW sets of each

More information

Building up a language SICP Variations on a Scheme. Meval. The Core Evaluator. Eval. Apply. 2. syntax procedures. 1.

Building up a language SICP Variations on a Scheme. Meval. The Core Evaluator. Eval. Apply. 2. syntax procedures. 1. 6.001 SICP Variations on a Scheme Scheme Evaluator A Grand Tour Techniques for language design: Interpretation: eval/appl Semantics vs. snta Sntactic transformations Building up a language... 3. 1. eval/appl

More information

Lecture 16 Notes AVL Trees

Lecture 16 Notes AVL Trees Lecture 16 Notes AVL Trees 15-122: Principles of Imperative Computation (Fall 2015) Frank Pfenning 1 Introduction Binar search trees are an ecellent data structure to implement associative arras, maps,

More information

Syntax-Directed Translation. Introduction

Syntax-Directed Translation. Introduction Syntax-Directed Translation Introduction Translation of languages guided by context-free grammars Attach attributes to the grammar symbols Values of the attributes are computed by semantic rules associated

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation ALSU Textbook Chapter 5.1 5.4, 4.8, 4.9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is syntax-directed translation? Definition: The compilation

More information

G53CMP: Lecture 4. Syntactic Analysis: Parser Generators. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 4 p.1/32

G53CMP: Lecture 4. Syntactic Analysis: Parser Generators. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 4 p.1/32 G53CMP: Lecture 4 Syntactic Analysis: Parser Generators Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 4 p.1/32 This Lecture Parser generators ( compiler compilers ) The parser generator Happy

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

More information

intermediate code generator syntax tree token stream intermediate representation parser checker tree

intermediate code generator syntax tree token stream intermediate representation parser checker tree Context-sensitive analysis context-sensitive questions might the compiler What ask? 1. Is x a scalar, anarray, or a function? 2. Is x declared before it is used? 3. Are any names declared but not used?

More information

Syntax-Directed Translation Part II

Syntax-Directed Translation Part II Syntax-Directed Translation Part II Chapter 5 Slides adapted from : Robert van Engelen, Florida State University Alessandro Artale, Free University of Bolzano Syntax-Directed Translation Schemes Syntax-directed

More information

Bottom-up Parser. Jungsik Choi

Bottom-up Parser. Jungsik Choi Formal Languages and Compiler (CSE322) Bottom-up Parser Jungsik Choi chjs@khu.ac.kr * Some slides taken from SKKU SWE3010 (Prof. Hwansoo Han) and TAMU CSCE434-500 (Prof. Lawrence Rauchwerger) Bottom-up

More information

2.8 Distance and Midpoint Formulas; Circles

2.8 Distance and Midpoint Formulas; Circles Section.8 Distance and Midpoint Formulas; Circles 9 Eercises 89 90 are based on the following cartoon. B.C. b permission of Johnn Hart and Creators Sndicate, Inc. 89. Assuming that there is no such thing

More information

Module Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check?

Module Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check? CS412/413 Introduction to Compilers and Translators Andrew Mers Cornell Universit Lecture 19: ADT mechanisms 10 March 00 Module Mechanisms Last time: modules, was to implement ADTs Module collection of

More information

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468 Parsers Xiaokang Qiu Purdue University ECE 468 August 31, 2018 What is a parser A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation What is syntax-directed translation? The compilation process is driven by the syntax. The semantic routines perform interpretation based on the syntax structure. Attaching attributes

More information

Downloaded from Page 1. LR Parsing

Downloaded from  Page 1. LR Parsing Downloaded from http://himadri.cmsdu.org Page 1 LR Parsing We first understand Context Free Grammars. Consider the input string: x+2*y When scanned by a scanner, it produces the following stream of tokens:

More information

Introduction to Parsing. Comp 412

Introduction to Parsing. Comp 412 COMP 412 FALL 2010 Introduction to Parsing Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make

More information

Building a Parser Part III

Building a Parser Part III COMP 506 Rice University Spring 2018 Building a Parser Part III With Practical Application To Lab One source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda

More information

Code Shape II Expressions & Assignment

Code Shape II Expressions & Assignment Code Shape II Expressions & Assignment Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

Computing Inside The Parser Syntax-Directed Translation, II. Comp 412

Computing Inside The Parser Syntax-Directed Translation, II. Comp 412 COMP 412 FALL 2018 Computing Inside The Parser Syntax-Directed Translation, II Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights

More information

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions

More information

COP4020 Programming Languages. Semantics Prof. Robert van Engelen

COP4020 Programming Languages. Semantics Prof. Robert van Engelen COP4020 Programming Languages Semantics Prof. Robert van Engelen Overview Static semantics Dynamic semantics Attribute grammars Abstract syntax trees COP4020 Spring 2011 2 Static Semantics Syntax concerns

More information

Transformations of Functions. Shifting Graphs. Similarly, you can obtain the graph of. g x x 2 2 f x 2. Vertical and Horizontal Shifts

Transformations of Functions. Shifting Graphs. Similarly, you can obtain the graph of. g x x 2 2 f x 2. Vertical and Horizontal Shifts 0_007.qd /7/05 : AM Page 7 7 Chapter Functions and Their Graphs.7 Transormations o Functions What ou should learn Use vertical and horizontal shits to sketch graphs o unctions. Use relections to sketch

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

SLOPE A MEASURE OF STEEPNESS through 7.1.5

SLOPE A MEASURE OF STEEPNESS through 7.1.5 SLOPE A MEASURE OF STEEPNESS 7.1. through 7.1.5 Students have used the equation = m + b throughout this course to graph lines and describe patterns. When the equation is written in -form, the m is the

More information

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End Architecture of Compilers, Interpreters : Organization of Programming Languages ource Analyzer Optimizer Code Generator Context Free Grammars Intermediate Representation Front End Back End Compiler / Interpreter

More information

Introduction to Compiler

Introduction to Compiler Formal Languages and Compiler (CSE322) Introduction to Compiler Jungsik Choi chjs@khu.ac.kr 2018. 3. 8 Traditional Two-pass Compiler Source Front End Back End Compiler Target High level functions Recognize

More information

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars CMSC 330: Organization of Programming Languages Context Free Grammars Where We Are Programming languages Ruby OCaml Implementing programming languages Scanner Uses regular expressions Finite automata Parser

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation 1 Syntax-Directed Translation 2 Syntax-Directed Translation 3 Syntax-Directed Translation In a syntax-directed definition, each production A α is associated with a set of semantic

More information

CSE3322 Programming Languages and Implementation

CSE3322 Programming Languages and Implementation Monash University School of Computer Science & Software Engineering Exam 2005 CSE3322 Programming Languages and Implementation Total Time Allowed: 3 Hours 1. Reading time is of 10 minutes duration. 2.

More information

CSCI Compiler Design

CSCI Compiler Design Syntactic Analysis Automatic Parser Generators: The UNIX YACC Tool Portions of this lecture were adapted from Prof. Pedro Reis Santos s notes for the 2006 Compilers class lectured at IST/UTL in Lisbon,

More information

COP4020 Programming Languages. Semantics Robert van Engelen & Chris Lacher

COP4020 Programming Languages. Semantics Robert van Engelen & Chris Lacher COP4020 Programming Languages Semantics Robert van Engelen & Chris Lacher Overview Static semantics Dynamic semantics Attribute grammars Abstract syntax trees Static Semantics Syntax concerns the form

More information