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

ucPDF

This document is an exam paper for the Compiler Design course at Marwadi University, detailing questions and answer keys for various topics related to compilers. It includes multiple-choice questions, definitions, and explanations of compiler phases, parsing techniques, and optimization strategies. The exam is scheduled for December 18, 2024, and consists of several sections covering theoretical and practical aspects of compiler design.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ucPDF

This document is an exam paper for the Compiler Design course at Marwadi University, detailing questions and answer keys for various topics related to compilers. It includes multiple-choice questions, definitions, and explanations of compiler phases, parsing techniques, and optimization strategies. The exam is scheduled for December 18, 2024, and consists of several sections covering theoretical and practical aspects of compiler design.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Enroll. No.

_________

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.

(a) Answer the following MCQs. [10]


1. Lexical Analysis phase generate and divide the program into__________.
a) Array b) Semantic Rules
c) Stack d) Tokens
2. Assembler is a program that translates___________
a) machine language to assembly language
b) assembly language into machine language
c) high level language into object program
d) None of the mentioned
3. A grammar that produces more than one parse tree for some sentence is called
a) Unambiguous b)Ambiguous
c) Regular d) None of these
4. LR stands for ___________
a) Left most Derivation
b) Rightmost Derivation
c) Right to Left Scanning
d) Left to Right Scanning with Rightmost Derivation in reverse
5. Which is the most powerful parser?
a) SLR b) LALR
c) Canonical LR d) Operator Precedence
6. Which of the following is a top-down parsing technique?
a) LR Parsing
b) Recursive Descent Parsing
c) Canonical LR Parsing
d) Simple LR Parsing
7. From the following options, Left Factoring is present in which grammar?
a) S→abc | Sxyz
b) S→Sm | k
c) S→Sab | hn
d) S→abc | abd | abh
8. Which of the following is not an example of a code optimization technique?
a) Register Allocation
b) Dead Code Elimination
c) Common Sub expression Elimination
d) Input Buffering
9. _______ intermediate code consists of 4 columns in the table.
a) Triples
b) Quadruples
c) (a) and (b) both
d) Indirect Triples
10. ________Phase is not include in Front End.
a) Lexical Analyzer
b) Syntax Analyzer
c) Code Generation

MARWADI UNIVERSITY 1|
Enroll. No._________

d) Semantic Analyzer

(b) Answer the following questions. [10]


1. Define: Translator
A program that converts source code from one form to another, such as compilers, interpreters, or
assemblers.
2. Derive the regular expression for the following language for Σ = {0, 1}
Binary string starting with 1
1(0+1)∗
3. Define: Finite Automata
A mathematical model of computation used to recognize regular languages.
4. What is DAG?
Directed Acyclic Graph; used in optimizing compilers to represent expressions and statements.
5. Name two types of Input Buffering Scheme.
Buffer Pairs, Sentinels
6. Name any two cousins of Compiler.
Preprocessor, Assembler, Linker, Loader
7. What is Token?
The smallest unit of a program with meaning, such as keywords, identifiers, or symbols.
8. Write postfix notation for a * b + c
ab∗c+
9. Write the Full form of NFA.
Non-deterministic Finite Automaton.
10. SLR (1) parser is bottom up parser. True or False?
True.

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._________

(a) Construct LR(0) parser for the following Grammer:


SAA
AaA|b
[8]

(b) Explain any four types of Compiler. [4]


Any 4 types (1marks each)
(c) Differentiate: Compiler and Interpreter. [4]
Any 4 difference (1marks each)
OR
(a) Construct CLR(1) parser for the following Grammer: [8]
SAA
AaA|b

MARWADI UNIVERSITY 4|
Enroll. No._________

(b) Explain any four types of Compiler Construction tools. [4]


Any 4 types (1marks each)
(c) Differentiate: Compiler and Assembler. [4]
Any 4 difference (1marks each)

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 }

(b) Explain Shift-Reduce Parser with example. [8]


Correct explanation with example.
MARWADI UNIVERSITY 5|
Enroll. No._________

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′ ∣ ε

2. Do left factoring in the following grammar.


S → iEtS | iEtSeS | a
E→b

S →iEtSS`|a
S` →∈|eS
E→b

(b) Explain Operator Precedence Parser with example. [8]


Correct explanation with example.

Question: 5.

(a) Explain Peephole optimization in detail. [6]


Any 6 types (1marks each)

(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|

You might also like