G53CMP: Lecture 1. Administrative Details 2016 and Introduction to Compiler Construction. Henrik Nilsson. University of Nottingham, UK

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

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

Compiler Construction LECTURE # 1

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Recap: Typical Compiler Structure. G53CMP: Lecture 2 A Complete (Albeit Small) Compiler. This Lecture (2) This Lecture (1)

Compiling Techniques

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

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

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

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

CST-402(T): Language Processors

Formal Languages and Compilers Lecture I: Introduction to Compilers

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

General Course Information. Catalogue Description. Objectives

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

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

Compiler construction

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

Compilers Crash Course

Compiler Construction

Compilers. Prerequisites

Important Project Dates

12048 Compilers II. Computer Science Engineering, 8º semester Mandatory, 2º Cycle. Theoretical credits: 3.0 Lab credits: 1.5. Theory: José Neira

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

INF5110 Compiler Construction

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

Introduction to Compiler Construction

Introduction to Compiler Construction

ECE573 Introduction to Compilers & Translators

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

CA Compiler Construction

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

Compiler Theory Introduction and Course Outline Sandro Spina Department of Computer Science

understanding recursive data types, recursive functions to compute over them, and structural induction to prove things about them

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

Compiler Construction Principles And Practice Solution Manual

CS/SE 153 Concepts of Compiler Design

CS 236 Language and Computation

History of Compilers The term

CSCI 565 Compiler Design and Implementation Spring 2014

DOID: A Lexical Analyzer for Understanding Mid-Level Compilation Processes

Compilers and computer architecture: introduction

Compilers for Modern Architectures Course Syllabus, Spring 2015

CS131: Programming Languages and Compilers. Spring 2017

CS 314 Principles of Programming Languages

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Working of the Compilers

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

CSE 504: Compiler Design

SOFTWARE ENGINEERING

CMPE 152 Compiler Design

CSE 582 Autumn 2002 Exam 11/26/02

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

G52LAC Languages and Computation Lecture 6

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

ST. XAVIER S COLLEGE

Compiler Construction 2010 (6 credits)

Concepts of Programming Languages

SOFTWARE ENGINEERING

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM

CMPE 152 Compiler Design

Compilers and Interpreters

Compiler Design (40-414)

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

Compiler Construction D7011E

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson

CS/SE 153 Concepts of Compiler Design

Compiler Construction

Overview of the Class

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

CS164: Midterm I. Fall 2003

Compiler Construction

CISC 124: Introduction To Computing Science II

Compilers and Code Optimization EDOARDO FUSELLA

Intermediate Representations

Compiler Design Spring 2018

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

What do Compilers Produce?

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

Overview of the Class

15-411/ Compiler Design

HOLY ANGEL UNIVERSITY COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY COMPILER THEORY COURSE SYLLABUS

Compiler Design Overview. Compiler Design 1

Why are there so many programming languages?

Compiling Regular Expressions COMP360

CS 242. Fundamentals. Reading: See last slide

Read & Download (PDF Kindle) Engineering A Compiler

CS 406/534 Compiler Construction Putting It All Together

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

A Brief Haskell and GHC Refresher

Programming Languages 2nd edition Tucker and Noonan"

Part A: Course Outline

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

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

COMPILER DESIGN LECTURE NOTES

Transcription:

G53CMP: Lecture 1 Administrative Details 2016 and Introduction to Compiler Construction Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 1 p.1/39

Finding People and Information (1) Henrik Nilsson Room A08, Computer Science Building e-mail: nhn@cs.nott.ac.uk Teaching Assistant (TA): Jonathan Fowler e-mail: jzf@cs.nott.ac.uk G53CMP: Lecture 1 p.2/39

Finding People and Information (2) Main module web page: www.cs.nott.ac.uk/~psznhn/g53cmp G53CMP: Lecture 1 p.3/39

Finding People and Information (2) Main module web page: www.cs.nott.ac.uk/~psznhn/g53cmp Moodle: moodle.nottingham.ac.uk/ course/view.php?id=45541 G53CMP: Lecture 1 p.3/39

