Introduction - CAP Course

Similar documents
Compilation: a bit about the target architecture

Lexing, Parsing. Laure Gonnord sept Master 1, ENS de Lyon

Writing Evaluators MIF08. Laure Gonnord

Compilation and Program Analysis (#11) : Hoare triples and shape analysis

Compiler Design (40-414)

Syntax Analysis MIF08. Laure Gonnord

Compil M1 : Front-End

Usually, target code is semantically equivalent to source code, but not always!

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Undergraduate Compilers in a Day

Lab 2. Lexing and Parsing with ANTLR4

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Lab 1. Warm-up : discovering the target machine, LC-3

Semantic Analysis. Lecture 9. February 7, 2018

LECTURE 3. Compiler Phases

Interpreters. Prof. Clarkson Fall Today s music: Step by Step by New Kids on the Block

CS 415 Midterm Exam Spring 2002

Introduction to Compiler Construction

Compiler Construction

Lab 1. Warm-up : Python and the target machine : LEIA

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

CMPT 379 Compilers. Anoop Sarkar.

Introduction to Compiler Construction

Syntax and Grammars 1 / 21

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Compilers Crash Course

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

COMP455: COMPILER AND LANGUAGE DESIGN. Dr. Alaa Aljanaby University of Nizwa Spring 2013

CS202 Compiler Construction. Christian Skalka. Course prerequisites. Solid programming skills a must.

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

CS/SE 153 Concepts of Compiler Design

CMPE 152 Compiler Design

Formats of Translated Programs

Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )

Welcome to CSE131b: Compiler Construction

Compilers - Chapter 2: An introduction to syntax analysis (and a complete toy compiler)

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Finding People and Information (1) G53CMP: Lecture 1. Aims and Motivation (1) Finding People and Information (2)

Compiling Regular Expressions COMP360

Compiling Techniques

What do Compilers Produce?

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

COMPILER DESIGN LECTURE NOTES

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Types and Static Type Checking (Introducing Micro-Haskell)

Programmiersprachen (Programming Languages)

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Compiler Design. Lecture 1

COMPILER DESIGN. For COMPUTER SCIENCE

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

CMPE 152 Compiler Design

Compilers and Interpreters

Chapter 11 Introduction to Programming in C

CS453 Compiler Construction

CS 321 IV. Overview of Compilation

Formal Languages and Compilers Lecture I: Introduction to Compilers

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

SLIDE 2. At the beginning of the lecture, we answer question: On what platform the system will work when discussing this subject?

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

A simple syntax-directed

Compilers and Code Optimization EDOARDO FUSELLA

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Introduction to Compiler

Chapter 11 Introduction to Programming in C

CS 4201 Compilers 2014/2015 Handout: Lab 1

CA Compiler Construction

CS426 Compiler Construction Fall 2006

Life Cycle of Source Program - Compiler Design

Why are there so many programming languages?

The Structure of a Syntax-Directed Compiler

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Inside PHP Tom OSCON th July, 2012

1DL321: Kompilatorteknik I (Compiler Design 1)

CSI32 Object-Oriented Programming

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis


About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Compilers. Pierre Geurts

The Structure of a Compiler

Building Compilers with Phoenix

15-411/ Compiler Design

CSEP 501 Compilers. Overview and Administrivia Hal Perkins Winter /8/ Hal Perkins & UW CSE A-1

Introduction. Compilers and Interpreters

Chapter 10 Language Translation

Compilers and interpreters

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Compiler Construction D7011E

Verified compilers. Guest lecture for Compiler Construction, Spring Magnus Myréen. Chalmers University of Technology

Compiler Construction Lecture 1: Introduction Winter Semester 2018/19 Thomas Noll Software Modeling and Verification Group RWTH Aachen University

Introduction. Interpreters High-level language intermediate code which is interpreted. Translators. e.g.

Advances in Compilers

Compiler Construction Lecture 1: Introduction Summer Semester 2017 Thomas Noll Software Modeling and Verification Group RWTH Aachen University

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Concepts in Programming Languages

Transcription:

Introduction - CAP Course Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@ens-lyon.fr Master 1, ENS de Lyon sept 2016

