Chapter2 Datastructure For Language Processing
Chapter2 Datastructure For Language Processing
Processing
●
The tradeoff between memory requirements and
search efficiency of a datastructure, is a
fundamental principle of systems programming.
●
A language processor makes a frequent use of
the search operation over its datastructure.
Classification of Data structures
●
They can be classified according to the following
criteria:
a) Nature of the data structure – whether a linear
or nonlinear datastructure.
b) Purpose of the datastructure - Whether a
search datastructure or an allocation datastructure.
c) Life time of a datastructure – whether used
during language processing or during target
program execution.
Linear and Non Linear
●
Alinear datastructure consists of a linear
arrangement of elements in memory.
●
It facilitates efficient search.
●
It requires a continuous area of memory for its
elements.
●
So it is forced to over estimate the memory
requirements and leads to memory wastage.
Non Linear data structures
●
The elements of Non Linear Data structure are
accessed using pointers.
●
Elements need not occupy contiguous areas of
memory.
●
It leads to lower search efficiency.
E F
A C
H E
G F
H
B F
D
Linear Nonlinear
Search and Allocation datastructure
●
Search datastructures are used during
language processing to maintain attribute
information concerning different entities in the
source program.
●
The attribute entry for an entity is created only
once but may be searched for a large no of
times.So search efficiency is important.
●
Allocation datastructures are characterized by
the fact that the address of the memory area
allocated to an entity is known to the users of
that entity.
●
No search operations are conducted on
them.Speed of allocation or deallocation and
efficiency of memory utilization are the
important criteria.
Life time of datastructures.
●
A language processor uses both search and
allocation datastructures during its operation.
●
Search datastructures are used to constitute diff.
tables.
●
Allocation datastructures are used to handle
programs with nested structures of some kind.
●
Target program rarely uses search datastrctures,
but uses allocation datastructures.
Program Sample(input,output);
var
x,y:real;
i: integer;
Procedure calc(var a,b :real);
var
sum:=a+b;
---------
end calc;
begin { Main program}
---------
end.
●
Symbol tables are created for both main
program and calc, say, Symtabsample and
Symtabcalc.
●
They are constructed as search datastructures.
●
Their attributes are bind during compilation and
searched many times.
var p: integer;
begin
new (p);
1 2 3 4 5 6 7 8 9 10
1 2 3