Finding People and Information (2) Main module web page: www.cs.nott.ac.uk/~psznhn/g53cmp Moodle: moodle.nottingham.ac.uk/ course/view.php?id=45541 Direct questions concerning lectures and coursework to the Moodle G53CMP Forum. G53CMP: Lecture 1 p.3/39

Finding People and Information (2) Main module web page: www.cs.nott.ac.uk/~psznhn/g53cmp Moodle: moodle.nottingham.ac.uk/ course/view.php?id=45541 Direct questions concerning lectures and coursework to the Moodle G53CMP Forum. Anyone can ask and answer questions, but you must not post exact solutions to the coursework. G53CMP: Lecture 1 p.3/39

Aims and Motivation (1) Why study Compiler Construction? G53CMP: Lecture 1 p.4/39

Aims and Motivation (1) Why study Compiler Construction? Why did you opt to take this module? G53CMP: Lecture 1 p.4/39

Aims and Motivation (1) Why study Compiler Construction? Why did you opt to take this module? More generally, what do you think are good reasons to take this module? G53CMP: Lecture 1 p.4/39

Aims and Motivation (2) Aims: Deepened understanding of: G53CMP: Lecture 1 p.5/39

Aims and Motivation (2) Aims: Deepened understanding of: how compilers (and interpreters) work and are constructed G53CMP: Lecture 1 p.5/39

Aims and Motivation (2) Aims: Deepened understanding of: how compilers (and interpreters) work and are constructed programming language design and semantics G53CMP: Lecture 1 p.5/39

Aims and Motivation (2) Aims: Deepened understanding of: how compilers (and interpreters) work and are constructed programming language design and semantics The former is a great, hands on, learning-by-doing way to learn the latter. G53CMP: Lecture 1 p.5/39

Aims and Motivation (3) Why? G53CMP: Lecture 1 p.6/39

Aims and Motivation (3) Why? The ACM/IEEE 2013 CS Curriculum Guidelines: G53CMP: Lecture 1 p.6/39

Aims and Motivation (3) Why? The ACM/IEEE 2013 CS Curriculum Guidelines: Graduates should realize that the computing field advances at a rapid pace, and graduates must possess a solid foundation that allows and encourages them to maintain relevant skills as the field evolves. Specific languages and technology platforms change over time.... G53CMP: Lecture 1 p.6/39

Aims and Motivation (3) Why? The ACM/IEEE 2013 CS Curriculum Guidelines:... Therefore, graduates need to realize that they must continue to learn and adapt their skills throughout their careers. To develop this ability, students should be exposed to multiple programming languages, tools, paradigms, and technologies as well as the fundamental underlying principles throughout their education. G53CMP: Lecture 1 p.6/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms Computer architecture G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms Computer architecture Programming language semantics G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms Computer architecture Programming language semantics Formal reasoning about programs G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms Computer architecture Programming language semantics Formal reasoning about programs Software engineering aspects G53CMP: Lecture 1 p.7/39

Aims and Motivation (4) Moreover: Compilers: a microcosm of computer science [CT04] Formal Languages and Automata Theory Datastructures and algorithms Computer architecture Programming language semantics Formal reasoning about programs Software engineering aspects Thus, capstone module tying everything together. G53CMP: Lecture 1 p.7/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G53CMP: Lecture 1 p.8/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G52MAL: formal language theory, grammars, (D)FAs G53CMP: Lecture 1 p.8/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G52MAL: formal language theory, grammars, (D)FAs G51MCS, G52IFR: formal reasoning, structural induction G53CMP: Lecture 1 p.8/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G52MAL: formal language theory, grammars, (D)FAs G51MCS, G52IFR: formal reasoning, structural induction G51PRG, G51FUN, G51OOP: programming, understanding programming languages G53CMP: Lecture 1 p.8/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G52MAL: formal language theory, grammars, (D)FAs G51MCS, G52IFR: formal reasoning, structural induction G51PRG, G51FUN, G51OOP: programming, understanding programming languages G51CSA: how computers work G53CMP: Lecture 1 p.8/39

