CA4003 - Compiler Construction



Similar documents
Language Processing Systems

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Compiler Construction

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

03 - Lexical Analysis

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Lecture 9. Semantic Analysis Scoping and Symbol Table

CSCI 3136 Principles of Programming Languages

Compiler Construction

Compiler I: Syntax Analysis Human Thought

Programming Languages CIS 443

A Typing System for an Optimizing Multiple-Backend Tcl Compiler

Semester Review. CSC 301, Fall 2015

Flex/Bison Tutorial. Aaron Myles Landwehr CAPSL 2/17/2012

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

2) Write in detail the issues in the design of code generator.

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Programming Languages

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Securing PHP Based Web Application Using Vulnerability Injection

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

CS / IT B.E. VII Semester Examination, December 2013 Cloud Computing Time : Three Hours Maximum Marks : 70

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

Program Optimization for Multi-core Architectures

Semantic Analysis: Types and Type Checking

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

C Compiler Targeting the Java Virtual Machine

Programming Languages

How Compilers Work. by Walter Bright. Digital Mars

Performance Analysis and Optimization on Lucene

Chapter 6: Programming Languages

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Compilers I - Chapter 4: Generating Better Code

Instruction Set Architecture (ISA)

1/20/2016 INTRODUCTION

Artificial Intelligence. Class: 3 rd

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Antlr ANother TutoRiaL

Programming Languages

Programming Assignment II Due Date: See online CISC 672 schedule Individual Assignment

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Automatic Text Analysis Using Drupal

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

In-Memory Database: Query Optimisation. S S Kausik ( ) Aamod Kore ( ) Mehul Goyal ( ) Nisheeth Lahoti ( )

Architectural Design Patterns for Language Parsers

Compilers. Presentation. Lecture 0. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.es

Compiler Compiler Tutorial

Introduction to Java

Programming Project 1: Lexical Analyzer (Scanner)

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Optimizing compilers. CS Modern Compilers: Theory and Practise. Optimization. Compiler structure. Overview of different optimizations

Module: Software Instruction Scheduling Part I

FTP client Selection and Programming

OAMulator. Online One Address Machine emulator and OAMPL compiler.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Programming Language Pragmatics

CSE 401 Compilers. Overview and Administrivia Hal Perkins Winter UW CSE 401 Winter 2015 A-1

Compiler Design July 2004

Chapter 2: Elements of Java

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Java CPD (I) Frans Coenen Department of Computer Science