Credits A large part of the compilation part of this course is inspired by the Compilation Course of JC Filliâtre at ENS Ulm who kindly offered the source code of his slides. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 2 / 20

What s compilation? source language compiler targuet language errors Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 3 / 20

Compilation toward the machine language We immediatly think of the translation of a high-level language (C,Java,OCaml) into the machine language of a processor (Pentium, PowerPC... ) % gcc -o sum sum.c i n t main ( i n t argc, char argv ) { i n t i, s = 0; for ( i = 0; i <= 100; i ++) s += i i ; p r i n t f ( " 0 0+...+100 100 = %d \ n ", s ) ; } 0010011110111101111111111110000010101111101111110000000000010100 1010111110100100000000000010000010101111101001010000000000100100 1010111110100000000000000001100010101111101000000000000000011100 10001111101011100000000000011100 Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 4 / 20

Target Language This aspect (compilation into assembly) will be presented in this course, but we will do more : Compilation is not (only) code generation A large number of compilation techniques are not linked to assembly code production. Moreover, languages can be interpreted (Basic, COBOL, Ruby, Python, etc.) compiled into an intermediate language that will be interpreted (Java, OCaml, Scala, etc.) compiled into another high level language (or the same!) compiled on the fly (or just on time) Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 5 / 20

Compiler/ Interpreter A compiler translates a program P intro a program Q such that for all entry x, the output Q(x) is the same as P (x). P Q x... An interpreter is a program that, given a program P and an entry x, computes the output of P (x) : P x s... Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 6 / 20

Compiler vs Interpreter Or : The compler makes a complex work once, to produce a code for whatever entry. An interpreter makes a simpler job, but on every entry. In general the code after compilation is more efficient. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 7 / 20

Example source lilypond PostScript file gs image \chords { c2 c f2 c } \new Staff \relative c' { \time 2/4 c4 c g'4 g a4 a g2 } \new Lyrics \lyricmode { twin4 kle twin kle lit tle star2 } 4 2 C C twin kle twin kle F C lit tle star Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 8 / 20

Compiler Quality Quality criteria? correctness efficiency of the generated code its own efficiency Optimizing compilers are so difficult to get right that we dare say that no optimizing compiler is completely error-free! Thus, the most important objective in writing a compiler is that it is correct. (Dragon Book, 2006) Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 9 / 20

Program Analysis To prove : Correctness of compilers/optimisations phases. Correctnes of programs : invariants... the second part of the course. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 10 / 20

Course Objective Be familiar with the mecanisms inside a (simple) compiler. Be familiar with basis of program analysis. And understand the links between them! Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 11 / 20

Course Content - Compilation Part Syntax Analysis : lexing, parsing, AST, types. Evaluators. Code generation. Code Optimisation. Lab : a complete compiler for the LC-3 architecture! Support language : Python 2.7 Frontend infrastructure : ANTLR 4. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 12 / 20

Course Content - Analysis Part Concrete semantics Abstract Interpretation A bit of verification : abstract interpretation, Hoare logic,... Labs : abstract interpretation. Support language : (most probably) Ocaml Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 13 / 20

Course Organization 13 + 1 course slots : Laure Gonnord. 14 lab slots : Aurélien Cavelan and Lionel Morel. The official URL : http://laure.gonnord.org/pro/teaching/capm1.html Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 14 / 20

Evaluation One partial exam. 2 mini-projects (labs). A final exam. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 15 / 20

Compiler phases 1 Compiler phases Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 16 / 20

Compiler phases Compiler phases Usually, we distinguish two parts in the design of a compiler : an analysis phase : recognizes the program to translate and its meaning. launch errors (syntax, scope, types... ) Then a synthesis phase : produces a target file. sometimes optmises. Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 17 / 20

Compiler phases Analysis Phase source code lexical analysis sequence of lexems (tokens) syntactic analysis (Parsing) abstract syntax tree (AST ) semantic analysis abstract syntax (+ symbol table) Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 18 / 20

Compiler phases Synthesis Phase abstract syntax code production (numerous phases) assembly language assembly (as) machine language linker (ld) executable code Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 19 / 20

Compiler phases Today assembly Laure Gonnord (M1/DI-ENSL) Introduction - CAP Course 2016 20 / 20