Compiler Design Unit 4
Compiler Design Unit 4
void pro_one()
void pro_two()
{
{
int one_1;
int two_1;
int one_2;
int two_2;
{
{
int one_3;
int two_3;
int one_4;
int two_4;
}
}
int one_5;
int two_5;
{
{
int one_6;
int two_6;
int one_7;
int two_7;
}
}
}
}
Symbol Table:
Scope Management
To determine the scope of a name, symbol tables are arranged in
hierarchical structure as shown in the example below:
Symbol Table:
Representing Scope Information
In the source program, every name possesses a region of validity, called
the scope of that name.
The rules in a block-structured language are as follows:
1.If a name declared within block B then it will be valid only within B.
2.If B1 block is nested within B2 then the name that is valid for block B2 is
also valid for B1 unless the name's identifier is re-declared in B1.
3.Tables are organized into stack and each table contains the list of names
and their associated attributes.
4.Whenever a new block is entered then a new table is entered onto the
stack. The new table holds the name that is declared as local to this block.
5.When the declaration is compiled then the table is searched for a name.
6.If the name is not found in the table then the new name is inserted.
7.When the name's reference is translated then each table is searched,
starting from the each table on the stack.
Symbol Table:
Storage organization
•When the target program executes Subdivision of Run-time Memory:
then it runs in its own logical address
space in which the value of each
program has a location.
•The drawback with static storage allocation is that the size and
position of data objects should be known at compile time.
•Another drawback is restriction of the recursion procedure.
Symbol Table:
Storage Allocation
Stack Storage Allocation
•An activation record is pushed into the stack when activation begins
and it is popped when the activation end.
•Activation record contains the locals so that they are bound to fresh
storage in each activation record. The value of locals is deleted when
the activation ends.
ERRORS
SX S’SY
XaX / bX/ a / a SX
Ycd XaX / bX/ a / b
Ycd
Error Handling
Error Recovery:
4. Global correction
•The parser examines the whole program and
tries to find out the closest match for it which is
error-free.