Aims and Motivation (5) Or, in terms of modules, G53CMP directly draws from/informs: G52MAL: formal language theory, grammars, (D)FAs G51MCS, G52IFR: formal reasoning, structural induction G51PRG, G51FUN, G51OOP: programming, understanding programming languages G51CSA: how computers work G54FOP/FPP: programming language theory G53CMP: Lecture 1 p.8/39

Aims and Motivation (6) Jobs? G53CMP: Lecture 1 p.9/39

Aims and Motivation (6) Jobs? There are plenty of companies out there with in-house languages or that critically rely on compiler/interpreter expertise for other reasons. Some possibly surprising examples: G53CMP: Lecture 1 p.9/39

Aims and Motivation (6) Jobs? There are plenty of companies out there with in-house languages or that critically rely on compiler/interpreter expertise for other reasons. Some possibly surprising examples: Facebook G53CMP: Lecture 1 p.9/39

Aims and Motivation (6) Jobs? There are plenty of companies out there with in-house languages or that critically rely on compiler/interpreter expertise for other reasons. Some possibly surprising examples: Facebook Standard Chartered Bank G53CMP: Lecture 1 p.9/39

Aims and Motivation (6) Jobs? There are plenty of companies out there with in-house languages or that critically rely on compiler/interpreter expertise for other reasons. Some possibly surprising examples: Facebook Standard Chartered Bank Jane Street G53CMP: Lecture 1 p.9/39

Learning Outcomes Knowledge of language and compiler design, semantics, key ideas and techniques. Experience of compiler construction tools. Experience of working with a medium-sized program. Programming in various paradigms Capturing design through formal specifications and deriving implementations from those. G53CMP: Lecture 1 p.10/39

Literature (1) David A. Watt and Deryck F. Brown. Programming Language Processors in Java, Prentice-Hall, 1999. Used to be the main book. The lectures partly follow the structure of this book. G53CMP: Lecture 1 p.11/39

Literature (1) David A. Watt and Deryck F. Brown. Programming Language Processors in Java, Prentice-Hall, 1999. Used to be the main book. The lectures partly follow the structure of this book. The coursework was originally based on it. G53CMP: Lecture 1 p.11/39

Literature (1) David A. Watt and Deryck F. Brown. Programming Language Processors in Java, Prentice-Hall, 1999. Used to be the main book. The lectures partly follow the structure of this book. The coursework was originally based on it. Hands-on approach to compiler construction. Particularly good if you like Java. G53CMP: Lecture 1 p.11/39

Literature (1) David A. Watt and Deryck F. Brown. Programming Language Processors in Java, Prentice-Hall, 1999. Used to be the main book. The lectures partly follow the structure of this book. The coursework was originally based on it. Hands-on approach to compiler construction. Particularly good if you like Java. Considers software engineering aspects. G53CMP: Lecture 1 p.11/39

Literature (1) David A. Watt and Deryck F. Brown. Programming Language Processors in Java, Prentice-Hall, 1999. Used to be the main book. The lectures partly follow the structure of this book. The coursework was originally based on it. Hands-on approach to compiler construction. Particularly good if you like Java. Considers software engineering aspects. A bit weak on linking theory with practice. G53CMP: Lecture 1 p.11/39

Literature (2) An alternative: Keith D. Cooper and Linda Torczon. Engineering a Compiler, Elsevier, 2004. Covers more ground in greater depth than this module. G53CMP: Lecture 1 p.12/39

Literature (2) An alternative: Keith D. Cooper and Linda Torczon. Engineering a Compiler, Elsevier, 2004. Covers more ground in greater depth than this module. Gradually becoming the new main reference for the module. G53CMP: Lecture 1 p.12/39

Literature (2) An alternative: Keith D. Cooper and Linda Torczon. Engineering a Compiler, Elsevier, 2004. Covers more ground in greater depth than this module. Gradually becoming the new main reference for the module. For each lecture, there are references to the relevant chapter(s) of both books (see lecture overview on the G53CMP web page). G53CMP: Lecture 1 p.12/39

