0% found this document useful (0 votes)
33 views

Chapter2 Datastructure For Language Processing

This document discusses data structures used for language processing. It classifies data structures as linear or nonlinear, and as search or allocation structures. Search structures are used during language processing to maintain attribute information, while allocation structures store memory addresses. Common search structures include symbol tables, with entries having fixed and variable fields. Operations on search structures include insertion, deletion, and searching by key.

Uploaded by

Raji k
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Chapter2 Datastructure For Language Processing

This document discusses data structures used for language processing. It classifies data structures as linear or nonlinear, and as search or allocation structures. Search structures are used during language processing to maintain attribute information, while allocation structures store memory addresses. Common search structures include symbol tables, with entries having fixed and variable fields. Operations on search structures include insertion, deletion, and searching by key.

Uploaded by

Raji k
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 21

Datastructures for Language

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);

allocates memory and stores the address in tables.



No search is involved.
Search data structures

A search data structure(or search structure) is a
set of entries, each entry accommodating the
information concerning one entity.

Each entry is assumed to contain a key field
which forms the basis for a search.

The key field is the symbol field containing the
name of an entity.
Entry formats

Each entry in a search data structure is a set of fields.

It consists of two parts: fixed part and varient part. Each
part consists of a set of fields.

Fields of the fixed part exist in each entry of the search
structure.

The value in a tag field of the fixed part determines the
information to be stored in the varient part of the entry.
● For each value vi in the tag field, the varient part of the
entry consists of the set of fields SFvi
Entries in the symbol table of a compiler have
the following fields:
Fixed part: symbol and class, class is the tag
field.
Tag value variant part

Variable type, length, dimension info

Procedure name addr. of param list, no of
param

Function name type of return value, len of
ret. value, addr of param
list, no of params

Label statement number.
Fixed and variable length entries.

An entry may be declared as a record or a structure of the
language .

In Fixed length entry format, each record is defined to
consist of the following fields:
1) Fields in the fixed part of the entry.
2) Uvi SFvi, i.e. the set of fields in all varient parts of the
entry.

All records in the fixed length entry have an identical
format.

It enables efficient search procedure, but inefficient use of
memory, since many records may contain redundant fields.

In the variable length entry format, a record
consists of the following fields:
1) Fields in the fixed part of the entry, including
the tag field.
2) { fj | fj SFvj if tag = vj }

In this entry format no memory wastage occurs.
a) Fixed Entry format

1 2 3 4 5 6 7 8 9 10

1. symbol 6. parameter list address


2.class 7. no. of parameters
3. type 8. type of return value
4. dimension info 9. length of return value
5. length 10. statement number.

b) variable length entry for label

1 2 3

1. name 2. class 3. statement number



When a variable length entry format is used, the
search method may require knowledge of the
length of the entry. So it consists of:
1) The length field
2) Fields in the fixed part of the entry, including
the tag field.
3) { fj | fj SFvj if tag = vj }
length entry
Hybrid entry format

Hybrid entry format combines the access efficiency of the
fixed entry format with the memory efficiency of the
variable entry format.

In this format, each entry is split into two halves, the fixed
part and the variable part.

A pointer field is added to the fixed part. It points to the
variable part of the entry.

The fixed and variable part are accommodated in two
different datastructures.

The fixed parts of all entries are organized into
search(linear) datastructure, while variable part is put into
allocation data structure.
Hybrid entry format

Fixed part pointer length Variable part


Operations on search structures.

You might also like