ucPDF
ucPDF
_________
MARWADI UNIVERSITY
Faculty of Technology
[CE-FOT1 (MU)] [ B. Tech]
SEM: 7 MU FINAL EXAM December: 2024
__________________________________________________________________________
Subject: - (Compiler Design) (01CE0714) Date:- 18/12/2024
Total Marks:-100 Time: - 3 Hrs.
ANSWER KEY
Question: 1.
MARWADI UNIVERSITY 1|
Enroll. No._________
d) Semantic Analyzer
Question: 2.
(a) Explain all the phases of Compiler in Detail with example. [8]
Lexical Analysis,Syntax Analysis, Semantic Analysis, Intermediate Code generation
,Code Optimization ,Code Generation with Symbol Table and Error Detection and
Recovery phase (1 marks each)
(b) Convert the following regular expression to DFA using subset construction method. [8]
(a|b)*abb
MARWADI UNIVERSITY 2|
Enroll. No._________
OR
(b) Convert the following regular expression to DFA using Syntax Tree Method. [8]
(a|b)*abb#
Question: 3.
MARWADI UNIVERSITY 3|
Enroll. No._________
MARWADI UNIVERSITY 4|
Enroll. No._________
Question: 4.
(a) Calculate the first and follow functions for the given grammar: [8]
S→aBDh
B →cC
C →bC/∈
D →EF
E →g / ∈
F →f / ∈
First Functions-
First(S) = { a }
First(B) = { c }
First(C) = { b , ∈ }
First(D) = { First(E) – ∈ } ∪ First(F) = { g , f , ∈ }
First(E) = { g , ∈ }
First(F) = { f , ∈ }
Follow Functions-
Follow(S) = { $ }
Follow(B) = { First(D) – ∈ } ∪ First(h) = { g , f , h }
Follow(C) = Follow(B) = { g , f , h }
Follow(D) = First(h) = { h }
Follow(E) = { First(F) – ∈ } ∪ Follow(D) = { f , h }
Follow(F) = Follow(D) = { h }
OR
(a) Solve the following: [8]
1. Consider the following grammar and eliminate left recursion.
A →ABd/ Aa / a
B →Be / b
A→aA′
A′→BdA′ ∣ aA′ ∣ ε
B→bB′
B′→eB′ ∣ ε
S →iEtSS`|a
S` →∈|eS
E→b
Question: 5.
(b) Derive the string "00101" for leftmost derivation and rightmost derivation using a CFG [6]
given by,
S → A1B
A → 0A | ε
B → 0B | 1B | ε
(c) What are different Register Allocation and Assignment Strategies? [4]
Any 4 types (1marks each)
OR
(a) Explain Activation Record in detail. [6]
Any 6 fields (1marks each)
(b) What is Ambiguous grammar? Check whether the given grammar is ambiguous or not. [6]
MARWADI UNIVERSITY 6|
Enroll. No._________
S→S+S|S*S|h
Definition(1 marks)
Yes Grammar is ambiguous. Take a string h+h*h will derive two parse tree.
(c) What is Basic Block? With example give the steps to identify the leader in basic blocks. [4]
Definition (1 marks)
Steps (3 marks)
Question: 6.
(a) What is Code Optimization? Explain the various types of Code Optimization Techniques. [8]
Definition (1 marks)
Any 7 types (1marks each)
(b) Write Three Address Code for the following expression: [4]
x = a + d * m ^ k – v (^ operator represent exponent)
t1 = m ^ k # Compute m raised to the power of k
t2 = d * t1 # Multiply d with t1
t3 = a + t2 # Add a to t2
t4 = t3 - v # Subtract v from t3
x = t4 # Assign the result to x
(c) Differentiate between Call by Value and Call by reference parameter passing methods. [4]
Any 4 difference (1marks each)
OR
(a) Explain the various issues in design of Code generation. [8]
Definition (1 marks)
Any 7 types (1marks each)
(b) Write Three Address Code for the following expression: [4]
a = b * -c + b * -c
t1 = -c # Negate c
t2 = b * t1 # Compute first b * -c
t3 = -c # Negate c again
t4 = b * t3 # Compute second b * -c
t5 = t2 + t4 # Add the two results
a = t5 # Assign the result to a
(c) Differentiate between Static and Dynamic memory allocation. [4]
Any 4 difference (1marks each)
MARWADI UNIVERSITY 7|