Literature (3) Great supplement: Alfred V Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers Principles, Techniques, and Tools, Addison-Wesley, 1986. (The Dragon Book.) Classic reference in the field. G53CMP: Lecture 1 p.13/39

Literature (3) Great supplement: Alfred V Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers Principles, Techniques, and Tools, Addison-Wesley, 1986. (The Dragon Book.) Classic reference in the field. Covers much more ground in greater depth than this module. G53CMP: Lecture 1 p.13/39

Literature (3) Great supplement: Alfred V Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers Principles, Techniques, and Tools, Addison-Wesley, 1986. (The Dragon Book.) Classic reference in the field. Covers much more ground in greater depth than this module. A book that will last for years. G53CMP: Lecture 1 p.13/39

Literature (3) Great supplement: Alfred V Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers Principles, Techniques, and Tools, Addison-Wesley, 1986. (The Dragon Book.) Classic reference in the field. Covers much more ground in greater depth than this module. A book that will last for years. There is a New(-ish) 2007 edition! G53CMP: Lecture 1 p.13/39

Literature (3) Great supplement: Alfred V Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers Principles, Techniques, and Tools, Addison-Wesley, 1986. (The Dragon Book.) Classic reference in the field. Covers much more ground in greater depth than this module. A book that will last for years. There is a New(-ish) 2007 edition! But nice that core principles have lasting value! G53CMP: Lecture 1 p.13/39

Literature (4) Other useful references: Benjamin C. Pierce. Types and Programming Languages. Graham Hutton. Programming in Haskell. G53CMP: Lecture 1 p.14/39

Lectures and Handouts Come prepared to take notes. There will be some handouts, but for the most part not. G53CMP: Lecture 1 p.15/39

Lectures and Handouts Come prepared to take notes. There will be some handouts, but for the most part not. All electronic slides, program code, and other supporting material in electronic form used during the lectures, will be made available on the course web page. G53CMP: Lecture 1 p.15/39

Lectures and Handouts Come prepared to take notes. There will be some handouts, but for the most part not. All electronic slides, program code, and other supporting material in electronic form used during the lectures, will be made available on the course web page. However! The electronic record of the lectures is neither guaranteed to be complete nor self-contained! G53CMP: Lecture 1 p.15/39

Assessment (1) First sit: The exam counts for 75 % of the total mark. The coursework counts for the remaining 25 %. 2 h exam, 3 questions, each worth 25 %. G53CMP: Lecture 1 p.16/39

Assessment (1) First sit: The exam counts for 75 % of the total mark. The coursework counts for the remaining 25 %. 2 h exam, 3 questions, each worth 25 %. Bonus! There will be (sub)question(s) on the exam closely related to the coursework! Effectively, the weight of the coursework is thus more like 50 %, except partly examined later. G53CMP: Lecture 1 p.16/39

Assessment (2) Resit: The exam counts for 100 % of the total mark. 2 h exam, 4 questions, each worth 25 % The coursework does not count. G53CMP: Lecture 1 p.17/39

Assessment (3) Why this structure? G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. Thus, if you do and understand the coursework, you will be handsomely rewarded. G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. Thus, if you do and understand the coursework, you will be handsomely rewarded. Past experience shows that students who don t engage with the coursework struggle to pass. G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. Thus, if you do and understand the coursework, you will be handsomely rewarded. Past experience shows that students who don t engage with the coursework struggle to pass. 2013/14, half of the G53CMP students got 1st or II-1 marks... G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. Thus, if you do and understand the coursework, you will be handsomely rewarded. Past experience shows that students who don t engage with the coursework struggle to pass. 2013/14, half of the G53CMP students got 1st or II-1 marks... but a quarter failed. Clear correlation to coursework engagement. G53CMP: Lecture 1 p.18/39

