Lecture No.1: Compiler Construction
Lecture No.1: Compiler Construction
1
COMPILER CONSTRUCTION.
Table of contents
Why Study Compilers
Introduction of language processing system
Preprocessor
Compilers
Properties of compilers
Assembler
Interpreter
Linker
Loader
The Context of a Compiler
Assignment
Why Study Compilers
Reason #1: understand compilers and languages.
Understand the code structure.
Understand language semantics.
Understand relation between source code and generated machine code.
Allow to become a better programmer and increase programmer productivity and increase portability
Reason #2: nice balance of theory and practice.
Theory:
Mathematical models: regular expressions, automata, grammars, graphs.
Algorithms that use these models.
Practice:
Apply theoretical notions to build a real compiler.
Reason #3: programming experience.
Creating a compiler entails writing a large computer program which manipulates complex data structures and
implement sophisticated algorithm
Increasing programming capability
Introduction of language processing
system
Preprocessor
A preprocessor produce input to compilers. They may perform the following
functions.
Macro processing: A preprocessor may allow a user to define macros that are short
hands for longer constructs.
1. File inclusion: A preprocessor may include header files into the program text.
2. Rational preprocessor: these preprocessors augment older languages with
more modern flow-of control and data structuring facilities.
3. Language Extensions: These preprocessor attempts to add capabilities to the
language by certain amounts to build-in macro.
Compilers
A Compiler is a program (system software) that reads a program written in one
language – the source language – and translates it into an equivalent program in
another language – the target language.
During translation process, the compiler reports to its user the presence of errors
in the source program.
Compilers
Source language can be any high level computer programming language ranging
from traditional programming language such as Fortran, C, Java etc to specialized
language that have been written for a specific area of computer application such
as LISP for AI etc.
Target language may be another programming language (assembly language) or
the machine language of a computer, depending upon the compiler. High High--
level source code level source code
Compilation Process
It takes the whole program at a time and either displays all of the possible errors
in the program or creates an object program.
The time at which the conversion of a source program to an object program
occurs is called compile time.
The object program is executed at run time.
Properties of compilers
The compiler creates the assembly code that is translated by an assembler into
machine code.
The linker together the machine code with some library routines into the code that
actually run on the machine.
Analysis and Synthesis Model
Analysis part breaks the source program into constituent pieces and imposes a
grammatical structure on them which further uses this structure to create an
intermediate representation of the source program
It is also termed as front end of compiler
Information about the source program is collected and stored in a data structure
called symbol table
Synthesis part
Synthesis part takes the intermediate representation as input and transforms it to
the target program
It is also termed as back end of compiler
Analysis and Synthesis Model
ASSIGNMENT NO .1