Total No. of Questions: 6 Total No.
of Printed Pages:3
Enrollment No......................................
Faculty of Engineering
End Sem (Odd) Examination Dec-2022
CB3CO10 Compiler Design
Programme: B.Tech. Branch/Specialisation: CSBS
Duration: 3 Hrs. Maximum Marks: 60
Note: All questions are compulsory. Internal choices, if any, are indicated. Answers of
Q.1 (MCQs) should be written in full instead of only a, b, c or d.
Q.1 i. Which of the following is a definition of compiler? 1
(a) Acceptance of a program written in a high-level language and
produces an object program
(b) Program is put into memory and executes it
(c) Translation of assembly language into machine language
(d) None of these
ii. Which of the following is known as a compiler for a high-level 1
language that runs on one machine and produces code for a different
machine?
(a) Cross compiler (b) Multi pass compiler
(c) Optimizing compiler (d) One pass compiler
iii. Which of the following statements is false? 1
(a) Ambiguous grammar can’t be LR (k)
(b) An LL (1) parser is a top-down parser
(c) LALR is more powerful than SLR
(d) Left as well as right most derivations can be in Unambiguous
grammar
iv. Which of the following suffices to convert an arbitrary CFG to an 1
LL(1) grammar?
(a) Removing left recursion only (b) Factoring the grammar alone
(c) Factoring & left recursion removal (d) None of these
v. Type checking is normally done during ______. 1
(a) Lexical Analysis (b) Syntax Analysis
(c) Code generation (d) Syntax Directed Translation
P.T.O.
[2] [3]
vi. Which attributes get values from the attribute value of child nodes? 1 S−>A
(a) Synthesized attributes (b) Inherited attributes A−>aB / bd
(c) S-attributed SDT (d) L-attributed SDT B−>bBC / f
vii. What is the use of a symbol table in compiler design? 1 C→g
(a) Finding name’s scope
(b) Type checking Q.4 i. What is symbol table and what is its significance? 3
(c) Keeping all of the names of all entities in one place ii. What is Bottom-Up parsing? Differentiate SLR, LR and LALR parser? 7
(d) All of these OR iii. Create SLR(1) parsing table for the given grammar. Check whether 7
viii. Which of the following is not true about the Symbol Table? 1 given grammar is SLR(1) or not-
(a) All the labels of the instructions are symbols S→E
(b) Table has entry for symbol name address value E→E+T / T
(c) Perform the processing of the assembler directives T→T*F/F
(d) Created during pass 1 F → id
ix. Which of the following is machine dependent code optimization? 1
(a) Constant folding (b) Copy Propagation Q.5 i. What is DAG? Draw DAG for following expression: 4
(c) Peephole Optimization (d) Loop Optimization A = (B*-C) + (B*-C)
x. A fragment of code that resides in the loop and computes the same 1 ii. Translate following expression into quadruples, triples and indirect 6
value at each iteration is called a- triples:
(a) Induction analysis (b) Strength reduction (X - Y) / (Z*C) - (X + Y - Z)
(c) loop-invariant code (d) None of these OR iii. What is the significance of Intermediate Code? Explain different forms 6
of Intermediate Code Representation.
Q.2 i. What is the significance of buffer pair in lexical analyzer? 2
ii. What are the functions of lexical analyzer? 3 Q.6 Attempt any two:
iii. Explain various phases of compiler with neat and labelled diagram. 5 i. Explain Peephole optimization & its technique. 5
OR iv. Explain the role of finite automata in case of lexical analyser with 5 ii. Elaborate Loop Optimization Techniques. 5
example. iii. Construct basic block and flow graph for expression: 5
if(x>y && y>z)
Q.3 i. Define context free grammar with example. 2 x++;
ii. Remove left recursion and calculate FIRST and FOLLOW of given 8
grammar, also state whether the given grammar is ambiguous or not: ******
S→A
A → aB / Ad
B→b
C→g
OR iii. Create predictive parser parsing table for the grammar. Also identify 8
whether the given grammar is ambiguous or not:
Marking Scheme LALR
CB3CO10 Compiler Design OR iii. For DFA(canonical items set) 3 Marks 7
SLR(1) parsing table 3 Marks
Q.1 i) a)Acceptance of a program written in a high-level language and 1 SLR Grammar identification: 1 Mark
produces an object program
ii) a) Cross compiler 1
iii) d) Left as well as right most derivations can be in Unambiguous 1 Q.5 i. Intermediate code -2 Marks
grammar DAG: 2 Marks
iv) (d) None of these 1 ii. Conversion into quadruples: 2 Marks 6
v) d) Syntax Directed Translation 1 Conversion into triples: 2 Marks
Conversion into indirect triples: 2 Marks
vi) a) Synthesized attributes 1
OR iii. significance of intermediate code: 3 Marks 6
vii) d) all of the mentioned 1 intermediate code representation forms: 3 Marks
viii) c) Perform the processing of the assembler directives 1
ix) c) Peephole Optimization 1 Q.6
x) c) loop-invariant code 1 i. Peephole optimization: 1 Mark 5
Its different techniques: 4 Marks (1 for each)
Q.2 i. significance of buffer pair in lexical analyzer-2 Marks 2 ii. 2.5 Marks for each loop optimization techniques (2 techniques) 5
ii. 1 Mark for each functions of lexical analyzer(3 functions) 3 iii. 3 address code-2 Marks 5
iii. For the explanation of different Phases of Compiler 4 marks,1 5 Basic block-2 Marks
marks for diagram Flow chart – 1 Mark
OR iv. Role of finite automata- 3 marks 5
Example- 2 marks ******
Q.3 i. Definition: 1 Mark 2
Example: 1 Mark
ii. For left recursion removal: 2 Marks 8
For First set calculation 2 Marks
For Follow set calculation 2 Marks
Result: 1Marks
Ambiguous grammar- 1 Mark
OR iii. For First set 2 marks 8
For Follow set 2 marks
For Parsing table 3 marks
For Ambiguous or not verify 1 marks
Q.4 i. Symbol table definition- 2marks 3
Symbol table significance- 1 Mark
ii. For Bottom up parsing: 2.5 Marks 7
3 difference: 1.5 Mark for each difference between SLR,LR and