Stage 2: Implementation Issues
Stage 2: Implementation Issues
Implementation Issues
Symbol Table (ST)
Each variable identifier find space in the ST
Major information collected during front end
compilation
Type
Width
Offset
Scope (visibility) of variables is implemented as
hierarchical symbol tables
As each lexeme is checked once, the ST data
structure is expected to be of O(1) time
complexity
CS F363/IS F342 Implementation
March 25, 2014 2
issues
Scope
• The scope is defined as the nested function.
• A function scope can be implemented as a
separate hash table.
• In order to support semantic checks such as
function overloading, the names of the
function identifiers are used as hashing keys
while accessing the symbol table
corresponding to the function scope.
T.type=integer
T L
L.in=integer
int L , id
L.in=integer
addtype(id.entry,L.in)
id
Symbol table is updated for both tokens ‘id’ with type of these as integers
exp
exp.t=BOOL
exp == exp
exp.t=INT exp.t=INT
( exp )
exp.t=INT 4
exp + exp
exp.t=INT exp.t=INT annotated Parse Tree
Parse Tree
2 2
2. exp -> exp and exp if ((exp2.t == BOOL) and (exp3.t ==BOOL)
then exp1.t = BOOL
else exp1.t = ERROR
_main[]
int a;
a integer
real b; b real
a = 5;
a = a + b;
print(a);
end;
Symbol table
Symbol table
D D
SA SA SI
Construct
Type: Construct
Type:
integer
VAR1 Expression,
real
MUL
Construct
Type:
Construct
Type:
VAR1
real
VAR1
real
Type:
ID
integer
Type: Type:
ID
CS F363/IS F342 Implementation real ID
March 25, 2014
issues
real 12
Matrix
_main[]
matrix mat1, mat2;
mat1 = [1,2, 3; 4, 5, 6; 6, 7, 8];
mat2 = [-6, -1, 10; 6, -10, 0];
m = mat1 + mat2;
print(a);
end;
<row>
NUM <remainingColElements>
COUNT
mat1 matrix
SIZE:
bottom COMMA NUM <remainingColElements>
up
COMMA NUM <remainingColElements>
CS F363/IS F342 Implementation
March 25, 2014 15
issues
mat1 = [1,2, 3; 4, 5, 6; 6, 7, 8];
ASSIGNOP
<matrix> COL = 3
ROW = 3
<row>
NUM <remainingColElements>
COUNT
mat1 matrix
SIZE:
<matrix, 3,3> bottom COMMA NUM <remainingColElements>
up
COMMA NUM <remainingColElements>
CS F363/IS F342 Implementation
March 25, 2014 16
issues
Matrix
_main[]
matrix mat1, mat2;
mat1 = [1,2, 3; 4, 5, 6; 6, 7, 8];
mat2 = [-6, -1, 10; 6, -10, 0];
m = mat1 + mat2;
print(a);
end;