Professional Documents
Culture Documents
Complier Design WINTER 2021 PAPER SOLUTION
Complier Design WINTER 2021 PAPER SOLUTION
Q.1
(a)Define following terms:
i.Compiler
ii.Interpreter
iii.Token
Q.2
(a)Explain input buffering methods.
(b)Define the following terms and give suitable example for it.
i. Augmented Grammar
ii.LR(0) Item
iii.LR(1) Item
(c)Draw the DFA for the regular expression (a|b)*abb using set
construction method only.
OR
2.Constant folding: The code that can be simplified by the user itself, is
simplified.
Consider the following:
Initial code:
x = 2 * 3;
Optimized code:
x = 6;
Q.4
(a)Draw a DAG for expression: a + a * (b – c) + (b – c) * d.
(b)Compare: Static v/s Dynamic Memory Allocation.
Static Memory Allocation Dynamic Memory Allocation
In the static memory allocation, In the Dynamic memory allocation,
variables get allocated permanently, till variables get allocated only if your
the program executes or function call program unit gets active.
finishes.
Static Memory Allocation is done Dynamic Memory Allocation is done
before program execution. during program execution.
It uses stack for managing the static It uses heap for managing the dynamic
allocation of memory allocation of memory
It is less efficient It is more efficient
In Static Memory Allocation, there is no In Dynamic Memory Allocation, there is
memory re-usability memory re-usability and memory can be
freed when not required
In static memory allocation, once the In dynamic memory allocation, when
memory is allocated, the memory size memory is allocated the memory size
can’t change. can be changed.
In this memory allocation scheme, we This allows reusing the memory. The
cannot reuse the unused memory. user can allocate more memory when
required. Also, the user can release the
memory when the user needs it.
execution is faster than dynamic execution is slower than static memory
memory allocation. allocation.
memory is allocated at compile time. memory is allocated at run time.
In this allocated memory remains from In this allocated memory can be
start to end of the program. released at any time during the program.
Example: This static memory Example: This dynamic memory
allocation is generally used for array. allocation is generally used for linked list.
1 Data-Dependence Graphs:
OR
Q.5
(a)Define a following: i.Basic block ii.Constant folding iii.Handle.
i. Basic block:
ii. Constant folding: The code that can be simplified by the user itself, is
simplified.
Consider the following:
Initial code:
x = 2 * 3;
Optimized code:
x = 6;
iii. Handle:
A handle is a substring that connects a right-hand side of the production rule in the grammar
and whose reduction to the non-terminal on the left-hand side of that grammar rule is a step
along with the reverse of a rightmost derivation.
It generates instructions by evaluating the mnemonics (symbols) in operation field and find the value
of symbol and literals to produce machine code. Now, if assembler do all this work in one scan then it
is called single pass assembler, otherwise if it does in multiple scans then called multiple pass
assembler. Here assembler divide these tasks in two passes:
• Pass-1:
1. Define symbols and literals and remember them in symbol table and literal table respectively.
2. Keep track of location counter
3. Process pseudo-operations
• Pass-2:
1. Generate object code by converting symbolic op-code into respective numeric op-code
2. Generate data for literals and look for values of symbols