Compiler Advance Sheet - 2023
Compiler Advance Sheet - 2023
ADVANCED COMPILER
Years Marks
2015 3
2016 5
2017 6
2018 5
2019 6
2020 4
2021 Set (1) 7
2021 Set (2) 8
COMPILER DESIGN GATE SYLLABUS
Q2. [MSQ]
ADVANCED COMPILER - 2023 1
Consider the following program:
int a = 5; x = 100, y=1; void main(){
void P(){ int a, y = 10;
int a = 1; a= x+1;
y++; P();
x = x + a; a = x – y;
Q(); print(a, x, y); // S2
print( a, x, y); // S1 Q();
} a = x + y;
void Q(){ print(a, x, y); // S3
int x =2; R();
a = a+10; print(a, x, y); // S4
R(); }
}
void R(){
x = x – 1;
}
Which of the following statement is/are true?
(a) Using Dynamic Scoping, the output of the given program is:
S1:11, 101, 11 S2:90, 101, 11 S3: 112, 101, 11 S4: 112, 100, 11
(b) Using Static Scoping , the output of the given program is:
S1:1, 100, 2 S2:90, 100, 10 S3:109, 99, 10 S4: 109, 98, 10
(c) If the initial value of the global variable „a‟ is 2 instead of 5 then
Using Dynamic Scoping, the output of the given program is:
S1:11, 101, 11 S2:90, 101, 11 S3:112, 101, 10 S4: 109, 98, 10
(d) If the initial value of the global variable „a‟ is 2 instead of 5 then
Using Static Scoping , the output of the given program is:
S1:1, 100, 2 S2:90, 100, 10 S3: 109, 99, 10 S4: 109, 98, 10
Q3. In a language that uses call-by-reference, a function f(x, y) is defined as follows:
Q4. [MSQ]
Which of the following pair(s) is/are not correct; (where pair contains the
expression and areas of the C runtime Environment)?
(a) (*H , Static) (b) (C, Heap)
(c) (H, Stack) (d) (G, Stack)
Q5. [MSQ]
Which of the following pair(s) is/are correct; (where pair contains the expression
and areas of the C runtime Environment)?
(a) (**H , Static) (b) (*C, Heap)
(c) (*B, Stack) (d) (E, Stack)
Q6. Consider the set of tokens: {ab, abc, abd, b, bc, bb, ca, cd, da, daa}. What is the
Q7. [MSQ]
Consider following simple Lexical rules:
/* regular definitions */
letter [A-Z][a-z]
uletter [A-Z]
p {uletter} + {letter}*
q {letter}{uletter}
r {letter}*
{p} {return(01);}
{q} {return(10);}
{r} {return(11);}
Suppose the input consists of a string of (upper- or lower-case) letters. Select
from the list below, a correct pair (w, i), where the program returns i when the
input is w.
(a) (BcDab, 011011)
(b) (aabBcC, 110110)
(c) (E, 01)
(d) (gHH, 10)
Q10. [MSQ]
Which of the following grammar(s) is/are not LL(1)?
(a) S → aAbB |bBcC A → Ba | Cc B → aB | 𝜆 C→ cC| c
(b) S → 𝑎𝑆𝑎 | 𝐴𝐵𝐶 A → aB | 𝜆 B → bB| 𝜆 C→ 𝑐| 𝜆
(c) S → 𝑎𝐵𝑏𝐴𝑐 A → 𝑎𝐵 | 𝑎𝐶 B → bB| 𝜆 C→ 𝑐| 𝜆
(d) S → AB | bC A→ cA| Bc B → SbB| 𝜆 C→ 𝑐| 𝜆
Q12. [MSQ]
Consider the following grammar G
S Aa | bAc | dc | bda
A a
Which of the following statement(s) is/are true?
(a) G is LR(1)
(b) G is LaLR(1)
(c) G is SLR(1)
(d) Let the number of rows in LR(1) parsing table is X and the number of rows in
LaLR(1) parsing table is Y, then |X - Y | is 0.
Q13. [MSQ]
Which of the following statement(s) is/are False?
(a) Given a predictive parsing table for a grammar, if the table contains no
duplicate entries then a predictive parser can be built for that grammar.
(b) The only way to eliminate a shift – reduce conflict from a grammar is to
rewrite the grammar.
(c) If a program specifies two functions with the same name, the error should be
reported by the compiler‟s lexer.
(d) The abstract syntax tree is the concrete parse tree with redundant
punctuation tokens.
Q14. A grammar with which of the following can *not* be LL (k)?
Q15. [MSQ]
Which of the following statement(s) is/are False?
1. Lexical analysis is recursive in order to handle nested parentheses.
2. Scanners don‟t know anything about the grammar of language.
3. A successful parse means the input is semantically correct.
4. Finite State machine can have an unlimited numbers of states.
5. A regular expression is a type of pattern used to classify lexemes
6. You can change state in a DFA without reading any input character.
(a)2 & 5 only
(b) 1, 3, 4 only
(c) All except 2
(d) 1, 3, 4, 6 only
Q17. Which of the following accurately specifies a constraint that a parser puts on the
Q20. [MSQ]
Consider the following grammar G:
S → aAb|Bc A → bBC| 𝝀 B → 𝒅𝑩| 𝝀 C→e | f
The grammar G is not LL(1) because
(a) G is ambiguous.
(b) G has left-recursive rules.
(c) G is not left-factored.
(d) In G, First(A) contains empty string and First(A) ∩ Follow(A) ≠ ∅.
Q21. Consider the following grammar G:
Q24. If you select one grammar (say Gk) from S at random then what is the probability
Q26. If you select one grammar (say Gk) from S at random then what is the probability
that Gk is LL(1) and the size of Gk is 2? ________
Q27. You select one grammar (say Gk) from S at random. If X be a random variable
that denotes the size of Gk, then what is the value of 𝐸 2𝑋 2 − 4𝑋 + 1 ? __________
[Assume E(X) represents the expectation of X]
Q28. If you select one grammar (say Gk) from S at random then what is the probability
That Gk is LL(1) and SLR(1) both? _______
Q29. If you select one grammar (say Gk) from S at random then what is the probability
that Gk is SLR(1) but not LL(1)? _______
Q30. Consider the grammar and LR(0) parsing table for the grammar
(1) E → E * B (2) E → E + B (3) E → B (4) B → 0 (5) B → 1
For the string “1 + 1 * 1”, the maximum number of symbols at a time in the
stack of LR parser is ____________
Q31. [MSQ]
In what situations would we use the stack pointer instead of the frame pointer?
(a) Allocating space for local variables in the middle of a function, e. g.:
Line# Code Snippet
1 void f (char c, int x)
2 int a = 5;
3 < some code>
4 int b = 7; //here
5 < more code . . .>
6 }
(b) Accessing the arguments passed to the current function
(c) Returning to the caller functions after the stack and frame pointer is restored
to the caller‟s original values.
(d) None of the above
Q41. Which of the last five values (nodes) added in the following tree created using
recursive descent parsing?
(a) x, 2, 3, y, 5
(b) 3, intit, plus, varref, y
(c) Varref, y, Write, Intit, 5
(d) Intit, Plus, Varref, Write, Intit
Q47. [MSQ]
Consider the following attributed grammar G:
SXT T. a: = X. b S. b: = T. b
T X T1 T. b: = T1. b T1. a: = T. a + X. b
T T. b: = T. a
Xa X. b: = 1
Xb X. b: = 2
Which of the following statement is/are true?
(a) The attribute „a‟ is inherited but „b‟ is synthesized.
(b) The grammar G is L-attributed.
(c) The grammar is S-attributed.
(d) For string “bba”, the value of attributes of root node S i.e., S.b is 5.
For the string 1247_8 value attribute for root node evaluates to_________
Q49. [MSQ]
Consider the following SDD to which generates Abstract syntax tree as an
intermediate code.
Assume Create_Node (a, b, c) creates the root node „a‟ with „b‟ as left-child and „c‟
as right-child. If the given SDD generates abstract syntax tree T for the string
6+7*2, then which of the following statement is/are true ?
Out of the following four properties which property/properties are not satisfied
by G?
(a) It is unambiguous.
(b) It is LL(1).
(c) It enforces left-associativity of + and *.
(d) It enforces precedence of * over +.
Q51. Arrange the following grammars in ascending order of their power to represent
different syntax and semantics rules of programming languages.
1. Syntax directed translations
2. Context free grammar
3. Context sensitive grammar
4. Attributed grammar
(a)1, 2, 3, 4
(b) 2, 3, 4, 1
(c) 3, 4, 1, 2
(d) 2, 3, 1, 4
Q57. How many basic blocks are there in the following 3 address code?
1. read a
2. read b
3. t1 = a + b // line3
4. t2 = a * 2
5. c = t1 + t2
6. if a < c goto 8
7. t2 = a + b
8. b = 25 // line8
9. c = b + c
10. d = a - b
11. if t2 = 0 goto 17
12. d = a + b
13. t1 = b - c
14. c = d - t1
15. if c < d goto 3
16. c = a + b
17. print c // line 17
18. print d
Q59. After applying which technique of code optimization Code I is transformed into
Code II?
Q63. How many live variables are there at the beginning of statement 5?
Q70. In the following CFG how many loop invariants can be moved out of the loop?
Q74. Minimum number of nodes in the DAG for the following three addresses code, is
_____________
#include<stdio.h>
struct s1 {int b; int i; float f;};
struct s2 {int b; int i; float f;};
struct s3 {int b; int i; float f;};
int main(){
struct s1 a;
struct s1 b;
struct s2 c;
struct s2 d;
struct s3 e;
struct s3 f;
__________// L1
return 0;
}
Q77. [MSQ]
Which of the following statement(s) has no error?
(a) (S2) b = d; (b) * (S2*) &b = e;
(c) a. i = = f. i; (d) a = f;
Q78. [MSQ]
Which of the following statement(s) has compile time error?
(a) * (S1*) &e = b = a; (b) a.i = c.i = e.i;
(c) d.f = f. i; (d) b.i = a.f;
Q79. Match each term on the left with the most appropriate phrase on the right:
Left Column Right Column
i. Token 1. Can be found at compile time
ii. Type error 2. Beneficial transformation of IR
iii. Machine-dependent 3. Can produce empty string
optimization 4. Contains regular expression in
iv. Machine – independent productions
optimization 5. Transformation of IR to native code
v. Null-able non – terminal 6. Unite of input text meaningful for
vi. Extended context – free parsing
grammar