Assessment (3) Why this structure? Compiler construction is best learnt by doing. Thus, if you do and understand the coursework, you will be handsomely rewarded. Past experience shows that students who don t engage with the coursework struggle to pass. 2013/14, half of the G53CMP students got 1st or II-1 marks... but a quarter failed. Clear correlation to coursework engagement. Numbers differ, but similar pattern most years. G53CMP: Lecture 1 p.18/39

Coursework (1) Learning goals: Getting a practical understanding of key concepts and techniques in the fields of compiler construction and language theory. G53CMP: Lecture 1 p.19/39

Coursework (1) Learning goals: Getting a practical understanding of key concepts and techniques in the fields of compiler construction and language theory. Getting hands-on experience of working with language processors. G53CMP: Lecture 1 p.19/39

Coursework (1) Learning goals: Getting a practical understanding of key concepts and techniques in the fields of compiler construction and language theory. Getting hands-on experience of working with language processors. Getting some experience of using compiler construction tools. G53CMP: Lecture 1 p.19/39

Coursework (1) Learning goals: Getting a practical understanding of key concepts and techniques in the fields of compiler construction and language theory. Getting hands-on experience of working with language processors. Getting some experience of using compiler construction tools. Getting experience of the issues involved in working with medium-sized programs. G53CMP: Lecture 1 p.19/39

Coursework (2) You will be given partial implementations of a compiler for a small language called MiniTrinagle. You will be asked to: G53CMP: Lecture 1 p.20/39

Coursework (2) You will be given partial implementations of a compiler for a small language called MiniTrinagle. You will be asked to: answer theoretical questions related to the code G53CMP: Lecture 1 p.20/39

Coursework (2) You will be given partial implementations of a compiler for a small language called MiniTrinagle. You will be asked to: answer theoretical questions related to the code extend the code with new features. G53CMP: Lecture 1 p.20/39

Coursework (2) You will be given partial implementations of a compiler for a small language called MiniTrinagle. You will be asked to: answer theoretical questions related to the code extend the code with new features. Detailed instructions for the coursework available (soon) from the module web page (Part I: 6 Oct.). G53CMP: Lecture 1 p.20/39

Coursework (2) You will be given partial implementations of a compiler for a small language called MiniTrinagle. You will be asked to: answer theoretical questions related to the code extend the code with new features. Detailed instructions for the coursework available (soon) from the module web page (Part I: 6 Oct.). Study these instructions very carefully! G53CMP: Lecture 1 p.20/39

Haskell and Coursework Support (1) The functional language Haskell is used throughout the module as: G53CMP: Lecture 1 p.21/39

Haskell and Coursework Support (1) The functional language Haskell is used throughout the module as: An ideal language for illustrating and discussing all aspects of compiler construction (and similar applications). G53CMP: Lecture 1 p.21/39

Haskell and Coursework Support (1) The functional language Haskell is used throughout the module as: An ideal language for illustrating and discussing all aspects of compiler construction (and similar applications). Functional language notation is closely aligned with mathematical notation and formalisms (such as attribute grammars) commonly used in text books on compilers. G53CMP: Lecture 1 p.21/39

Haskell and Coursework Support (1) The functional language Haskell is used throughout the module as: An ideal language for illustrating and discussing all aspects of compiler construction (and similar applications). Functional language notation is closely aligned with mathematical notation and formalisms (such as attribute grammars) commonly used in text books on compilers. A really good choice for implementing compilers in practice (and much else beside). G53CMP: Lecture 1 p.21/39

Haskell and Coursework Support (2) To help you get up to speed using Haskell and provide some extra help with the coursework: G53CMP: Lecture 1 p.22/39

Haskell and Coursework Support (2) To help you get up to speed using Haskell and provide some extra help with the coursework: Some of the lectures closely aligned with the coursework. G53CMP: Lecture 1 p.22/39

Haskell and Coursework Support (2) To help you get up to speed using Haskell and provide some extra help with the coursework: Some of the lectures closely aligned with the coursework. Haskell revision coursework (unassessed). G53CMP: Lecture 1 p.22/39

