CA Compiler Construction

Similar documents
Formal Languages and Compilers Lecture I: Introduction to Compilers

Compiler Construction LECTURE # 1

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Compilers Crash Course

A simple syntax-directed

Compiler Design Overview. Compiler Design 1

Compiler Design (40-414)

Compiling Techniques

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

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

Compilers and Code Optimization EDOARDO FUSELLA

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

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

A Simple Syntax-Directed Translator

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

CA Compiler Construction

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

Compiler Construction D7011E

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

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

Introduction to Compiler

COSE312: Compilers. Lecture 1 Overview of Compilers

Undergraduate Compilers in a Day

Error Recovery during Top-Down Parsing: Acceptable-sets derived from continuation

MANIPAL INSTITUTE OF TECHNOLOGY (Constituent Institute of MANIPAL University) MANIPAL

Compiler Construction

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

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

Compiler Construction 1. Introduction. Oscar Nierstrasz

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

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

CPSC 411: Introduction to Compiler Construction

Compiler Construction 1. Introduction. Oscar Nierstrasz

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

LEXIMET: A Lexical Analyzer Generator including McCabe's Metrics.

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

CS 132 Compiler Construction

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

Compiling Regular Expressions COMP360

Application Specific Signal Processors S

Parsing and Pattern Recognition

Compiler Construction

CS 352: Compilers: Principles and Practice

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

CS426 Compiler Construction Fall 2006

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

General Course Information. Catalogue Description. Objectives

Programming Language Processor Theory

tokens parser 1. postfix notation, 2. graphical representation (such as syntax tree or dag), 3. three address code

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

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

Front End. Hwansoo Han

Quick Parser Development Using Modified Compilers and Generated Syntax Rules

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

Modern Compiler Design: An approach to make Compiler Design a Significant Study for Students

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

Introduction to Compiler Design

Compilers. Pierre Geurts

CS131: Programming Languages and Compilers. Spring 2017

ST. XAVIER S COLLEGE

Working of the Compilers

Lexical Analysis. Introduction

Compiler Construction 2010 (6 credits)

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

Compiler Theory. (Semantic Analysis and Run-Time Environments)

High-level View of a Compiler

COMP3131/9102: Programming Languages and Compilers

Evaluation of Semantic Actions in Predictive Non- Recursive Parsing

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Chapter 4. Abstract Syntax

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

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

An Overview of Compilation

CPS 506 Comparative Programming Languages. Syntax Specification

The role of semantic analysis in a compiler

Compilers and computer architecture: introduction

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

CST-402(T): Language Processors

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

LECTURE 3. Compiler Phases

A Java Based 4th Generation Multi-Targeted User Interface Compiler (JUICE)

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Introduction to Compiler Construction

Compilers. Lecture 2 Overview. (original slides by Sam

Syntax and Grammars 1 / 21

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Compiler Construction

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

Lecture Notes on Alias Analysis

UNIT -2 LEXICAL ANALYSIS

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00

INF5110 Compiler Construction

Garbage Collection. Weiyuan Li

Compilers for Modern Architectures Course Syllabus, Spring 2015

Name of chapter & details

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev

Intermediate Representations

Read & Download (PDF Kindle) Modern Compiler Implementation In ML

Compiler Construction

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 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 locations 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.