Professional Documents
Culture Documents
I. Symbol Table:
Symbol Table is a data structure created and maintained by the compiler. It represent
data in tabular form. It stores information about the scope and binding information
about names, information about instances of various entities such as variable and
function names, classes, objects.
a. Symbol Table:
Lexical Syntax Semantic Intermediate Code Target Code
Analyzer: Analyzer: Analyzer: Code Optimization: generation:
generation:
Creates new Adds Uses Refers Uses Generates
table entries information available symbol table information code by using
in the table. regarding information for knowing present in the address
i.e. like attribute in the table how much symbol table information
entries about type, scope, to check for and what for machine- of identifier
tokens. dimension, semantics i.e. type of run- dependent present in
line of to verify that time is optimization. the table.
reference, expressions allocated and
use, etc in and table helps in
the table. assignments adding
are temporary
semantically variable
correct(type information.
checking)
and update it
accordingly.
b. Interpret the given statement from all the phases of compiler and mention
output of each phase after passes through it phases.
Symbol Table:
E -> T = E/T
T -> T + F/F
F -> F – G/G
G -> G/D /D
D -> D/L
L -> a/b/5/c/d/id
Result = (a - b) + (c / d) + 5
Lexical Analysis:
Id = (id – id) + (id / id) + 5
Syntax Analysis:
E -> T = T
=> T + F
=> T + F + F
=> F + G + G
=> F - G + G/D + D
=> G - G + D/D + L
=> D - D + L/L + 5
=> L - L + c/d + 5
=> id - id + id/id + 5
Result = (a - b) + (c / d) + 5
E
T = T
T + F
T + F G
F G D
F - G G D L
/
G
D D L id
D L L id
L id id
id
Semantic Analysis:
Id1 +
- / inttoreal
Code Optimization:
x = (id4 / id5) + 5
z = x + (id2 – id3)
a. Interpret the given statement from all the phases of compiler and mention output of
each phase after passes through it phases.