Haskell and Coursework Support (2) To help you get up to speed using Haskell and provide some extra help with the coursework: Some of the lectures closely aligned with the coursework. Haskell revision coursework (unassessed). Slides from a Haskell revision lecture via module web page. G53CMP: Lecture 1 p.22/39

Laboratory Sessions Laboratory sessions: Fridays, 9 11, A32 G53CMP: Lecture 1 p.23/39

Laboratory Sessions Laboratory sessions: Fridays, 9 11, A32 TAs will be present during the laboratory sessions from 7 October (except possibly 21 October). G53CMP: Lecture 1 p.23/39

Coursework Assessment (1) Two parts to the coursework: I and II G53CMP: Lecture 1 p.24/39

Coursework Assessment (1) Two parts to the coursework: I and II Each part to be solved individually G53CMP: Lecture 1 p.24/39

Coursework Assessment (1) Two parts to the coursework: I and II Each part to be solved individually Submission for each part: - Brief written report (hard copy & PDF) - All source code (electronically) G53CMP: Lecture 1 p.24/39

Coursework Assessment (1) Two parts to the coursework: I and II Each part to be solved individually Submission for each part: - Brief written report (hard copy & PDF) - All source code (electronically) For part II, compulsory 10 minute oral examination in assigned slot during one of the lab sessions after the submission deadline. G53CMP: Lecture 1 p.24/39

Coursework Assessment (1) Two parts to the coursework: I and II Each part to be solved individually Submission for each part: - Brief written report (hard copy & PDF) - All source code (electronically) For part II, compulsory 10 minute oral examination in assigned slot during one of the lab sessions after the submission deadline. Catch-up slots only if missed slot with good cause; personal tutor to request on your behalf. G53CMP: Lecture 1 p.24/39

Coursework Assessment (2) G53CMP: Lecture 1 p.25/39

Coursework Assessment (2) A number of weighted questions for each. part G53CMP: Lecture 1 p.25/39

Coursework Assessment (2) A number of weighted questions for each. part Written answer to each question assessed on - Correctness (0, 1, or 2 marks) - Style (0, 1, or 2 marks) G53CMP: Lecture 1 p.25/39

Coursework Assessment (2) A number of weighted questions for each. part Written answer to each question assessed on - Correctness (0, 1, or 2 marks) - Style (0, 1, or 2 marks) In the oral examination (part II only), you explain your answers. G53CMP: Lecture 1 p.25/39

Coursework Assessment (2) A number of weighted questions for each. part Written answer to each question assessed on - Correctness (0, 1, or 2 marks) - Style (0, 1, or 2 marks) In the oral examination (part II only), you explain your answers. Your explanations are assessed as follows: - 2: 100 % of mark for written answer - 1: 65 % of mark for written answer - 0: 0 % of mark for written answer G53CMP: Lecture 1 p.25/39

Coursework Deadlines Coursework deadlines: Part I: Monday 31 October, 15:00. Part II: Monday 28 November, 15:00. G53CMP: Lecture 1 p.26/39

Coursework Deadlines Coursework deadlines: Part I: Monday 31 October, 15:00. Part II: Monday 28 November, 15:00. Oral examinations during the lab sessions the following two Fridays; i.e. 2 and 9 December. G53CMP: Lecture 1 p.26/39

Coursework Deadlines Coursework deadlines: Part I: Monday 31 October, 15:00. Part II: Monday 28 November, 15:00. Oral examinations during the lab sessions the following two Fridays; i.e. 2 and 9 December. Start early! It is not possible to do this coursework at the last minute. G53CMP: Lecture 1 p.26/39

What is a Compiler? (1) Compilers are program translators: source program compiler target program error diagnostics Typical example: Source language: C Target language: x86 assembler G53CMP: Lecture 1 p.27/39

What is a Compiler? (1) Compilers are program translators: source program compiler target program error diagnostics Typical example: Source language: C Target language: x86 assembler Why? To make it easier to program computers! G53CMP: Lecture 1 p.27/39

