Compiler Design
Compiler Design
Compiler Design
Compiler Design(BTCS601)
Assignment-1
Ques.1 What are compilers and de-compilers? Why are they needed?
Ans.1
COMPILER: A compiler is a software program that transforms high-level source code that is
written by a developer in a high-level programming language into a low level object code
(binary code) in machine language, which can be understood by the processor. The process of
converting high-level programming into machine language is known as compilation.
The processor executes object code, which indicates when binary high and low signals are
required in the arithmetic logic unit of the processor.
DE-COMPILER: A de-compiler is a programming tool that converts an executable program
or low-level/machine language into a format understandable to software programmers. It
performs the operations of a compiler, which translates source code into an executable format,
but in reverse. A de-compiler’s recipient is a human user, whereas the compiler’s is the
machine.
A de-compiler can be useful in some cases for the following purposes:
Ans.2
A compiler can broadly be divided into two phases based on the way they compile.
Analysis Phase
Known as the front-end of the compiler, the analysis phase of the compiler reads the source
program, divides it into core parts and then checks for lexical, grammar and syntax errors.The
analysis phase generates an intermediate representation of the source program and symbol
table, which should be fed to the Synthesis phase as input.
1
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Synthesis Phase
Known as the back-end of the compiler, the synthesis phase generates the target program with the
help of intermediate source code representation and symbol table.
A compiler can have many phases and passes.
Pass : A pass refers to the traversal of a compiler through the entire program.
Phase : A phase of a compiler is a distinguishable stage, which takes input from the previous
stage, processes and yields output that can be used as input for the next stage. A pass can have
more than one phase.
Ans. 3
Execution of a C/C++ program involves four stages using different compiling/execution tool, these
tools are set of programs which help to complete the C/C++ program's execution process.
1. Preprocessor
2. Compiler
3. Linker
4. Loader
1) Preprocessor
This is the first stage of any C/C++ program execution process; in this stage Preprocessor processes
the program before compilation. Preprocessor include header files, expand the Macros.
2) Complier
This is the second stage of any C/C++ program execution process, in this stage generated output file
after preprocessing ( with source code) will be passed to the compiler for compilation. Complier will
compile the program, checks the errors and generates the object file (this object file contains assembly
code).
3) Linker
This is the third stage of any C/C++ program execution process, in this stage Linker links the
more than one object files or libraries and generates the executable file.
4) Loader
This is the fourth or final stage of any C/C++ program execution process, in this stage
Loader loads the executable file into the main/primary memory. And program run.
2
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Suppose, you save a C program with prg1.c – here .c is the extension of C code, prg1.c file contains
the program (source code of a C program). Preprocessor reads the file and generates the prg1.i (prg1.ii
– for c++ source code) file, this file contains the preprocessed code.
Compiler reads the prg1.i file and further converts into assembly code and generates prg1.s
and then finally generates object code in prg1.o file.
Linker reads prg1.o file and links the other assembly/object code or library files and generates
executable file named prg1.exe.
Loader loads the prg1.exe file into the main/primary memory and finally program run.
One more file is created that contains the source code named prg1.bak; it’s a backup file of the
program files.
Linker: In high level languages, some built in header files or libraries are stored. These libraries are
predefined and these contain basic functions which are essential for executing the program. These
functions are linked to the libraries by a program called Linker. If linker does not find a library of a
function then it informs to compiler and then compiler generates an error. The compiler
automatically invokes the linker as the last step in compiling a program. Not built in libraries, it also
links the user defined functions to the user defined libraries. Usually a longer program is divided
into smaller subprograms called modules. And these modules must be combined to execute the
program. The process of combining the modules is done by the linker.
3
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Pre-processor
A source program may be divided into modules stored in separate files. The task of collecting the
source program is entrusted to a separate program called pre-processor. It may also expand macros
into source language statement.
Ans.5
For example, if you are writing a compiler for the C programming language, the symbols { }
( ) ; all have significance on their own. The letter a usually appears as part of a keyword or
variable name, and is not interesting on it's own. Instead, we are interested in the whole
word. Spaces and newlines are completely uninteresting, and we want to ignore them
completely, unless they appear within quotes "like this"
It's job is to analyse the structure of the input stream, and operate of the "big picture".
In the course of it's normal work, the parser also verifies that the input is syntactically sound.
Consider again the example of a C-compiler. In the C-language, a word can be a function name
or a variable, depending on whether it is followed by a ( or a = There should be exactly one }
for each { in the program.
YACC stands for "Yet Another Compiler Compiler". This is because this kind of analysis of text
files is normally associated with writing compilers.
Ques. 6 What is LEX? Describe auxiliary definitions and translation for LEX with suitable
example.
Ans. 6
o Lex is a program that generates lexical analyzer. It is used with YACC parser generator.
o The lexical analyzer is a program that transforms an input stream into a sequence of tokens.
o It reads the input stream and produces the source code as output through implementing the lexical
analyzer in the C program.
4
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
lex.1
program and produces a C program lex.yy.c.
o Finally C compiler runs the lex.yy.c program and produces an object program a.out.
o a.out is lexical analyzer that transforms an input stream into a sequence of tokens.
5
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Ans.7
However, programs mostly execute with the help of operating systems (you can write programs
which do not use an OS to execute, but that would be a lot of unnecessary work) - which provide
abstractions on top of the hardware which the programs can use. The OS is responsible for setting up
a "context" for any program to run i.e. provide the program the memory it needs, provide general
purpose libraries which the program can use for doing common stuff such as write to files, print to
console etc.
However, to set up the context for the program (provide it memory, load its data, set up a stack for
it), the OS needs to read a program's executable file and needs to know a few things about the
program such as the data which the program expects to use, size of that data, the initial values stored
in that data region, the list of opcodes that make up the program (also called the text region of a
process), their size etc. All of this data and a lot more (debugging information, readonly data such as
hardcoded strings in the program, symbol tables etc) is stored within the executable file. Each OS
understands a different format of this executable file, since they expect all this info to be stored in
the executable in different ways.
A couple of formats that have been used for storing information in an executable file are ELF
and COFF on UNIX systems and PE on Windows.
Not all programs need executable formats. Look up bootloaders on Google. These are special
programs which occupy the first sector of a bootable partition on the hard-disk and are used to
load the OS itself.
Ques. 8 Explain Compiler construction tools?
Ans. 8
The compiler writer can use some specialized tools that help in implementing various phases of a
compiler. These tools assist in the creation of an entire compiler or its parts. Some commonly used
compiler construction tools include:
1. Parser Generator –
It produces syntax analyzers (parsers) from the input that is based on a grammatical
description of programming language or on a context-free grammar. It is useful as the
syntax analysis phase is highly complex and consumes more manual and compilation
time.
Example: PIC, EQM
6
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
2. Scanner Generator –
It generates lexical analyzers from the input that consists of regular expression description
based on tokens of a language. It generates a finite automation to recognize the regular
expression.
Example: Lex
7
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
8
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Assignment-02
An ordered, rooted tree that represents the A tree representation of the abstract syntactic
syntactic structure of a string according to some structure of source code written in a
context free grammar programming language
Also known as parsing tree, derivation tree, and Also known as abstract syntax tree
concrete syntax tree
Contains records of the rules (tokens) to match Contains records of the syntax of programming
input texts language
It is a kind of Top-Down Parser. A top-down parser builds the parse tree from the top to down,
starting with the start non-terminal. A Predictive Parser is a special case of Recursive Descent
Parser, where no Back Tracking is required.
By carefully writing a grammar means eliminating left recursion and left factoring from it, the
resulting grammar will be a grammar that can be parsed by a recursive descent parser.
Predictive Parser
Predictive parser is a recursive descent parser, which has the capability to predict which
production is to be used to replace the input string. The predictive parser does not suffer from
backtracking.
To accomplish its tasks, the predictive parser uses a look-ahead pointer, which points to the
next input symbols. To make the parser back-tracking free, the predictive parser puts some
constraints on the grammar and accepts only a class of grammar known as LL(k) grammar.
9
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Predictive parsing uses a stack and a parsing table to parse the input and generate a parse tree.
Both the stack and the input contains an end symbol $ to denote that the stack is empty and
the input is consumed. The parser refers to the parsing table to take any decision on the input
and stack element combination.In recursive descent parsing, the parser may have more than
one production to choose from for a single instance of input, whereas in predictive parser,
each step has at most one production to choose. There might be instances where there is no
production matching the input string, making the parsing procedure fail.
Shift-Reduce Parsing
Shift-reduce parsing uses two unique steps for bottom-up parsing. These steps are known as
shift-step and reduce-step.
10
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
● Shift step: The shift step refers to the advancement of the input pointer to the next input
symbol, which is called the shifted symbol. This symbol is pushed onto the stack. The
shifted symbol is treated as a single node of the parse tree.
● Reduce step : When the parser finds a complete grammar rule (RHS) and replaces it to
(LHS), it is known as reduce-step. This occurs when the top of the stack contains a
handle. To reduce, a POP function is performed on the stack which pops off the handle
and replaces it with LHS non-terminal symbol.
LR Parser
The LR parser is a non-recursive, shift-reduce, bottom-up parser. It uses a wide class of
context-free grammar which makes it the most efficient syntax analysis technique. LR parsers
are also known as LR(k) parsers, where L stands for left-to-right scanning of the input stream;
R stands for the construction of right-most derivation in reverse, and k denotes the number of
lookahead symbols to make decisions.
There are three widely used algorithms available for constructing an LR parser:
● SLR(1) – Simple LR Parser:
○ Works on smallest class of grammar
○ Few number of states, hence very small table
○ Simple and fast construction
● LR(1) – LR Parser:
○ Works on complete set of LR(1) Grammar
○ Generates large table and large number of states
○ Slow construction
● LALR(1) – Look-Ahead LR Parser:
○ Works on intermediate size of grammar
○ Number of states are same as in SLR(1)
Q.4 What is Operator Precedence Grammar? Apply the Operator Precedence Parsing
on the String id*id+id.
Ans. A grammar that is used to define mathematical operators is called an operator grammar
or operator precedence grammar. Such grammars have the restriction that no production has
either an empty right-hand side (null productions) or two adjacent non-terminals in its right-
hand side.
11
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
simpler than more general-purpose parsers such as LALR parsers. Operator-precedence parsers
can be constructed for a large class of context-free grammars.
Operator precedence grammars rely on the following three precedence relations between the
terminals:
Relation meaning
There are three widely used algorithms available for constructing an LR parser:
12
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Model of LR Parser
LR parser consists of an input, an output, a stack, a driver program and a parsing table that has
two functions
1. Action
2. Goto
13
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
The driver program is the same for all LR parsers. Only the parsing table changes from one
parser to another.
The parsing program reads character from an input buffer one at a time, where a shift reduce
parser would shift a symbol; an LR parser shifts a state. Each state summarizes the information
contained in the stack.
The stack holds a sequence of states, so, s1, · ·· , Sm, where Sm is on the top.
Action This function takes as arguments a state i and a terminal a (or $, the input end marker).
The value of ACTION [i, a] can have one of the four forms:
i) Shift j, where j is a state.
ii) Reduce by a grammar production A—> β.
iii) Accept.
iv) Error.
Goto This function takes a state and grammar symbol as arguments and produces a state.
If GOTO [Ii ,A] = Ij, the GOTO also maps a state i and non terminal A to state j.
Q.6 Draw the block diagram of LR Parser.
LR parsing is divided into four parts: LR (0) parsing, SLR parsing, CLR parsing and LALR
parsing.
14
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Shift Reduce parser attempts for the construction of parse in a similar manner as done in bottom
up parsing i.e. the parse tree is constructed from leaves(bottom) to the root(up). A more general
form of shift reduce parser is LR parser.
Basic Operations –
● Shift: This involves moving symbols from the input buffer onto the stack.
● Reduce: If the handle appears on top of the stack then, its reduction by using
appropriate production rule is done i.e. RHS of production rule is popped out of
stack and LHS of production rule is pushed onto the stack.
● Accept: If only the start symbol is present in the stack and the input buffer is
empty, then the parsing action is called accept. When accepted action is obtained,
it means successful parsing is done.
● Error: This is the situation in which the parser can neither perform shift action nor
reduce action and not even accept action
15
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
● Ambiguous grammars
● Unambiguous grammars
Ambiguous grammar:
A CFG is said to ambiguous if there exists more than one derivation tree for the given input
string i.e., more than one LeftMost Derivation Tree (LMDT) or RightMost Derivation Tree
(RMDT).
Definition: G = (V,T,P,S) is a CFG is said to be ambiguous if and only if there exist a string
in T* that has more than on parse tree.
P is a finite set of productions of the form, A -> α, where A is a variable and α ∈ (V ∪ T)* S is a
For Example:
We can create 2 parse tree from this grammar to obtain a string id+id+id :
The following are the 2 parse trees generated by left most derivation:
16
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Both the above parse trees are derived from the same grammar rules but both parse trees are
different. Hence the grammar is ambiguous.
Assignment-03
17
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
1. Data Dependencies: when statements compute data that are used by other
statements.
2. Control Dependencies: are those which arise from the ordered flow of control
in program.
18
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
formal parameter is reflected in the actual parameters (because changes are made at the
address).
● Call by Copy Restore
In call by copy restore compiler copies the value in formal parameters when the procedure
is called and copy them back in actual parameters when control returns to the called
function. The r-values are passed and on return r-value of formals are copied into l-value
of actuals.
● Call by Name
In call by name the actual parameters are substituted for formals in all the places formals
occur in the procedure. It is also referred as lazy evaluation because evaluation is done
on parameters only when needed.
QUADRUPLE
Op Arg1 Arg2 Result
(0) + a b T1
(1) + c d T2
(2) * T1 T2 T3
(3) + T1 c T4
(4) + T3 T4 T5
TRIPLE
Op Arg1 Arg2
(0) + A B
19
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
(1) + C D
(2) * (0) (1)
(3) + (0) C
(4) + (2) (3)
INDIRECT TRIPLE
100 (0)
101 (1)
102 (2)
103 (3)
104 (4)
Op Arg1 Arg2
(0) + A B
(1) + C D
(2) * (0) (1)
(3) + (0) C
(4) + (2) (3)
20
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
21
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
22
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
23
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
24
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
25
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
e=a+b
d=b*c
a=e-d
e=a+b
b=b*c
a=e-b
Q.7 What is the difference between dynamic and static storage management. Explain the
importance of run time storage management in compiler.
SOL:
It uses stack for managing the static It uses heap for managing the dynamic
3 allocation of memory allocation of memory
The information which required during an execution of a procedure is kept in a block of storage
called an activation record. The activation record includes storage for names local to the
procedure.
We can describe address in the target code using the following ways:
1. Static allocation
2. Stack allocation
26
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
In static allocation, the position of an activation record is fixed in memory at compile time
In the stack allocation, for each execution of a procedure a new activation record is pushed
onto the stack. When the activation ends then the record is popped.
SOL
Registers are the fastest locations in the memory hierarchy. But unfortunately, this resource is
limited. It comes under the most constrained resources of the target processor. Register
allocation is an NP-complete problem. However, this problem can be reduced to graph coloring
to achieve allocation and assignment. Therefore, a good register allocator computes an
effective approximate solution to a hard problem.
The register allocator determines which values will reside in the register and which register
will hold each of those values. It takes as its input a program with an arbitrary number of
registers and produces a program with finite register set that can fit into the target machine
Allocation –
Maps an unlimited namespace onto that register set of the target machine.
Allocation ensures that code will fit the target machine’s reg. set at each instruction.
Assignment –
Maps an allocated name set to physical register set of the target machine.
● Assumes allocation has been done so that code will fit into the set of physical registers.
● No more than ‘k’ values are designated into the registers, where ‘k’ is the no. of physical
registers.
27
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
ASSIGNMENT - V
Q1. Describe the Compiler and its phases with a neat and clean diagram.
Ans. COMPILER: A compiler is a software program that transforms high-level
source code that is written by a developer in a high-level programming language
into a low level object code (binary code) in machine language, which can be
understood by the processor. The process of converting high-level programming
into machine language is known as compilation.
The processor executes object code, which indicates when binary high and low
signals are required in the arithmetic logic unit of the processor.
phases of a compiler.
Lexical Analysis
The first phase of scanner works as a text scanner. This phase scans the source
code as a stream of characters and converts it into meaningful lexemes. Lexical
analyzer represents these lexemes in the form of tokens as:
28
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
<token-name, attribute-value>
Syntax Analysis
The next phase is called the syntax analysis or parsing. It takes the token
produced by lexical analysis as input and generates a parse tree (or syntax tree).
In this phase, token arrangements are checked against the source code grammar,
i.e. the parser checks if the expression made by the tokens is syntactically correct.
Semantic Analysis
Semantic analysis checks whether the parse tree constructed follows the rules of
language. For example, assignment of values is between compatible data types,
and adding string to an integer. Also, the semantic analyzer keeps track of
identifiers, their types and expressions; whether identifiers are declared before
use or not etc. The semantic analyzer produces an annotated syntax tree as an
output.
Code Optimization
The next phase does code optimization of the intermediate code. Optimization
can be assumed as something that removes unnecessary code lines, and arranges
the sequence of statements in order to speed up the program execution without
wasting resources (CPU, memory).
Code Generation
In this phase, the code generator takes the optimized representation of the
intermediate code and maps it to the target machine language. The code
generator translates the intermediate code into a sequence of (generally) re-
locatable machine code. Sequence of instructions of machine code performs the
task as the intermediate code would do.
Symbol Table
It is a data-structure maintained throughout all the phases of a compiler. All the
identifier's names along with their types are stored here. The symbol table makes
it easier for the compiler to quickly search the identifier record and retrieve it.
The symbol table is also used for scope management.
29
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
1. Macro processing:
A macro is a rule or pattern that specifies how a certain input sequence should
be mapped to an output sequence according to a defined procedure. The mapping
process that instantiates a macro into a specific output sequence is known as
macro expansion.
2. File Inclusion:
Preprocessor includes header files into the program text. When the preprocessor
finds an #include directive it replaces it by the entire content of the specified file.
3. Rational Preprocessors:
These processors change older languages with more modern flow-of-control and
data-structuring facilities.
4. Language extension :
30
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
·One-pass assemblers go through the source code once and assume that all
symbols will be defined before any instruction that references them.
·Two-pass assemblers create a table with all symbols and their values in the first
pass, and then use the table in a second pass to generate code
31
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
A linker or link editor is a program that takes one or more objects generated by
a compiler and combines them into a single executable program. Three tasks of
the linker are
1.Searches the program to find library routines used by program, e.g. printf(),
math routines.
32
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
2. Determines the memory locations that code from each module will occupy
and relocates its instructions by adjusting absolute references 3. Resolves
references among files.
A loader is the part of an operating system that is responsible for loading
programs in memory, one of the essential stages in the process of starting a
program.
Strategy Top down approach starts Bottom up approach starts evaluating the
evaluating the parse tree from the parse tree from the lowest level of the tree
1
top and moves downwards for and moving upwards for parsing the node.
parsing other nodes.
Attempt Top down parsing attempts to find Bottom up parsing attempts to reduce the
2 the leftmost derivation for a given input string to the first symbol of the
string. grammar.
Derivatio Top down parsing uses leftmost Bottom up parsing uses the rightmost
3
n Type derivation. derivation.
Objective Top down parsing searches for a Bottom up parsing searches for a production
4 production rule to be used to rule to be used to reduce a string to get a
construct a string. starting symbol of grammar.
33
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
SOL:
34
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
35
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
36
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
37
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
38
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
39
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Ans. t1 = a+b
t2 = c+d
t3 = t1*t2
t4 = t1+c
t5 = t3 + t4
QUADRUPLE
(0) + a b T1
(1) + c d T2
(2) * T1 T2 T3
(3) + T1 c T4
(4) + T3 T4 T5
TRIPLE
40
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Op Arg1 Arg2
(0) + A B
(1) + C D
(3) + (0) C
INDIRECT TRIPLE
100 (0)
101 (1)
102 (2)
103 (3)
104 (4)
41
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
Op Arg1 Arg2
(0) + A B
(1) + C D
(3) + (0) C
42
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
y = x + 5;
i = y;
z = i;
w = z * 3;
Optimized code:
y = x + 5;
i = y;
1. w = y * 3;
Constant folding:
The code that can be simplified by the user itself, is simplified.
Initial code:
x = 2 * 3;
Optimized code:
2. x = 6;
Strength Reduction:
The operators that consume higher execution time are replaced by the operators
consuming less execution time.
Initial code:
y = x * 2;
Optimized code:
y = x + x; or y = x << 1;
Initial code:
43
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
y = x / 2;
Optimized code:
3. y = x >> 1;
4. Null sequences:
Useless operations are deleted.
5. Combine operations:
Several operations are replaced by a single equivalent operation.
Static memory allocation is performed when the compiler compiles the program and
generates object files, linker merges all these object files and creates a single executable
file, and loader loads this single executable file in main memory, for execution. In static
memory allocation, the size of the data required by the process must be known before
the execution of the process initiates.
If the data sizes are not known before the execution of the process, then they have to be
guessed. If the data size guessed is larger than the required, then it leads to wastage of
memory. If the guessed size is smaller, then it leads to inappropriate execution of the
process.
Static memory allocation method does not need any memory allocation operation
during the execution of the process. As all the memory allocation operation required for
the process is done before the execution of the process has started. So, it leads to faster
execution of a process.
Static memory allocation provides more efficiency when compared by the dynamic
memory allocation.
Dynamic memory allocation is performed while the program is in execution. Here, the
memory is allocated to the entities of the program when they are to be used for the first
time while the program is running.
The actual size, of the data required, is known at the runtime so, it allocates the exact
memory space to the program thereby, reducing the memory wastage.
44
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
● Control stack is a run time stack which is used to keep track of the live
procedure activations i.e. it is used to find out the procedures whose execution
have not been completed.
● When it is called (activation begins) then the procedure name will push on to
the stack and when it returns (activation ends) then it will popped.
● Activation record is used to manage the information needed by a single
execution of a procedure.
● An activation record is pushed into the stack when a procedure is called and it
is popped when the control returns to the caller function.
45
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
46
ASSIGNMENT | DIVYANSH JAIN(17100BTCMCI01669)
47