Spos Unit 2 PPT 2022 Compressed
Spos Unit 2 PPT 2022 Compressed
Spos Unit 2 PPT 2022 Compressed
in assembly language.
•The macro begins with the %macro directive and ends with
the
MACRO DEFINITION
The Syntax for macro definition −
%macro macro_name number_of_params
<macro body>
%endmacro
FEATURES OF MACROPROCESSOR
1. Macro represents a group of commonly used statements in the source
programming language.
Sourc Target
Compile
e Progra
r
Progra m
m
Error Outpu 3
message t
s
Phases of Compiler
ANALYSIS–
SYNTHESIS
MODE
L
5
8
3/17/2019 PROF. ANAND GHARU
Example : https://youtu.be/P1bQUyl__t0
PHASESOFCOMPILE
R
58
59
Lexical analyzer phase is the first phase of compilation process. It takes source
code as input. It reads the source program one character at a time and converts it
into meaningful lexemes. Lexical analyzer represents these lexemes in the form
of tokens.
• Syntax Analysis :
In the intermediate code generation, compiler generates the source code into the
intermediate code. Intermediate code is generated between the high-level
language and the machine language. The intermediate code should be generated
in such a way that you can easily translate it into the target machine code.
3/17/2019 PROF. ANAND GHARU
Phases of Compiler
• Code Optimization :
• Code Generation :
Code generation is the final stage of the compilation process. It takes the
optimized intermediate code as input and maps it to the target machine
language. Code generator translates the intermediate code into the machine code
of the specified computer.
3/17/2019 PROF. ANAND GHARU
Example :
3/17/2019
Types of Compiler
1. Cross Compilers
They produce an executable machine code for a platform but, this platform
is not the one on which the compiler is running.
2. Bootstrap Compilers
The process of writing a compiler (or Assembler) in the target
programming language which has to be compiled is known as
"Bootstrapping“
3. Source to source/transcompiler
These compilers convert the source code of one programming language
to the source code of another programming language.
Types of Compiler
4. Incremental compiler :
Incremental Compiler is a compiler, which performs the recompilation
of only modified source rather than compiling the whole source program
Decompiler
Basically, it is not a compiler. It is just the reverse of the compiler.
It converts the machine code into high-level language.
ISSUES IN
COMPILATION
Hierarchy of operations need to be maintained to
determine correct order of expressionevaluation
7
3
3/17/2019 PROF. ANAND GHARU
ISSUES IN
COMPILATION
Resolve occurrence of each variable name in a program
i.e construct separate symbol tables for different
namespaces.
Perform optimization
74
4
0
3/17/2019 PROF. ANAND GHARU
INTERPRTER
S
• rpretation”
“Inte
– Performing the operations implied by
the source program
Source
Progra
m Interpreter Outpu
Input t
Error Messages
8
1
3/17/2019 PROF. ANAND GHARU
Position of a Parser in
the Compiler Model
Token,
tokenva
Source l Parser Intermediate
Lexical
Progra and rest representatio
Analyze
m Get of front- n
r
next end
token
Lexical Syntax error
error Semantic
error
Symbol Table
Position of a Parser in
the Compiler Model
The Role Of Parser
• A parser implements a C-F grammar
• The role of the parser is two fold:
1. To check syntax (= string recognizer)
– And to report syntax errors accurately
2. To invoke semantic actions
– For static semantics checking, e.g. type checking
of expressions, functions, etc.
– For syntax-directed translation of the source code to an
intermediate representation
The Role Of Parser
1.It verifies the structure generated by the tokens based
on the grammar.
2. It constructs the parse tree.
3. It reports the errors.
4. It performs error recovery.
Issues :
Parser cannot detect errors such as:
5. Variable re-declaration
6. Variable initialization before use
7. Data type mismatch for an operation.
The above issues are handled by Semantic Analysis
phase.
The Role Of Parser
Syntax error handling :
Programs can contain errors at many different levels. For
example :
1. Lexical, such as misspelling an identifier, keyword or
operator.
2.Syntactic, such as an arithmetic expression with
unbalanced parentheses.
3.Semantic, such as an operator applied to an
incompatible operand.
4. Logical, such as an infinitely recursive call.
The Role Of Parser
Functions of error handler :
1. It should report the presence of errors clearly and
accurately.
2.It should recover from each error quickly enough to be
able to detect subsequent errors.
3.It should not significantly slow down the processing of
correct programs.
TYPES OF
ERRORS
A parser should be able to detect and report any error in the
program. It is expected that when an error is encountered, the
parser should be able to handle it and carry on parsing the rest
of the input. Mostly it is expected from the parser to check
for errors but errors may be encountered at various stages of
the compilation process. A program may have the
following kinds of errors at various stages:
4
4
3/17/2019 PROF. ANAND GHARU