What is a Compiler? (2) GCC translates this C program int main(int argc, char *argv) { printf("%d\n", argc - 1); } into this x86 assembly code (excerpt): movl decl subl pushl pushl call 8(%ebp), %eax %eax $8, %esp %eax $.LC0 printf addl $16, %esp G53CMP: Lecture 1 p.28/39

Source and Target Languages Large spectrum of possibilities, for example: Source languages: - (High-level) programming languages - Modelling languages - Document description languages - Database query languages G53CMP: Lecture 1 p.29/39

Source and Target Languages Large spectrum of possibilities, for example: Source languages: - (High-level) programming languages - Modelling languages - Document description languages - Database query languages Target languages: - High-level programming language - Low-level programming language (assembler or machine code, byte code) G53CMP: Lecture 1 p.29/39

Where are Compilers Used? (1) Implementation of programming languages: C, C++, Java, C#, Haskell, Lisp, Prolog, Ada, Fortran, Cobol,... G53CMP: Lecture 1 p.30/39

Where are Compilers Used? (1) Implementation of programming languages: C, C++, Java, C#, Haskell, Lisp, Prolog, Ada, Fortran, Cobol,... Document processing: LaTeX DVI, DVI PostScript/PDF/... G53CMP: Lecture 1 p.30/39

Where are Compilers Used? (1) Implementation of programming languages: C, C++, Java, C#, Haskell, Lisp, Prolog, Ada, Fortran, Cobol,... Document processing: LaTeX DVI, DVI PostScript/PDF/... Databases: optimization of database queries expressed in query languages like SQL. G53CMP: Lecture 1 p.30/39

Where are Compilers Used? (2) Hardware design: modelling and simulation/verification, compilation to silicon. E.g. Spice, VHDL. G53CMP: Lecture 1 p.31/39

Where are Compilers Used? (2) Hardware design: modelling and simulation/verification, compilation to silicon. E.g. Spice, VHDL. Modelling and simulation of physical systems (cars, trains, aircraft, nuclear power plants,... ): Simulink, Modelica. G53CMP: Lecture 1 p.31/39

Where are Compilers Used? (2) Hardware design: modelling and simulation/verification, compilation to silicon. E.g. Spice, VHDL. Modelling and simulation of physical systems (cars, trains, aircraft, nuclear power plants,... ): Simulink, Modelica. In Web browsers to speed up execution of code embedded in web pages, applets, Rich Internet Applications (RIA), etc. G53CMP: Lecture 1 p.31/39

Where are Compilers Used? (2) Hardware design: modelling and simulation/verification, compilation to silicon. E.g. Spice, VHDL. Modelling and simulation of physical systems (cars, trains, aircraft, nuclear power plants,... ): Simulink, Modelica. In Web browsers to speed up execution of code embedded in web pages, applets, Rich Internet Applications (RIA), etc.... G53CMP: Lecture 1 p.31/39

Compilers vs. Interpreters Interpreters are another class of translators: Compiler: translates a program once and for all into target language. G53CMP: Lecture 1 p.32/39

Compilers vs. Interpreters Interpreters are another class of translators: Compiler: translates a program once and for all into target language. Interpreter: effectively translates (the used parts of) a source program every time it is run. G53CMP: Lecture 1 p.32/39

Compilers vs. Interpreters Interpreters are another class of translators: Compiler: translates a program once and for all into target language. Interpreter: effectively translates (the used parts of) a source program every time it is run. Techniques like Just-In-Time Compilation (JIT) blurs this distinction. G53CMP: Lecture 1 p.32/39

Compilers vs. Interpreters Interpreters are another class of translators: Compiler: translates a program once and for all into target language. Interpreter: effectively translates (the used parts of) a source program every time it is run. Techniques like Just-In-Time Compilation (JIT) blurs this distinction. Compilers and interpreters sometimes used together, e.g. Java: Java compiled into Java byte code, byte code interpreted by a Java Virtual Machine (JVM), JVM might use JIT. G53CMP: Lecture 1 p.32/39

