0% found this document useful (0 votes)
33 views

Compiler Lecture 1

This document discusses an introduction to compiler design course. It covers the aims of the course, which are to introduce students to the principles and techniques of translating programs from one language to another. It also outlines the learning outcomes and topics that will be covered in the course.

Uploaded by

mnielsonc
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Compiler Lecture 1

This document discusses an introduction to compiler design course. It covers the aims of the course, which are to introduce students to the principles and techniques of translating programs from one language to another. It also outlines the learning outcomes and topics that will be covered in the course.

Uploaded by

mnielsonc
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

CSE 359 - Compiler Design

Lecture 1: Introduction
• Aims:
– Any program written in a programming language must
be translated before it can be executed.
– This translation is typically accomplished by a
software system called compiler.
– This course aims to introduce students to the principles
and techniques used to perform this translation and
the issues that arise in the construction of a compiler.

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 1


Design
Learning Outcomes:
 A student successfully completing this course should be able
to:
 understand the principles governing all phases of the
compilation process.
 understand the role of each of the basic components of a
standard compiler.
 show awareness of the problems of and methods and
techniques applied to each phase of the compilation process.
 apply standard techniques to solve basic problems that arise in
compiler construction.
 understand how the compiler can take advantage of particular
processor characteristics to generate good code.

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 2


Design
Course Texts

• Aho, Lam, Sethi, Ullman. “Compilers: Principles, Techniques and


Tools”, 2nd edition. (Aho2) The 1st edition (by Aho, Sethi, Ullman –
Aho1), the “Dragon Book”, has been a classic for over 20 years.

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 3


Design
Syllabus
Introduction to compilers: Introductory concepts, types of compilers,
applications, phases of a compiler.
Lexical analysis: Role of the lexical analyzer, input buffering, token
specification, recognition of tokens, symbol tables.
Parsing: Parser and its role, context free grammars, top-down parsing.
Syntax-directed translation: Syntax-directed definitions, construction of syntax
trees, top-down translation.
Type checking: Type systems, type expressions, static and dynamic checking of
types, error recovery.
Run-time organization: Run-time storage organization, storage strategies.
Intermediate code generation: Intermediate languages, declarations, assignment
statements.
Code optimization: Basic concepts of code optimization, principal sources of
optimization.
Code generation.
Features of some common compilers: Characteristic features of C, Pascal and
Fortran compilers.
CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 4
Design
CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 5
Design
Definitions Source program
compiler

What is a compiler? Target program


 A program that accepts as input a program text in a certain
language and produces as output a program text in another
language, while preserving the meaning of that text (Grune et al,
2000).
 A program that reads a program written in one language (source
language) and translates it into an equivalent program in another
language (target language) (Aho et al)
What is an interpreter?
 A program that reads a source program and produces the results of
executing this source.

We deal with compilers! Many of these issues arise with interpreters!

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 6


Design
CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 7
Design
Examples
• C is typically compiled
• Lisp is typically interpreted
• Java is compiled to bytecodes, which are then
interpreted
Also:
• C++ to Intel Core 2/.../Assembly
• C++ to C
• High Performance Fortran (HPF) to Fortran (parallelising
compiler)
• C to C (or any language to itself)

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 8


Design
Qualities of a Good Compiler
What qualities would you want in a compiler?
– generates correct code (first and foremost!)
– generates fast code
– conforms to the specifications of the input language
– copes with essentially arbitrary input size, variables, etc.
– compilation time (linearly) proportional to size of source
– good diagnostics
– consistent optimisations
– works well with the debugger

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 9


Design
Principles of Compilation
The compiler must:
• preserve the meaning of the program being compiled.
• “improve” the source code in some way.
Other issues (depending on the setting):
• Speed (of compiled code)
• Space (size of compiled code)
• Feedback (information provided to the user)
• Debugging (transformations obscure the relationship source
code vs target)
• Compilation time efficiency (fast or slow compiler?)

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 10


Design
Why study Compilation Technology?
• Success stories (one of the earliest branches in CS)
– Applying theory to practice (scanning, parsing, static analysis)
– Many practical applications have embedded languages (eg, tags)
• Practical algorithmic & engineering issues:
– Approximating really hard (and interesting!) problems
– Emphasis on efficiency and scalability
– Small issues can be important!
• Ideas from different parts of computer science are involved:
• AI: Heuristic search techniques; greedy algorithms - Algorithms: graph
algorithms - Theory: pattern matching - Also: Systems, Architecture
• Compiler construction can be challenging and fun:
– new architectures always create new challenges; success requires
mastery of complex interactions; results are useful; opportunity to
achieve performance.
CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 11
Design
Uses of Compiler Technology
• Most common use: translate a high-level program to object code
– Program Translation: binary translation, hardware synthesis, …
• Optimizations for computer architectures:
– Improve program performance, take into account hardware parallelism, etc…
• Automatic parallelisation or vectorisation
• Performance instrumentation: e.g., -pg option of cc or gcc
• Interpreters: e.g., Python, Ruby, Perl, Matlab, sh, …
• Software productivity tools
– Debugging aids: e.g, purify
• Security: Java VM uses compiler analysis to prove “safety” of Java
code.
• Text formatters, just-in-time compilation for Java, power
management, global distributed computing, …
Key: Ability to extract properties of a source program (analysis) and
transform it to construct a target program (synthesis)
CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 12
Design
Summary
• A compiler is a program that converts some input
text in a source language to output in a target
language.
• Compiler construction poses some of the most
challenging problems in computer science.

• Next lecture: structure of a typical compiler.

CSE 359 - Compiler Masud Ibn Afjal, CSE, HSTU 13


Design

You might also like