Lecture Notes on Intermediate Representation
|
|
- Bethanie Day
- 5 years ago
- Views:
Transcription
1 Lecture Notes on Intermediate Representation : Compiler Design Frank Pfenning Lecture 10 September 23, Introduction In this lecture we discuss the middle end of the compiler. After the source has been parsed we obtain an abstract syntax tree, on which we carry out various static analyses to see if the program is well-formed. In the L2 language, this consists of checking that every finite control flow path ends in a return statement, that every variable is initialized before its use along every control flow path, and that break and continue statements occur only inside loops. In later languages, type-checking will be an important additional task. After we have constructed and checked the abstract syntax tree, we transform the program through several forms of intermediate representation on the way to abstract symbolic assembly and finally actual x86-64 assembly form. How many intermediate representations and their precise form depends on the context: the complexity and form of the language, to what extent the compiler is engineered to be retargetable to different machine architectures, and what kinds of optimizations are important for the implementation. Some of the most well-understood intermediate forms are intermediate representation trees (IR trees), static single-assignment form (SSA), quads and triples. Quads (that is, three-address instructions) and triples (two-address instructions) are closer to the back end of the compiler and you will probably want to use one of them, maybe both. In this lecture we focus on IR trees.
2 L10.2 Intermediate Representation 2 Abstract Syntax Trees We describe abstract syntax trees in a BNF form (Backus-Naur Form) which was originally designed for describing grammars. An abstract syntax tree is the output of parsing and is formed by removing immaterial information from the parse tree (e.g., tokens that are not important in the tree structure) and transforming into a more canonical form. Here we use BNF to describe the recursive structure of the abstract syntax trees. Expressions e ::= n x e 1 e 2 e 1 e 2 e 1 &&e 2 e 1 e 2 f(e 1,..., e n ) Statements s ::= assign(x, e) if(e, s 1, s 2 ) while(e, s) break continue return(e) nop seq(s 1, s 2 ) We use n for constants, x for variables, for effect-free operators, for potentially effectful operators (such as division, which could raise an exception), && and for logical and and or, respectively. The latter have the meaning as in C, always returning either 0 or 1, and short-circuit evaluation if the left-hand side is false (for &&) or true (for ). The break and continue statements must occur inside a while loop and also have the semantics of C: break jumps to the first statement after the current loop, and continue skips the remaining statements in the body of the loop and jumps directly to the testing of the exit condition. 3 IR Trees In the translation to IR trees we want to achieve several goals. One is to isolate potentially effectful expressions, making their order of execution explicit. This simplifies instruction selection and also means that the remaining pure expressions can be optimized much more effectively. Another goal is to make the control flow explicit in the form of conditional or unconditional branches, which is closer to the assembly language target and allows us to apply standard program analyses based on an explicit control flow graph. The treatment in the textbook achieves this [App98, Chapters 7 and 8] but it does so in a somewhat complicated manner using tree transformations that would not be motivated for our language. We describe the IR through pure expressions p and commands c. Programs are just sequences of commands; typically these would be the bodies of function definitions. An empty sequence of commands is denoted by, and we write r 1 ; r 2 for the concatenation of two sequences of commands.
3 Intermediate Representation L10.3 Pure Expressions p ::= n x p 1 p 2 Commands c ::= x p x p 1 p 2 x f(p 1,..., p n ) if (p) goto l goto l l : return(p) Programs r ::= c 1 ;... ; c n Pure expressions are a subset of all expressions that do not have any (side)effects. We choose an IR tree representation in which potentially effectful operations and function calls can only appear at the top-level of assignments. The logical operators are no longer present and must be eliminated in the translation in favor of conditionals. These transformations help optimizations and analysis. Function calls only take pure arguments, which guarantees the left-to-right evaluation order prescribed in the C0 language semantics. Since function calls may have effects, we also lift function calls to the command level rather than embedded inside expression evaluation. 4 Translating Expressions The first idea may be to translate abstract syntax expressions to pure expressions, but this does not quite work because potentially effectful expressions have to be turned into commands, and commands are not permitted inside pure expressions. Returning just a command, or sequence of commands, is also insufficient because we somehow need to refer to the result of the translation as a pure expression so we can use it, for example, in a conditional jump or return command. A solution is to translate from an expression e to a pair consisting of a sequence of instructions r and a pure expression p. After executing r, the value of p will the value of e (assuming the computation does not abort). We write tr(e) = ě, ê where ě is a sequence of commands r that we need to write down to compute the effects of e and ê is a pure expression p that we can use to compute
4 L10.4 Intermediate Representation the value of e back up. Here are the first three clauses in the definition of tr(e): tr(n) =, n tr(x) =, x tr(e 1 e 2 ) = (ě 1 ; ě 2 ), ê 1 ê 2 Constants and variables translate to themselves. If we have a pure operation e 1 e 2 it is possible that the subexpressions have effects, so we concatenate the command sequences for these to expressions ě 1 and ě 2. Now ê 1 and ê 2 are pure expressions referring to the values of e 1 and e 2, respectively, so we can combine them with a pure operation to get a pure expression representing the result. We can see that the translation of any pure expression p yields an empty sequence of commands followed by the same pure expression p, that is, tr(p) =, p. Effectful operations and function calls require us to introduce some commands and a fresh temporary variable to refer to the value resulting from the operation or call. tr(e 1 e 2 ) = (ě 1 ; ě 2 ; t ê 1 ê 2 ), t (t new) tr(f(e 1,..., e n )) = (ě 1 ;... ; ě n ; t f(ê 1,..., ê n )), t (t new) In this and other cases of the translation we need to make sure that new labels are created as targets for conditional jumps, just like we need to create new temporary variables. Finally, a possible translation of one of the logical operators; the second one is left as an exercise. Note that ě 2 is executed only if ê 1 is true. tr(e 1 &&e 2 ) = (ě 1 ; if (!ê 1 ) goto l 1 ; ě 2 ; if (!ê 2 ) goto l 1 ; t 1; goto l 2 ; l 1 : ; t 0; l 2 : ), t (t, l 1, l 2 new) 5 Translating Statements Translating statements is in some ways simpler, because we only need to return a sequence of instructions. It is slightly more complicated in other
5 Intermediate Representation L10.5 ways, because inside loops we need to track the targets for break and continue statements. So the statement translation takes three arguments: the statement to translate, and two optional labels. We elide these labels for simplicity: they are absent on the top-level and passed down in recursive calls and change when entering a while loop. We write tr(s) = š, where š is a sequence of commands r. Assigments and conditionals are simple, given the translation of expression from the previous section. tr(assign(x, e)) = ě; x ê tr(if(e, s 1, s 2 )) = ě; if (ê) goto l 1 ; š 2 ; goto l 2 ; l 1 : ; š 1 ; l 2 : (l 1, l 2 new) There are several plausible translation for a while loop. Due to the way many instantiations of the target architecture do branch prediction, it is efficient for the conditional branch in the loop to go backwards. tr(while(e, s)) = goto l 2 ; l 1 : ; š; l 2 : ; ě; if (ê) goto l 1 ; l 3 : During the recursive translation of s, the break label is set to l 3 and the continue label is set to l 2. The jump into the middle of the loop can interfere with optimizations, so it is often beneficial to replicate the test before loop entry, especially in the common case when the code for ě and ê is small. tr(while(e, s)) = ě; if (!ê) goto l 3 ; l 1 : ; š; l 2 : ; ě; if (ê) goto l 1 ; l 3 :
6 L10.6 Intermediate Representation The remaining cases are simple: break and continue statements jump unconditionally to their corresponding labels; the cases for return, nop and seq are below. tr(return(e)) = ě; return(ê) tr(nop) = tr(seq(s 1, s 2 )) = š 1 ; š 2 6 Ambiguity in Language Specification The C standard explicity leaves the order of evaluation of expressions unspecified [KR88, p. 200]: The precedence and associativity of operators is fully specified, but the order of evaluation of expressions is, with certain exceptions, undefined, even if the subexpressions involve side effects. At first, this may seem like a virtue: by leaving evaluation order unspecified, the compiler can freely optimize expressions without running afoul the specification. The flip side of this coin is that programs are almost by definition not portable. They may check and execute just fine with a certain compiler, but subtly or catastrophically break when a compiler is updated, or the program is compiled with a different compiler. A possible reply to this argument is that a program whose proper execution depends on the order of evaluation is simply wrong, and the programmer should not be surprised if it breaks. The flaw in this argument is that dependence on evaluation order may be a very subtle property, and neither language definition nor compiler give much help in identifying such flaws in a program. No amount of testing with a single compiler can uncover such problems, because often the code will execute correctly under the decision made for this compiler. It may even be that all available compilers at the time the code is written may agree, say, evaluating expressions from left to right, but the code could break in a future version. Therefore I strongly believe that language specifications should be entirely unambiguous. In this course, this is also important because we want to hold all compilers to the same standard of correctness. This is also why the behavior of division by 0 and division overflow, namely an exception, is fully specified. It is not acceptable for an expression such as (1/0)*0 to be optimized to 0. Instead, it must raise an exception.
7 Intermediate Representation L10.7 The translation to intermediate code presented here therefore must make sure that any ;potentially effectful expressions are indeed evaluated from left to right. Careful inspection of the translation will reveal this to be the case. On the resulting pure expressions, many valid optimizations can still be applied which would otherwise be impossible, such as commutativity, associativity, or distributivity, all of which hold for modular arithmetic. References [App98] Andrew W. Appel. Modern Compiler Implementation in ML. Cambridge University Press, Cambridge, England, [KR88] Brian W. Kernighan and Dennis M. Ritchie. The C Programming Language. Prentice Hall, second edition, 1988.
Lecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 9 September 24, 2009 1 Introduction In this lecture we discuss the middle end of the compiler. After the source
More informationLecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 10 1 Introduction In this lecture we discuss the middle end of the compiler. After the source has been parsed
More informationLecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 10 September 26, 2013 1 Introduction In this lecture we discuss the middle end of the compiler. After the source
More informationLecture Notes on Compiler Design: Overview
Lecture Notes on Compiler Design: Overview 15-411: Compiler Design Frank Pfenning Lecture 1 August 26, 2014 1 Introduction This course is a thorough introduction to compiler design, focusing on more lowlevel
More informationLecture Notes on Dataflow Analysis
Lecture Notes on Dataflow Analysis 15-411: Compiler Design Frank Pfenning Lecture 5 September 9, 2008 1 Introduction In this lecture we first extend liveness analysis to handle memory references and then
More informationLecture Notes on Liveness Analysis
Lecture Notes on Liveness Analysis 15-411: Compiler Design Frank Pfenning André Platzer Lecture 4 1 Introduction We will see different kinds of program analyses in the course, most of them for the purpose
More informationLecture Notes on Bottom-Up LR Parsing
Lecture Notes on Bottom-Up LR Parsing 15-411: Compiler Design Frank Pfenning Lecture 9 September 23, 2009 1 Introduction In this lecture we discuss a second parsing algorithm that traverses the input string
More informationLecture Notes on Static Single Assignment Form
Lecture Notes on Static Single Assignment Form 15-411: Compiler Design Frank Pfenning Lecture 6 September 12, 2013 1 Introduction In abstract machine code of the kind we have discussed so far, a variable
More informationTheoretical Part. Chapter one:- - What are the Phases of compiler? Answer:
Theoretical Part Chapter one:- - What are the Phases of compiler? Six phases Scanner Parser Semantic Analyzer Source code optimizer Code generator Target Code Optimizer Three auxiliary components Literal
More informationLecture Notes on Bottom-Up LR Parsing
Lecture Notes on Bottom-Up LR Parsing 15-411: Compiler Design Frank Pfenning Lecture 9 1 Introduction In this lecture we discuss a second parsing algorithm that traverses the input string from left to
More informationLecture Notes on Shift-Reduce Parsing
Lecture Notes on Shift-Reduce Parsing 15-411: Compiler Design Frank Pfenning, Rob Simmons, André Platzer Lecture 8 September 24, 2015 1 Introduction In this lecture we discuss shift-reduce parsing, which
More informationLecture 4: Syntax Specification
The University of North Carolina at Chapel Hill Spring 2002 Lecture 4: Syntax Specification Jan 16 1 Phases of Compilation 2 1 Syntax Analysis Syntax: Webster s definition: 1 a : the way in which linguistic
More informationChapter 9: Dealing with Errors
Chapter 9: Dealing with Errors What we will learn: How to identify errors Categorising different types of error How to fix different errors Example of errors What you need to know before: Writing simple
More informationThis book is licensed under a Creative Commons Attribution 3.0 License
6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars
More informationLECTURE 17. Expressions and Assignment
LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationSemantics via Syntax. f (4) = if define f (x) =2 x + 55.
1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)
More informationLecture Notes on Static Semantics
Lecture Notes on Static Semantics 15-411: Compiler Design Frank Pfenning Lecture 12 October 8, 2015 1 Introduction After lexing and parsing, a compiler will usually apply elaboration to translate the parse
More informationWhere we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers
Where we are CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 13: Intermediate Code 25 Sep 09 Source code (character stream) Token stream Abstract syntax tree Abstract syntax tree
More informationA simple syntax-directed
Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationProgramming Language Processor Theory
Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern
More informationProgramming Languages Third Edition. Chapter 9 Control I Expressions and Statements
Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE
More informationParsing. 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 informationLecture Notes on Register Allocation
Lecture Notes on Register Allocation 15-411: Compiler Design Frank Pfenning Lecture 3 September 1, 2009 1 Introduction In this lecture we discuss register allocation, which is one of the last steps in
More informationLecture Notes on Program Equivalence
Lecture Notes on Program Equivalence 15-312: Foundations of Programming Languages Frank Pfenning Lecture 24 November 30, 2004 When are two programs equal? Without much reflection one might say that two
More informationLecture Notes on Static Single Assignment Form
Lecture Notes on Static Single Assignment Form 15-411: Compiler Design Frank Pfenning, Rob Simmons Lecture 10 October 1, 2015 1 Introduction In abstract machine code of the kind we have discussed so far,
More informationCST-402(T): Language Processors
CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars
More informationCompilers - Chapter 2: An introduction to syntax analysis (and a complete toy compiler)
Compilers - Chapter 2: An introduction to syntax analysis (and a complete toy compiler) Lecturers: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 304, William Penney Building Naranker Dulay (nd@doc.ic.ac.uk)
More informationChapter 3. Describing Syntax and Semantics
Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:
More informationChapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees
Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees 3.3.1 Parse trees 1. Derivation V.S. Structure Derivations do not uniquely represent the structure of the strings
More informationSpecifying Syntax COMP360
Specifying Syntax COMP360 The most important thing in the programming language is the name. A language will not succeed without a good name. I have recently invented a very good name and now I am looking
More informationLecture Notes on Top-Down Predictive LL Parsing
Lecture Notes on Top-Down Predictive LL Parsing 15-411: Compiler Design Frank Pfenning Lecture 8 1 Introduction In this lecture we discuss a parsing algorithm that traverses the input string from l eft
More informationCMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield
CMPS 3500 Programming Languages Dr. Chengwei Lei CEECS California State University, Bakersfield Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing
More informationProgramming Languages Third Edition
Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand
More informationLecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning
Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,
More informationLecture Compiler Middle-End
Lecture 16-18 18 Compiler Middle-End Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 What We Have Done A lot! Compiler Frontend Defining language Generating
More informationprogramming languages need to be precise a regular expression is one of the following: tokens are the building blocks of programs
Chapter 2 :: Programming Language Syntax Programming Language Pragmatics Michael L. Scott Introduction programming languages need to be precise natural languages less so both form (syntax) and meaning
More informationStating the obvious, people and computers do not speak the same language.
3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what
More informationBuilding Compilers with Phoenix
Building Compilers with Phoenix Syntax-Directed Translation Structure of a Compiler Character Stream Intermediate Representation Lexical Analyzer Machine-Independent Optimizer token stream Intermediate
More informationAcknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation
Acknowledgement CS3300 - Compiler Design Semantic Analysis - IR Generation V. Krishna Nandivada IIT Madras Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all
More informationIteration. Side effects
Computer programming Iteration. Side effects Marius Minea marius@cs.upt.ro 17 October 2017 Assignment operators We ve used the simple assignment: lvalue = expression lvalue = what can be on the left of
More informationLecture Notes on Common Subexpression Elimination
Lecture Notes on Common Subexpression Elimination 15-411: Compiler Design Frank Pfenning Lecture 18 October 29, 2015 1 Introduction Copy propagation allows us to have optimizations with this form: l :
More informationA Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013
A Bad Name Optimization is the process by which we turn a program into a better one, for some definition of better. CS 2210: Optimization This is impossible in the general case. For instance, a fully optimizing
More informationLecture 10 Parsing 10.1
10.1 The next two lectures cover parsing. To parse a sentence in a formal language is to break it down into its syntactic components. Parsing is one of the most basic functions every compiler carries out,
More informationCS 406/534 Compiler Construction Putting It All Together
CS 406/534 Compiler Construction Putting It All Together 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
More information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationAn Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1
An Overview to Compiler Design 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1 Outline An Overview of Compiler Structure Front End Middle End Back End 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 2 Reading
More informationTopic 7: Intermediate Representations
Topic 7: Intermediate Representations COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 2 Intermediate Representations 3 Intermediate Representations 4 Intermediate Representations
More informationCS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting
CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation
More informationIntroduction to Lexing and Parsing
Introduction to Lexing and Parsing ECE 351: Compilers Jon Eyolfson University of Waterloo June 18, 2012 1 Riddle Me This, Riddle Me That What is a compiler? 1 Riddle Me This, Riddle Me That What is a compiler?
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationOptimizing Finite Automata
Optimizing Finite Automata We can improve the DFA created by MakeDeterministic. Sometimes a DFA will have more states than necessary. For every DFA there is a unique smallest equivalent DFA (fewest states
More informationCompiler Design: Lab 3 Fall 2009
15-411 Compiler Design: Lab 3 Fall 2009 Instructor: Frank Pfenning TAs: Ruy Ley-Wild and Miguel Silva Test Programs Due: 11:59pm, Thursday, October 8, 2009 Compilers Due: 11:59pm, Thursday, October 15,
More informationIntro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 1 Tuesday, January 29, 2013 1 Intro to semantics What is the meaning of a program? When we write a program, we use
More informationLecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning
Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,
More informationCSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings
More informationLexical Scanning COMP360
Lexical Scanning COMP360 Captain, we re being scanned. Spock Reading Read sections 2.1 3.2 in the textbook Regular Expression and FSA Assignment A new assignment has been posted on Blackboard It is due
More informationCSCI312 Principles of Programming Languages!
CSCI312 Principles of Programming Languages! Chapter 2 Syntax! Xu Liu Review! Principles of PL syntax, naming, types, semantics Paradigms of PL design imperative, OO, functional, logic What makes a successful
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Syntactic Analysis Dr. Hyunyoung Lee 1 What Is a Programming Language? Language = syntax + semantics The syntax of a language is concerned with the form of a program: how
More informationList of Figures. About the Authors. Acknowledgments
List of Figures Preface About the Authors Acknowledgments xiii xvii xxiii xxv 1 Compilation 1 1.1 Compilers..................................... 1 1.1.1 Programming Languages......................... 1
More informationLecture Notes on Loop Optimizations
Lecture Notes on Loop Optimizations 15-411: Compiler Design Frank Pfenning Lecture 17 October 22, 2013 1 Introduction Optimizing loops is particularly important in compilation, since loops (and in particular
More informationCS 6110 S14 Lecture 1 Introduction 24 January 2014
CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions
More informationParsing 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 informationAssignment 4: Semantics
Assignment 4: Semantics 15-411: Compiler Design Jan Hoffmann Jonathan Burns, DeeDee Han, Anatol Liu, Alice Rao Due Thursday, November 3, 2016 (9:00am) Reminder: Assignments are individual assignments,
More informationCS415 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 informationLECTURE 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 informationLecture 15: Iteration and Recursion
Lecture 15: and Recursion The University of North Carolina at Chapel Hill Spring 2002 Lecture 15: and Recursion Feb 13/15 1 Control Flow Mechanisms Sequencing Textual order, Precedence in Expression Selection
More informationSyntax Analysis, VII One more LR(1) example, plus some more stuff. Comp 412 COMP 412 FALL Chapter 3 in EaC2e. target code.
COMP 412 FALL 2017 Syntax Analysis, VII One more LR(1) example, plus some more stuff Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More informationWe ve written these as a grammar, but the grammar also stands for an abstract syntax tree representation of the IR.
CS 4120 Lecture 14 Syntax-directed translation 26 September 2011 Lecturer: Andrew Myers We want to translate from a high-level programming into an intermediate representation (IR). This lecture introduces
More informationParsing. source code. while (k<=n) {sum = sum+k; k=k+1;}
Compiler Construction Grammars Parsing source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2012 01 23 2012 parse tree AST builder (implicit)
More informationWorking of the Compilers
Working of the Compilers Manisha Yadav Nisha Thakran IT DEPARTMENT IT DEPARTMENT DCE,GURGAON DCE,GURGAON Abstract- The objective of the paper is to depict the working of the compilers that were designed
More informationannouncements CSE 311: Foundations of Computing review: regular expressions review: languages---sets of strings
CSE 311: Foundations of Computing Fall 2013 Lecture 19: Regular expressions & context-free grammars announcements Reading assignments 7 th Edition, pp. 878-880 and pp. 851-855 6 th Edition, pp. 817-819
More informationSardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization
Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA
More informationChapter 6 Control Flow. June 9, 2015
Chapter 6 Control Flow June 9, 2015 Expression evaluation It s common in programming languages to use the idea of an expression, which might be a simple object function invocation over some number of arguments
More informationEECS 6083 Intro to Parsing Context Free Grammars
EECS 6083 Intro to Parsing Context Free Grammars Based on slides from text web site: Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. 1 Parsing sequence of tokens parser
More information8. Control statements
8. Control statements A simple C++ statement is each of the individual instructions of a program, like the variable declarations and expressions seen in previous sections. They always end with a semicolon
More informationSyntax 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 informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
More informationFall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev
Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation
More informationAlternatives for semantic processing
Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies
More informationCSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona
CSc 453 Compilers and Systems Software 13 : Intermediate Code I Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Introduction Compiler Phases
More informationSection A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.
Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or
More informationCSE 311 Lecture 21: Context-Free Grammars. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 21: Context-Free Grammars Emina Torlak and Kevin Zatloukal 1 Topics Regular expressions A brief review of Lecture 20. Context-free grammars Syntax, semantics, and examples. 2 Regular expressions
More informationOperational Semantics. One-Slide Summary. Lecture Outline
Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:
More informationStatic Checking and Intermediate Code Generation Pat Morin COMP 3002
Static Checking and Intermediate Code Generation Pat Morin COMP 3002 Static Checking and Intermediate Code Generation Parser Static Checker Intermediate Code Generator Intermediate Code Generator Parse
More information22c:111 Programming Language Concepts. Fall Syntax III
22c:111 Programming Language Concepts Fall 2008 Syntax III Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified
More informationSyntax 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 informationPrinciple of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments
More information3. Parsing. Oscar Nierstrasz
3. Parsing Oscar 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 informationFormal Languages and Compilers Lecture I: Introduction to Compilers
Formal Languages and Compilers Lecture I: Introduction to Compilers Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/
More informationCOP 3402 Systems Software Syntax Analysis (Parser)
COP 3402 Systems Software Syntax Analysis (Parser) Syntax Analysis 1 Outline 1. Definition of Parsing 2. Context Free Grammars 3. Ambiguous/Unambiguous Grammars Syntax Analysis 2 Lexical and Syntax Analysis
More informationCSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1
CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on
More informationGarbage In/Garbage SIGPLAN Out
COMFY A Comfortable Set of Control Primitives for Machine Language Programming Author: Henry G. Baker, http://home.pipeline.com/ hbaker1/home.html; hbaker1@pipeline.com Henry G. Baker 1 Laboratory for
More informationCPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia
CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia This is a closed book exam; no notes; no calculators. Answer in the space provided. There are 8 questions on 14 pages,
More informationCNG 140 C Programming. Syllabus. Course Info Fall Semester. Catalog Description
CNG 140 C Programming 2012-2013 Fall Semester Syllabus Course Info Catalog Description Advanced programming with C: Storage and control structures, recursion and programming with dynamic data structures.
More informationHomework & Announcements
Homework & nnouncements New schedule on line. Reading: Chapter 18 Homework: Exercises at end Due: 11/1 Copyright c 2002 2017 UMaine School of Computing and Information S 1 / 25 COS 140: Foundations of
More informationCompiler Design Overview. Compiler Design 1
Compiler Design Overview Compiler Design 1 Preliminaries Required Basic knowledge of programming languages. Basic knowledge of FSA and CFG. Knowledge of a high programming language for the programming
More informationProject 3 Due October 21, 2015, 11:59:59pm
Project 3 Due October 21, 2015, 11:59:59pm 1 Introduction In this project, you will implement RubeVM, a virtual machine for a simple bytecode language. Later in the semester, you will compile Rube (a simplified
More information