Inside the Compiler (1) Traditionally, a compiler is broken down into several phases: Scanner: lexical analysis Parser: syntactic analysis Checker: contextual analysys (e.g. type checking) Optimizer: code improvement Code generator G53CMP: Lecture 1 p.33/39

Inside the Compiler (2) Lexical Analysis: G53CMP: Lecture 1 p.34/39

Inside the Compiler (2) Lexical Analysis: - Verify that input character sequence is lexically valid. G53CMP: Lecture 1 p.34/39

Inside the Compiler (2) Lexical Analysis: - Verify that input character sequence is lexically valid. - Group characters into sequence of lexical symbols, tokens. G53CMP: Lecture 1 p.34/39

Inside the Compiler (2) Lexical Analysis: - Verify that input character sequence is lexically valid. - Group characters into sequence of lexical symbols, tokens. - Discard white space and comments (typically). G53CMP: Lecture 1 p.34/39

Inside the Compiler (3) Syntactic Analysis/Parsing G53CMP: Lecture 1 p.35/39

Inside the Compiler (3) Syntactic Analysis/Parsing - Verify that the input program is syntactically valid, i.e. conforms to the Context Free Grammar of the language. G53CMP: Lecture 1 p.35/39

Inside the Compiler (3) Syntactic Analysis/Parsing - Verify that the input program is syntactically valid, i.e. conforms to the Context Free Grammar of the language. - Determine the program structure. G53CMP: Lecture 1 p.35/39

Inside the Compiler (3) Syntactic Analysis/Parsing - Verify that the input program is syntactically valid, i.e. conforms to the Context Free Grammar of the language. - Determine the program structure. - Construct a representation of the program reflecting that structure without unnecessary details, usually an Abstract Syntax Tree (AST). G53CMP: Lecture 1 p.35/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. - Report undefined symbols. G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. - Report undefined symbols. - Type checking. -... G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. - Report undefined symbols. - Type checking. -... Optimization: G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. - Report undefined symbols. - Type checking. -... Optimization: - Code improvements aiming at making it run faster and/or use less space, energy, etc. G53CMP: Lecture 1 p.36/39

Inside the Compiler (4) Contextual Analysis/Checking Static Semantics: - Resolve meaning of symbols. - Report undefined symbols. - Type checking. -... Optimization: - Code improvements aiming at making it run faster and/or use less space, energy, etc. - Almost always heuristics: cannot guarantee optimal result. G53CMP: Lecture 1 p.36/39

Inside the Compiler (5) Code Generation: G53CMP: Lecture 1 p.37/39

Inside the Compiler (5) Code Generation: - Output the appropriate sequence of target language instructions. G53CMP: Lecture 1 p.37/39

Inside the Compiler (5) Code Generation: - Output the appropriate sequence of target language instructions. - Might involve further low-level (target-specific) optimization. G53CMP: Lecture 1 p.37/39

Inside the Compiler (6) sequence of characters scanner Lexical Analysis sequence of tokens parser Syntactic Analysis/Parsing Abstract Syntax Tree (AST) checker Contextual Analysis/checking Static Semantics (e.g. Type Checking) Intermediate Representation (IR), e.g. verified/annotated AST optimizer/ code generator Optimization and Code Generation (possibly many steps involving a number of intermediary representations) target code G53CMP: Lecture 1 p.38/39

Inside the Compiler (7) Front end: Scanner, Parser, Contextual checker. Depends more heavily on the source language. G53CMP: Lecture 1 p.39/39

Inside the Compiler (7) Front end: Scanner, Parser, Contextual checker. Depends more heavily on the source language. Middle section ( Middle end ): Optimizer. Operates on an Intermediary Representation (IR) that could be fairly independent of source and target language. Hence potentially reusable! G53CMP: Lecture 1 p.39/39

Inside the Compiler (7) Front end: Scanner, Parser, Contextual checker. Depends more heavily on the source language. Middle section ( Middle end ): Optimizer. Operates on an Intermediary Representation (IR) that could be fairly independent of source and target language. Hence potentially reusable! Back end: Code Generator Depends heavily on the target language. G53CMP: Lecture 1 p.39/39