Compila(on for the composi(on of so2ware protec(ons for embedded systems

International Journal of Scientific & Engineering Research, Volume 4, Issue 11, November ISSN

Natural Language to Relational Query by Using Parsing Compiler

Objects for lexical analysis

Syntaktická analýza. Ján Šturc. Zima 208

Optimization of SQL Queries in Main-Memory Databases

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Detection of DOM-based Cross-Site Scripting by Analyzing Dynamically Extracted Scripts

Briki: a Flexible Java Compiler

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

University of Wales Swansea. Department of Computer Science. Compilers. Course notes for module CS 218

Departamento de Investigación. LaST: Language Study Tool. Nº 143 Edgard Lindner y Enrique Molinari Coordinación: Graciela Matich

Sources: On the Web: Slides will be available on:

Technical paper review. Program visualization and explanation for novice C programmers by Matthew Heinsen Egan and Chris McDonald.

CIS570 Modern Programming Language Implementation. Office hours: TDB 605 Levine

The C Programming Language course syllabus associate level

MieruCompiler: Integrated Visualization Tool with Horizontal Slicing for Educational Compilers

6.170 Tutorial 3 - Ruby Basics

28 Application Architectures

Explain the relationship between a class and an object. Which is general and which is specific?

Compilers Lexical Analysis

Acknowledgements. In the name of Allah, the Merciful, the Compassionate

The programming language C. sws1 1

Context free grammars and predictive parsing

A Programming Language Where the Syntax and Semantics Are Mutable at Runtime

Lecture 1: Introduction

SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE

Symbol Tables. Introduction


Computer Science 217

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

Recovering Business Rules from Legacy Source Code for System Modernization

Transcription:

CA4003 - Compiler Construction David Sinclair Overview This module will cover the compilation process, reading and parsing a structured language, storing it in an appropriate data structure, analysing the data structure and generating an executable program. In this module we will cover: Structure of a compiler Lexical analysis Parsing Abstract syntax Semantic Analysis Intermediate Code Generation Register Allocation & Code Optimisation Run-time Environments Code Generation

Overview [2] The obvious application of these techniques will be in compiling a high-level computer program into an executable program. However these techniques can also be used to process and analyse any structured data. Texts Essential: Andrew W. Appel, Modern Compiler Implementation in Java, Cambridge University Press, 1998, ISBN 0-521-58388-8 Supplementary: Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers: Principles, Techniques and Tools, 2 nd Edition, Addison-Wesley, 2007, ISBN 0-321-49169-6

Contact Details Lecturer: David Sinclair Office: L253 Phone: 5510 Email: David.Sinclair@computing.dcu.ie WWW: http://www.computing.dcu.ie/ davids Course web page: http://www.computing.dcu.ie/ davids/ca4003/ca4003.html How do I successfully complete this module? The module mark is a straight weighted average of: 30% continuous assessment 2 assignments first assignment: Front-end - lexical, syntax analysis (15%) second assignment: Back-end - sematic analysis and generating intermediate code (15%) 70% end-of-semester examination 10 questions. Do all questions.

Compiler and Interpreters What is a compiler? It is a program that translates an executable program in one language into an executable program in another language. What is an interpreter? It is a program that reads an executable program and produces the results of running that program. This typically involves executing (or evaluating) the source program. Many of the same front-end issues arise in interpreters and compilers. Overview of the Compilation Process The compilation process consists of a number of phases. The number of phases varies from compiler to compiler depending on their complexity. A basic set of phases are: Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Code Generation Code Optimisation Code Generation The first 3 phases comprise the front-end of the compiler. The second 3 phases comprise the back-end of the compiler.

Lexical Analysis The goal of lexical analysis is to convert a stream of characters from the source program into stream of tokens that represent recognised keywords, identifiers, numbers and punctuation. Some tokens, such as identifiers and numbers, require an additional quantity, called a lexeme, that indicates the type and/or value of the token. answer = x 2 y id(answer), =, id(x),, num(2), -, id(y) Syntax Analysis The goal of the syntax analysis is to combine the tokens generated by the lexical analysis into a valid sentence. A grammar is a set of rules that specifies how the tokens can be combined. Let s assume the following grammar. goal assignment exp assignment id = exp exp id num mul add subtract mul exp * exp add exp + exp subtract exp - exp The above grammar is very flawed. We will see why later in the course.

Syntax Analysis [2] Parse Tree goal Abstract Syntax Tree (AST) assignment assignment <id:answer > = exp <id:answer > mul subtract <id:y > exp subtract - exp <id:x > <num:2> exp mul * exp <id:y > <id:x > <num:2> The Abstract Syntax Tree (AST) is a compressed version of the Parse Tree, but without the redundant information. Semantic Analysis In a compiler this phase checks the source program for semantic errors, and gathers type information for the intermediate code generation phase. For example, what if answer and y are integer and x is a float? In an interpreter this phase evaluates the source program stored in the AST.

Intermediate Code Generation Intermediate code is a kind of abstract machine code. which does not rely on a particular target machine by specifying the registers or memory locations to be used for each operation. This separates compilation into a mostly language dependent front end, and a mostly machine-dependent back end. For example: loop: JLE x 0 end SUB x 1 temp MOV temp x JMP loop end:... Code Optimisation This is an optional phase which can be used to improve the improve the intermediate code to make it run faster and/or use less memory. For example, the variable temp in the previous fragment of intermediate code is not required. This can be removed to give the following: loop: JLE x 0 end SUB x 1 x JMP loop end:...

Code Generation This phase translates intermediate code into object code, allocating memory allocations for data, and selecting registers. This can also include a linking phase when the language allows the source code to be written in separate files.