Introduction To Compiler Design-Unit I
Introduction To Compiler Design-Unit I
INTRODUCTION
Introduction to Compiler:
⚫Programming languages are notations for
describing computations to people and to
machines. The world as we know it depends on
programming languages, because all the
software running on all the computers was
written in some programming language. But,
before a program can be run, it first must be
translated into a form in which it can be
executed by a computer.
⚫The software systems that do this translation
are called compilers.
Language Processor
a compiler is a program that can read a program in one
language | the source language | and translate it into an
equivalent program in another language | the target
language
⚫If the target program is an executable machine-language
program, it can then be called by the user to process inputs
and produce outputs
t2 = id3 * t1
t1 = id3 * 60.0 t3 = id2 + t2
id1 = id2 + t1 id1 = t3
6. Code Generation
⚫The code generator takes as input an intermediate representation
of the source program and maps it into the target language.
⚫If the target language is machine code, registers or memory
locations are selected for each of the variables used by the
program.
⚫A crucial aspect of code generation is the judicious assignment
of registers to hold variables.
LDF R2, id3
MULF R2, R2, #60.0
LDF R1, id2
ADDF R1, R1, R2
STF id1, R1
⚫The F in each instruction tells us that it deals with oating-
point numbers.
⚫LD-Loads
⚫MUL-Multiply
⚫ADD-Addition
⚫ST-Store
⚫ Since the lexical analyzer is the part of the compiler that reads the source
text, it may perform certain other tasks besides identification of lexemes.
⚫ One such task is stripping out comments and whitespace (blank, newline,
tab, and perhaps other characters that are used to separate tokens in the
input).
lexical analyzers are divided into a cascade of two
processes:
E = M * C**2
⚫ are written below as a sequence of pairs.
D) Lexical Errors
⚫ It is hard for a lexical analyzer to tell, without the aid of other
components, that there is a source-code error.
⚫ For instance, if the string fi is encountered for the first time in a C
program in the context:
fi ( a == f(x)) ...
⚫ A lexical analyzer cannot tell whether fi is a misspelling of the
keyword if or an undeclared function identifier.
⚫ Other possible error-recovery actions are:
a) Delete one character from the remaining input.
b) Insert a missing character into the remaining input.
c) Replace a character by another character.
d) Transpose two adjacent characters.
THANK YOU