Implementation of Symbol Table
Implementation of Symbol Table
i) List various applications of system software (1 mark for each point, any four
points)
Multiprogramming Multiprocessing
1) It is the interlarded execution of 1) It is the simultaneous execution
two of more processed by a of two or more processes by a
processor without waiting for multiprocessor within a single
external event. computer system.
2) Multiprogramming loads more 2) Multiprocessing involves the
than one program in to the execution of multiple concurrent
memory, so that processor can processes in a system instead of
switch between any of the loaded processing a single process at any
program. one instant.
3) These systems are designed to 3) It means a process is run on
maximize CPU usage. i.e. Number multiple processors. So execution
of processes run on a single speed up is achieved
processor
4) In these several programmes are 4) It means that computer can
running at a time, like windows process more than one thing at a
with many programmes open. time.
Page 2 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
iii) Explain the working of Bucket Sort. (2 marks for explanation, 2 marks for
example)
The sort involves examine the least significant digit of the keyword first, and the
item is then assigned to a bucket uniquely depend on the value of the digit.
After all items have been distributed the buckets items are merged in order and
then the process is repeated until no more digits are left. A number system of
base P requires P buckets.
There are serious disadvantages to using it internally on a digital compiler
1) It takes two separate processes, a separation and a merge
2) It requires a lot of extra Storage for the buckets.
The average time required for the sort is ( N log P(K) ) where N is the
table size, K is the maximum key size & P is the radix of the radix sort.
The extra storage required is N P.
Page 3 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
iv) Explain hash and random entry search (1 mark for hash, 3 marks for random
entry)
Ans. In hash and random entry search the random entry number K generated
from the key by methods similar to their used in address calculation. If the K th position
s avoid, then the new element is put there; is not then some other call must be found
for the insertion.
The first problem is the generation of a random number from the
key. The four character EBCDIC keywords divide the keywords by the table
length N and use the remainder. This scheme works well as long as N and
the key size have no common factors. For a given group of in keywords
the remainder should be fairly evenly distributed over O---(N-1). Another
method is to treat the keyword as a binary fraction and multiply it by
another binary fraction.
The second problem is the procedure to be followed when the first
trial entry result in a filled position. There are a member of methods of
resolving this problem.
1) Random entry with replacement: A sequence of random numbers is
generated from the keyword from each of these a number between
1 and N is formed and the table is protect at the position. Probing
are terminated when a void space is found. Notice that the random
numbers generated are independence and it is perfectly possible to
probe the same position twice.
2) Random entry without replacement: This is the same as above
except that any attempt to prove the same position twice is
bypassed. This method holds advantage over the only when proves
are expensive e.g. for files on tape or drum.
3) Open addressing: If the first probe gives a position K and that
position is filled, then the next location K+1 is probed and so on
until a free position is found. If the search runs off the bottom of
the table, then it is renewed at the top.
Page 4 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
ii) With neat diagram explain intermediate phase of compiler. (3 marks for
diagram, 3 marks for explanation)
Ans. The compiler creates an intermediate form of source program.
It affords 2 advantages
1) It facilitates optimization of object code.
2) It allows a logical separation between machine independent and machine
dependent.
One intermediate form is a parse tree.
For E.G
Page 5 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
M1 * 2 276 M1
/ M1 92
M2 M2
M2 B * 6 B
M3 M3
= A M3
M4 = A M3
M4
2) Save the Macro definition:- The processor must store the macro instruction
definitions which it will need for expanding macro calls.
3) Recognize the Macro calls:- The processor must recognize macro call that
appear as operation mnemonics. This suggest that macro names be handled
as a type of opcode.
2) Syntax Phase:-
1st i) In this phase the compiler must recognize the phases (syntatic
construction); each phrase is a semantic entry and is a string of tokens that
has meaning, and 2nd Interpret the meaning of the constructions.
ii) Syntactic analysis also notes syntax errors and assure some sort of
recovery. Once the syntax of statement is correct, the second step is to
interpret the meaning (semantic).
There are many ways of recognizing the basic constructs and interpreting
the meaning.
Page 9 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
iii) Syntax analysis uses rules (reductions) which specifies the syntax form
of source language.
iv) These reduction defines the basic syntax construction and appropriate
compiler routine (action routine) to be executed when a construction is
recognized.
v) The action routine interpret the meaning and generate either code or
intermediate form of construction.
3) Interpretation Phase:- This phase is typically a routine that are called when a
construct is recognized. The purpose of these routines is to on intermediate
form of source program and add information to identifier table.
6) Code generation:-
i) This phase produce a program which can be in Assembly or machine language.
ii)This phase has matrix as input.
iii) It uses the code production in the matrix to produce code.
iv)It also reference the identifier table in order to generate address & code
conversion.
Page 10 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
7) Assembly phase:-The compiler has to generate the machine language code for
computer to understand. The task to be done is as follows:-
i) Generating code
ii) Resolving all references.
iii) Defining all labels.
iv) Resolving literals and symbolic table.
OR
Q.2)c) (1mark for each phase)
Ans. 1) Lexical Analysis:- This phase takes as input the original program and if the
elements of the program are correct it generates some meaningful units
called “tokens”
2) Syntax Analysis:- This phase takes as input the tokens generated by lexical
phase and if the syntax of the statement is correct it generates a parse tree
representation.
3) Sementic Analysis:- This phase performs the check on the meaning of the st
statement and performs the necessary modifications in the parse tree
representation.
(If the structure of compiler does not include sementic analysis then in
such a case sementic analysis is assumed to take place within the syntax an
analysis phase)
4) Intermediate code generation:- This phase takes as input the pass tree
Representation and generates an intermediate representation to break the
complexity of the statement and hence helps in faster translation.
5) Code optimization:- This phase is responsible for generating an optimized
Intermediate representation so that the resulting code would get executed
Faster.
6) Code Generation:- This phase is responsible for generating the target
program which can be assembly language program or machine language
Program.
7) Symbol table:- It is used for keeping a track on the symbols encountered in
the program.
8) Error handler:- It is responsible for the detection reporting and the handling
of the errors which can occur in any of the compilation phase.
Page 11 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
Q.3) Attempt any FOUR of the following:
Ans: The loader is a program which accepts the object program decks prepares these
programs for execution by the computer and initiates the execution.
In simple loading scheme, the assembler o/p the machine language translation
of a program on a secondary storage device and a loader is placed in core. The
loader places into memory the machine language version of the users program
and transfers control to it. Since the loader program is much smaller than the
assembler, this makes more core available to the users program
Page 12 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
Ans. Relocating loader avoids possible reassembling of all subroutines when a single
subroutine is changed and perform the tasks of allocation and linking for the
programmer. The BSS loader allows many procedure segments yet only one data
segment.
The o/p of a relocating assembler using a BSS scheme is the object program and
information about all other program it references.
For each source program the assembler o/p a text prefixed by a transfer vector
that consist of addresses containing names of the subroutines referenced by the
source program. The assembler would also provide the loader with additional
information such as the length of the entire program and the length of the transfer
vector position. After loading the text and the transfer vector into core, the loader
would load each subroutine identified in the transfer vector. It would the place a
transfer instruction to the corresponding subroutine in each entry in the transfer
vector.
The BSS loader scheme is other used on compiler with a fixed length direct
address instruction format.
The relocation bit solves the problem of relocation, the transfer vector is used to
solve the problem of linking and the program length information solves the problem of
allocation.
Page 13 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
c) State the use of macro with suitable example (2 marks for explanation, 2 marks for
example)
Ans. Macros are single line abbreviation for groups of instructions. For every
occurrence of this one. Line macro instruction, the macro processing assemble will
substitute the entire block.
He can achieve the conciseness and ease in coding of high level language
without losing the basic advantage of assembly language programming.
Ans.
People
Application Programming
Compilers Assemblers Macro processors
Loaders Text editor be baggily aids searching and sorting
I/O program File system Schedule Libraries Memory management device management
Compiler is system program that accept people life languages and translate
them into machine language.
Loaders are system programs that prepare machine language programs for
execution.
i) What is macro? Explain macroprocessor and macro definition. (2 mark for macro, 1
marks for macroprocessor, 1 mark for macro definition)
Ans. The assembly language programmer often finds that certain set of instructions get
repeated often in the code. Instead of repeating the set of instructions the
programmer can take advantage of macro facility where macro is defined as “Single
line abbreviation for group of instructions”
Page 16 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
For e.g.:-
A 2, Data
A 3, Data
.
.
.
A 1, Data
A 2, Data
A 3, Data
.
.
.
The above requirement can be achieved by using macro facility as follows:-
MACRO
INCR
A 1, Data
Macro A 2, Data
definition A 3, Data
MEND
.
.
.
INCR
.
.
INCR
END
Page 17 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
The meaning of INCR is not known to the assembler because it is programmer
defined and hence we need a Macroprocessor that would take if and process it.
MACRO
INCR
A 1, Data
A 2, Data
A 3, Data
MEND
ii) Explain different data structures used by Phase-II assembler. (4 marks for
explanation)
a) Symbolic mnemonic
b) Instruction length
c) Binary machine opcode.
d) Format.
iv) Pseudo-operation Table (POT):- It indicate for each pseudo-op the symbolic
mnemonic and action to be taken in pass 2
Or
v) Symbol Table (ST):- It is used to generate the address of the symbol address in
the program.
vi) Base table (BT):- It indicate which registers are currently specified as base
register by USING Pseudo-ops.
vii) INST workspace:- It is used for holding each instruction and its various parts
are being getting assembled.
viii) PUNCH CARD workspace:- It is used for punching (outputting) the assembled
instruction on to cards.
ix) PRINT LINE workspace:- It is used for generating a printed assembly listing for
programmers reference.
x) Object card:- This card contain the object program in a format required by the
loader.
iii) Explain how to reduce different process in compiler. (1 mark for each process)
Ans. There are 4 different ways to reduce process in compiler. They are as follows:-
Linker Loader
3) Linker accepts the input (.obj 3) Loader accepts the input from
file) from compiler or assembler. linker.
Ans. The interpretation phase is typically a collection of routines that are called
when a construct is recognized in the syntactic phase. The purpose of these routine is
to create an intermediate form of the source program and add information to the
identifier table.
The separation of the syntactic phase from the interpretation phase is a logical
division. The former phase recognizes syntactic constructs while the latter interpret
the precise meaning in to the matrix or identifier table.
i) It is the only phase which is allowed to communicate with the original source
program.
ii) This phase take as input the original source program and generate some
meaningful units called “tokens”.
a) Explain overlay structure in detail. (2 mark for diagram, 6 marks for explanation)
Ans. The subroutines of a program are needed at different times. For e.g. Pass 1 and
pass 2 of an assembler are call other subroutine it is possible to produce an
overlay structure that identifiers mutually exclusive subroutines.
In order for the overlay structure to work it is necessary for the module
loader to the various procedures as they are needed. The portion of the loader
that actually intercepts the “calls” and loads the necessary procedure is collect
the overlay supervision or simply the upper.
Page 22 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
A (20 K)
B (20 K) D (10 K)
70 K
e (30 K) E (20 K)
Overlay structure
Above program consisting of five subprogram (A, B, C, D & E) that require look
bytes of core. The arrow indicate that subprogram A only calls B, D and E; subprogram
B only calls C and E; subprogram D only calls E; and subprogram C and E do not call any
other routine procedures B and D are never in use at the same time; neither are C and
E. If are load only those procedures that are actually to be used at any particular time,
the amount of core needed is equal to the longest path of the overlay structure. This
happens to be 70k.
b) Draw the block diagram of the phases of compiler. (8 marks for correct complete
diagram)
Ans.
OR
(There are two diagrams for this question. so any one diagram can be considered)
Page 24 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
c) Explain Binary search and Linear search. (4 marks for each search)
Ans. Binary search:- A more systematic copy of searching an ordered table is: start at
the middle of the table and compare the keyword with the middle entry. The keyword
may be equal to greater than or smaller than the item checked. The next action taken
for each of these outcomes is as follows:
1 AL
2 EX
3 FN
4 FU IF>FU
5 IF
6 IW IF<IW IF=IF
7 LE
8 LO IF<LO
9 NC
10 OP
11 OR
12 RO
13 RN
14 JE
15 T1
Linear search:- In linear search the given keyword id compare exhaustively with
every entry in the table with the given keyword. Element examined sequentially
starting from the first element and ended when list exhausted.
7) It provides little comfort to know that on the average only search half of the
dictionary.
Page 26 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
8) The average length of time to find and entry is
N
T(avg)=[ overhead associated with entry probe] *
2
Ans. Insertion sort is based on the principle of inserting the element at a correct place
in a previously sorted list. It can be varied from 1 to n-1 to sort the entire array.
Elements 5 0 1 9 2 6 4
to be sorted
1st Iteration (place element at location ‘1’ i.e. a[1]; at its correct place)
0 1 2 3 4 5 6
0 5 1 9 2 6 4
Sorted unsorted
0 1 5 9 2 6 4
Sorted unsorted
Page 27 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
0 1 5 9 2 6 4
Sorted unsorted
0 1 2 5 6 9 4
Sorted unsorted
0 1 2 4 5 6 9
Ans. i) in syntactic analysis the compiler must recognize the phrases (syntactic
construction), each phrase is a semantic entry and is a string of tokens that has
meaning and interpret the meaning of the construction.
ii) Syntactic analysis also notes syntax errors and assure some sort of recovery. Once
the syntax of statement is correct, the second step is to interpret the meaning
(semantic).
iii) There are many ways of recognizing the basic construct and interpreting the
meaning.
iv) Syntax analysis uses rules (reductions) which specifies the syntax form of source
language.
v) These reduction defines the basic syntax construction and appropriate action
routine to be executed when a construction is recognized.
Page 28 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
vi) The action routine interprets the meaning and generates either code or
intermediate form of construction.
c) Explain conditional macro with an example. (2 marks for explanation, 2 marks for
example)
Ans. Two important macroprocessor pseudo-ops AIF and AGO permit conditional
reordering of the sequence of macro expansion. This allows conditional selection of
the machine instructions that appear in expansions of Macro call.
A2, DATA 2
A3, DATA 3
.
.
.
Loop 2 A1, DATA 3
A2, DATA 2
.
.
.
Loop 3 A1, DATA1
.
.
.
DATA 1 D C F ‘5’
DATA 2 D C F ‘10’
DATA 3 D C F ‘15’
Page 29 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
In the below example, the operands, labels and the number of instructions generated
change in each sequence. The program can written as follows:-
.
.
.
MACRO
A 2, & ARG2
A 3, & ARG3
.FINI MEND
.
.
.
LOOP1 VARY 3, DATA1, DATA2, DATA3 loop 1 A1, DATA1
. A2, DATA2
. A3, DATA3
.
LOOP2 VARY 1, DATA1 loop 2 A1,DATA3
. A2, DATA2
.
.
DATA 1 D C F ‘5’
DATA 2 D C F ‘10’
DATA 3 D C F ‘15’
Page 30 of 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 12 EXAMINATIONS
Subject code: 12263 Model Answer
Labels starting with a period(.) such as .FINI are macro labels and do not appear in the
output of the macroprocessor . The statement AIF ( & COUNT EQ1) .FINI direct the
macroprocessor to skip to the statement. Labeled .FINI if the parameter corresponding
to & COUNT is a1; otherwise the macroprocessor is to continue with the statement
following the AIF pseudo-ops.
AIF is a conditional branch pseudo ops it performs an arithmetic test and branches only
if the tested condition is true.
AIF & AGOcontrol the sequence in which the macroprocessor expands the
statements in macro instructions.
d) Explain disadvantage of BSS loader? (1 mark for each disadvantage, 1 mark for
function of BSS)
Ans. The BSS loader allows many procedure segments, but only one data segments.
E) What is Macro language? (4 marks for explanation) (Any other suitable example
can be considered)
Ans. Macro language is a language which is understand by macroprocessor. Macro
requires an overhead of macroprocessor . Macro language is always enclosed in
MACRO & MEND pseudo-opcode.
Macro is a single line abbreviation for group of instructions.
The template for defining a macro is as follows:-
_____
_____
E.g:-
MACRO
INCR
A1, DATA
A2, DATA
A3, DATA
MEND
.
.
.
INCR
.
.
.
END