0% found this document useful (0 votes)
55 views2 pages

2017 - Csen 4101

This document contains a sample exam paper for the course CSEN 4101 Compiler Construction. It includes 10 multiple choice questions in Group A and short answer/explanation questions in Groups B through E related to compiler design topics like grammars, parsing, code generation, and optimization. Students are required to answer all of Group A questions and at least one question from each of Groups B through E.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views2 pages

2017 - Csen 4101

This document contains a sample exam paper for the course CSEN 4101 Compiler Construction. It includes 10 multiple choice questions in Group A and short answer/explanation questions in Groups B through E related to compiler design topics like grammars, parsing, code generation, and optimization. Students are required to answer all of Group A questions and at least one question from each of Groups B through E.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

B.TECH/CSE/7TH SEM/CSEN 4101/2017 B.

TECH/CSE/7TH SEM/CSEN 4101/2017

B.TECH/CSE/7TH SEM/CSEN 4101/2017 (vii) Peephole optimization


COMPILER CONSTRUCTION (a) is applied to a small part of the code
(CSEN 4101) (b) can be used to optimize intermediate code
(c) can be applied to a portion of the code that is not contiguous
Time Allotted : 3 hrs Full Marks : 70 (d) all of these.
Figures out of the right margin indicate full marks. (viii) Optimization(s) connected with x : = x + 0 is(are)
Candidates are required to answer Group A and (a) peephole and algebraic
any 5 (five) from Group B to E, taking at least one from each group. (b) reduction in strength and algebraic
(c) peephole only
Candidates are required to give answer in their own words as far as practicable. (d) loop and peephole.
Group – A (ix) What is used to keep track of currently active activations?
(Multiple Choice Type Questions) (a) Control stack (b) Activation
1. Choose the correct alternative for the following: 10 × 1 = 10 (c) Execution (d) Symbol.

(i) Which one of the following statement is false for the SLR (1) and LALR (1) (x) {S, A, B} is the non-terminal alphabet and {a, b} is the terminal
parsing tables for a context free grammar? alphabet of the CFG. S is the start symbol. The set of production rules
(a) The reduce entries in both the tables may be different are given below
(b) The error entries in both the tables may be different S  aB S  bA B  b A  a B  bS A  aS B  aB B A  bAA
(c) The go to part of both tables may be different Which string is accepted by the given grammar?
(d) The shift entries in both the tables may be identical. (a) aabbbb (b) abbbba
(ii) The language produced by the regular grammar S  aS|bS|a|b (c) aabbab (d) aaaabb.
(a) a*b* (b) aa*bb*
(c) (a+b)* (d) (a + b)(a + b)* Group – B

(iii) A given grammer is not LL(1) if the parsing table of a grammer may contain 2. (a) Convert the following regular expression to an equivalent NFA
(a) any blank field (011 + 101 + 110 + 111)*
(b) any Є-entry (b) Construct DFA directly (not by generating NFA) for the regular
(c) duplicate entry of same production expression ( a | b ) * ab.
(d) more than one production rule.
(c) List the tokens (with 'type'-s and 'value'-s) for:
(iv) Given the grammar S  ABc A  a|Є B  b|Є.FOLLOW(A) is the set int max (int x, int y)
(a) {$} (b) {b} (c) {b, c} (d) {a, b, c}. {
(v) We have the grammar E->E + n | E * n | n. The handles in the right- Return (x > y? x : y);
sentential form of the reduction for a sentence n + n * n are }
(a) n, n + n and n + n * n (b) n, E + n and E * n 3 + 4 + 5 = 12
(c) n, E + n and E + E * n (d) n, E + n and E + n * n
3. (a) Explain the different phases of a compiler, showing the output of each
(vi) The grammar S  Sa1|Sa2|b1|b2 phase, using the example of the following statement:
(a) is left recurssive for (i = 0; i < 10; i++)
(b) is a CFG a = a + 10;
(c) has common left factor(s)
(d) is left recurssive and also has common left factor(s)
CSEN 4101 1 CSEN 4101 2
B.TECH/CSE/7TH SEM/CSEN 4101/2017 B.TECH/CSE/7TH SEM/CSEN 4101/2017

(b) What is the front end and back end of a compiler? (b) Generate three-address code for the above expression and implement
10 + 2 = 12 it in quadruples, triples, and indirect triples.
6 + 6 = 12
Group – C
4. (a) What language does the following CFG generate?
Group – E
S  aB | bA
A  a | aS | bAA 8. (a) Translate the following code it into machine code and show the
B  b | bS | aBB register and address descriptors while the instructions are generated.
(Assume that two registers are available.)
(b) Consider the following grammar and construct the SLR parsing table
D:=B-C
EE+T|T
E:=A-B
T  TF | F
B:=B+C
F  (E) | id A:=E-D
4 + 8 = 12
(b) Explain following terminologies:
5. (a) Eliminate left recursion from the following grammar: (i) Absolute machine code
S → Ab | b (ii) Relocatable machine code
A → Ac| Sd | Є (iii) Assembly code.
9 + 3 = 12
(b) Find FIRST and FOLLOW sets of each nonterminal of the grammar
obtained after solving part (a) of the question. 9. (a) Explain the following techniques of code optimization with suitable examples:
(c) Explain the terms "shift-reduce" conflict and "reduce-reduce" conflict (i) Copy propagation
in the context of LR parsers. (ii) Dead code elimination
4 + 4 + 4 = 12 (iii) Code motion
(iv) Common sub-expression elimination
Group – D (b) Divide the following code into basic blocks and draw the flow graph.
6. (a) Define inherited and synthesized attributes with suitable examples. (i) f =1;
(ii) i = 2;
(b) E E1 * T {E.val = E1.val * T.val}
(iii) if (i > x) goto (viii)
E T {E.val = T.val}
(iv) f = f * i;
T T1  F {T.val = T1.val  F.val}
(v) t = i+1;
T F {T.val = F.val}
(vi) i = t;
F 2 {F.val = 2}
(vii) goto (iii)
F 4 {F.val = 4}
(viii) goto calling program
Using the above Syntax Directed Translations, construct a parse tree
(4 × 2) + (2 + 2) = 12
for the expression 4  2  4 * 2 and show the evaluation order.
(3 + 3) + 6 = 12

7. (a) Construct a DAG and write the sequence of instructions for the expression
p + q / (r  s) + (r – s) * q.

CSEN 4101 3 CSEN 4101 4

You might also like