Transcription

2 What is Compiler? Software systems that translate a program written in one language ( source language ) into a program written in another language ( target language ). Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

3 What is Compiler? Software systems that translate a program written in one language ( source language ) into a program written in another language ( target language ). Typically, the source language is a high-level language, e.g., C, and the target language is a machine language, e.g., x86. Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

4 What is Compiler? Software systems that translate a program written in one language ( source language ) into a program written in another language ( target language ). Typically, the source language is a high-level language, e.g., C, and the target language is a machine language, e.g., x86. cf) When the target language is not a machine language: Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

6 Structure of Modern Compilers The front-end understands the source program and translates it to an intermediate representation (IR). The middle-end takes a program in IR and optimizes it in terms of efficiency, energy consumption, and so on. The back-end transforms the IR program into machine-code. Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

7 Front End The lexical analyzer transforms the character stream into a stream of tokens. The syntax analyzer transforms the stream of tokens into a syntax tree. The semantic analyzer checks if the program is semantically well-formed. The IR translator translates the syntax tree into IR. Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

8 Lexical 1 Analyzer (Lexer) A lexer analyzes the lexical structure of the source program: 1 of or relating to words or the vocabulary of a language as distinguished from its grammar and construction Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

9 Lexical 1 Analyzer (Lexer) A lexer analyzes the lexical structure of the source program: ex) The lexical analyzer transform the character stream pos = init + rate * 10 1 of or relating to words or the vocabulary of a language as distinguished from its grammar and construction Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

10 Lexical 1 Analyzer (Lexer) A lexer analyzes the lexical structure of the source program: ex) The lexical analyzer transform the character stream pos = init + rate * 10 into a sequence of lexemes: pos, =, init, +, rate, *, 10 1 of or relating to words or the vocabulary of a language as distinguished from its grammar and construction Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

12 Syntax 2 Analyzer (Parser) A parser analyzes the grammatical structure of the source program: 2 the way in which words are put together to form phrases, clauses, or sentences Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

13 Syntax 2 Analyzer (Parser) A parser analyzes the grammatical structure of the source program: ex) the parser transforms the sequence of tokens into the syntax tree: (ID, pos), =, (ID, init), +, (ID, rate), *, (NUM,10) 2 the way in which words are put together to form phrases, clauses, or sentences Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

22 Summary A modern compiler consists of three phases: Front end understands the syntax and semantics of source program. Middle end improves the efficiency of the program. Back end generates the target program. Hakjoo Oh COSE Spring, Lecture 1 March 7, / 15

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

Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution

Overview Roadmap Language Translators: Interpreters & Compilers Context of a compiler Phases of a compiler Compiler Construction tools Terminology How related to other CS Goals of a good compiler 1 Compilers

COMP455: COMPILER AND LANGUAGE DESIGN Dr. Alaa Aljanaby University of Nizwa Spring 2013 Chapter 1: Introduction Compilers draw together all of the theory and techniques that you ve learned about in most

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

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character 2. The symbol table implementation is based on the property of locality of reference is a) Linear

CA4003 - Compiler Construction Semantic Analysis David Sinclair Semantic Actions A compiler has to do more than just recognise if a sequence of characters forms a valid sentence in the language. It must

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical

CD Assignment I 1. Explain the various phases of the compiler with a simple example. The compilation process is a sequence of various phases. Each phase takes input from the previous, and passes the output

Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

Syntax Analysis MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Goal of this chapter Understand the syntaxic structure of a language; Separate the different steps of syntax analysis; Be able to write a

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

Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:

CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 7 1 Announcements First project and second homework

Compiling Regular Expressions COMP360 Logic is the beginning of wisdom, not the end. Leonard Nimoy Compiler s Purpose The compiler converts the program source code into a form that can be executed by the

COP4020 Spring 2011 Midterm Exam Name: (Please print Put the answers on these sheets. Use additional sheets when necessary or write on the back. Show how you derived your answer (this is required for full

Introduction to Compilers Compilers are language translators input: program in one language output: equivalent program in another language Introduction to Compilers Two types Compilers offline Data Program

CS415 Compilers Overview of the Course These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Critical Facts Welcome to CS415 Compilers Topics in the

SECOND SEMESTER 2015-2016 Course Handout (Part II) Date:23-01-2017 In addition to part I (General Handout for all courses appended to the time table) this portion gives further specific details regarding

Abstract Syntax Trees & Top-Down Parsing Review of Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree

Review of Parsing Abstract Syntax Trees & Top-Down Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree

Review of Parsing Abstract Syntax Trees & Top-Down Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree

i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target