MCQ System Software - Compiler
MCQ System Software - Compiler
MCQ System Software - Compiler
Compiler Design
MULTIPLE CHOICE QUESTIONS
O
IF
July 29, 2021
N
A
M
Compiler Design Manifold Institute of Technical Education
LD
O
IF
N
A
M
LD
1 Compiler Design 1
1.1 Multiple Choice Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
O
IF
N
A
M
iii
Compiler Design Manifold Institute of Technical Education
LD
O
IF
N
A
M
LD
1. [ Parsers | GATE 2019 ] Consider the grammar given below:
S ! Aa
A ! BD
B !b|2
D !d| 2
Let a, b, d and $ be indexed as follows:
O
IF
Compute the FOLLOW set of the non-terminal B and write the index values for
the symbols in the FOLLOW set in the descending order. (For example, if the
FOLLOW set is { a, b, d, $ } , then the answer should be 3210)
(a) 30
N
(b) 31
(c) 10
(d) 21
2. [ Parsers | GATE 2019 ] Which one of the following kinds of derivation is used
A
by LR parsers?
(a) Leftmost in reverse
(b) Rightmost in reverse
M
(c) Leftmost
(d) Rightmost
3. [ Parsers | GATE 2019 ] Consider the augmented grammar given below:
S’ ! S
S ! ( L ) | id
L ! L,S | S
Let I0 = CLOSURE ({ [ S’ ! ·S] } ). The number of items in the set GOTO (I0 ,
( ) is: _____.
(a) 4
1
Compiler Design Manifold Institute of Technical Education
(b) 5
(c) 6
(d) 7
4. [ Synthesized-and-L-Attribute | GATE 2019 ] Consider the following grammar
and the semantic actions to support the inheritance type declaration attributes. Let
X1 , X2 , X3 , X4 , X5 and X6 be the placeholders for the non-terminals D, T, L or L1
in the following table:
LD
Which one of the following are the appropriate choices for X1 , X2 , X3 and X4 ?
(a) X1 = L, X2 = L, X3 = L1 , X4 = T
O
(b) X1 = L, X2 = T, X3 = L1 , X4 = L
(c) X1 = T, X2 = L, X3 = L1 , X4 = T
(d) X1 = T, X2 = L, X3 = T, X4 = L1
IF
5. [ Compilers | GATE 2018 ] Which one of the following statements is FALSE?
(a) Context-free grammar can be used to specify both lexical and syntax rules.
(b) Type checking is done before parsing.
N
Which one of the following is correct for the given parse tree?
(a) $ has higher precedence and is left associative; # is right associative
LD
outputs the token that matches the longest possible prefix.
If the string bbaacabc is processes by the analyzer, which one of the following is
the sequence of tokens it outputs?
(a) T1 T2 T3
(b) T1 T1 T3
(c) T2 T1 T3
(d) T3 T3
O
8. [ Static-single-assignment | GATE 2017 [ Set-1] ]
mediate program in three address code
p = a − b
Consider the following inter-
IF
q = p * c
p = u * v
q = p + q
Which of the following corresponds to a static single assignment form of the above
code?
N
A
(a)
M
(b)
(c)
(d)
9. [ First-and-Follow | GATE 2017 [ Set-1] ] Consider the following grammar:
LD
What is FOLLOW(Q) ?
(a) { R}
(b) { w}
(c) { w, y}
(d) { w, $ }
O
IF
10. [ Parsers | GATE 2017 [ Set-1] ] Consider the following grammar:
stmt ! if expr then expr else expr ; stmt | l
expr ! term relop term | term
term ! id | number
id ! a | b | c
N
number ! [ 0-9 ]
where relop is a relational operator (e.g., < , > , ...), l refers to the empty state-
ment, and if , then , else are terminals.
A
(a) 1024
(b) 1025
(c) 1026
(d) 1027
11. [ Register-Allocation | GATE 2017 [ Set-1] ] Consider the expression (a-1)*(((b+c)/3)+d)).
Let X be the minimum number of registers required by an optimal code genera-
tion (without any register spill) algorithm for a load/store architecture, in which
(i) only load and store instructions can have memory operands and (ii) arithmetic instructions can have only
The value of X is ___________.
(a) 2
(b) 3
(c) 4
(d) 5
12. [ Compilers | GATE 2017 [ Set-2] ] Match the following according to input (from
the left column) to the compiler phase (in the right column) that processes it:
LD
(a) P! (ii), Q! (iii), R! (iv), S! (i)
(b) P! (ii), Q! (i), R! (iii), S! (iv)
(c) P! (iii), Q! (iv), R! (i), S! (ii)
(d) P! (i), Q! (iv), R! (ii), S! (iii)
13. [ Parsers | GATE 2017 [ Set-2] ]
is/are CORRECT? O
Which of the following statements about parser
E!E-T|T
T!T+F|F
F ! (E) | id
Which of the following grammars is not left recursive, but is equivalent to G?
M
(a)
(b)
(c)
LD
(d)
15. [ Static-single-assignment | GATE 2016 [ Set-1] ] Consider the following code
segment.
x = u - t;
y = x * v;
x = y + w;
y = t - z;
y = x * y;
O
IF
The minimum number of variables required to convert the above code segment
to static single assignment form is ________.
(a) 10
(b) 11
N
(c) 12
(d) 13
16. [ Syntax-Directed-Translation | GATE 2016 [ Set-1] ] Consider the following Syn-
A
A ! Sb { print 3 }
Using the above SDTS, the output printed by a bottom-up parser, for the input
aab is:
(a) 1 3 2
(b) 2 2 3
(c) 2 3 1
(d) syntax error
17. [ Compilers | GATE 2016 [ Set-2] ] Match the following:
LD
grammars is free from left recursion?
(a)
O
IF
(b)
N
(c)
A
(d)
19. [ Parsers | GATE 2015 [ Set-1] ] Which one of the following is True at any valid
M
(b) 9
(c) 10
(d) 11
21. [ Live-Variable | GATE 2015 [ Set-1] ] Let an represent the number of bit strings
of length n containing two consecutive 1s. What is the recurrence relation for an ?
(a) an + an + 2n 2
2 1
(b) an + 2an + 2n 2
2 1
(c) 2an + an + 2n 2
2 1
LD
(d) 2an + 2an + 2n 2
2 1
O
IF
N
The variables which are live both at the statement in basic block 2 and at the
statement in basic block 3 of the above control flow graph are
A
(a) p, s, u
(b) r, s, u
(c) r, u
M
(d) q, v
23. [ Syntax-tree-and-context-flow-graph | GATE 2015 [ Set-2] ] In the context of
abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the follow-
ing is TRUE?
(a) In both AST and CFG, let node, N2 be the successor of node N1 . In the input
program, the code corresponding to N2 is present after the code corresponding
in N1 .
(b) For any input program, neither AST nor CFG will contain a cycle
(c) The maximum number of successors of a node in an AST and a CFG depends
on the input program
(d) Each node is AST and CFG corresponds to at most one statement in the input
program
24. [ Compilers | GATE 2015 [ Set-2] ] Match the following:
(P) Lexical analysis (1) Graph c o l o r i n g
(Q) Parsing (2) DFA minimization
(R ) Register allocation (3) Post −order t r a v e r s a l
(S) Expression evaluation (4) Production t r e e
LD
(c) P-2, Q-4, R-1, S-3
(d) P-2, Q-3, R-4, S-1
25. [ Control-Flow-Graph | GATE 2015 [ Set-2] ] Consider the intermediate code
given below.
1. i = 1
2. j = 1
3. t1 = 5 * i
4. t2 = t1 + j
5. t3 = 4 * t2
6. t4 = t3
7. a[ t4] = -1
8. j = j + 1
O
IF
9. if j < = 5 goto(3)
10. i = i + 1
11. if i < 5 goto(2) The number of nodes and edges in the control-flow-graph
constructed for the above code, respectively, are
(a) 5 and 7
N
(b) 6 and 7
(c) 5 and 5
(d) 7 and 8
A
26. [ Parsers | GATE 2015 [ Set-3] ] Among simple LR (SLR), canonical LR, and
look-ahead LR (LALR), which of the following pairs identify the method that is
very easy to implement and the method that is the most powerful, in that order?
(a) SLR, LALR
M
S1: LL(1) can parse all strings that are generated using grammar G.
S2: LR(1) can parse all strings that are generated using grammar
(a) Only S1
(b) Only S2
(c) Both S1 and S2
(d) Neither S1 nor S2
28. [ Code-Optimization | GATE 2014 [ Set-1] ] Which one of the following is
FALSE?
(a) A basic block is a sequence of instructions where control enters the sequence
LD
at the beginning and exits at the end.
(b) Available expression analysis can be used for common subexpression elimina-
tion.
(c) Live variable analysis can be used for dead code elimination.
(d) x=4*5 ) x=20 is an example of common subexpression elimination.
29. [ Parsers | GATE 2014 [ Set-1] ] A canonical set of items is given below
S −−> L . > R
Q −−> R .
are recursive.
31. [ Regular-Expressions | GATE 2014 [ Set-1] ] Which of the regular expressions
given below represent the following DFA?
LD
I) 0*1(1+00*1)*
II) 0*1*1+11*0*1
III) (0+1)*1
(a) I and II only
(b) I and III only
O
IF
(c) II and III only
(d) I, II, and III
32. [ Associativity-and-Precedence | GATE 2014 [ Set-2] ] Consider the grammar
defined by the following production rules, with two operators * and +
N
S −−> T * P
T −−> U | T * U
P −−> Q + P | Q
Q −−> Id
U −−> Id
A
Which one of the following statements about the source code for the C program is
LD
CORRECT?
(a) X is declared as "int X[ 32] [ 32] [ 8] ".
(b) X is declared as "int X[ 4] [ 1024] [ 32] ".
(c) X is declared as "char X[ 4] [ 32] [ 8] ".
(d) X is declared as "char X[ 32] [ 16] [ 2] ".
35. [ General | GATE 2014 [ Set-2] ] Consider the expression tree shown. Each
O
leaf represents a numerical value, which can either be 0 or 1. Over all possible
choices of the values at the leaves, the maximum possible value of the expression
represented by the tree is _______.
IF
N
(a) 6
(b) 7
A
(c) 8
(d) 9
36. [ Code-Generation-and-Code-Optimization | GATE 2014 [ Set-3] ] One of the
purposes of using intermediate code in compilers is to
M
LD
( LRU ) page replacement policy. Assume that all the page frames are initially
empty. What is the total number of page faults that will occur while processing
the page reference string given below?
4, 7, 6, 1, 7, 6, 1, 2, 7, 2
(a) 6
(b) 7
(c) 8
(d) 9
O
IF
39. [ Run-Time-Environments | GATE 2012 ] Consider the program given below,
in a block-structured pseudo-language with lexical scoping and nesting of proce-
dures permitted.
Program main ;
Var . . .
N
Procedure A1 ;
Var . . .
C a l l A2 ;
End A1
A
Procedure A2 ;
Var . . .
Procedure A21 ;
M
Var . . .
C a l l A1 ;
End A21
C a l l A21 ;
End A21
C a l l A1 ;
End main .
Consider the calling chain : Main-> A1-> A2-> A21-> A1 The correct set of
activation records along with their access links is given by:
(a)
LD
(b) O
IF
N
(c)
A
M
(d)
40. [ Parsers | GATE 2012 ] For the grammar below, a partial LL(1) parsing table is
also presented along with the grammar. Entries that need to be filled are indicated
as E1, E2, and E3. 2 is the empty string, $ indicates end of input, and, | separates
alternate right hand sides of productions.
S ! aAbB | bAaB | 2
A ! S
B ! S
The FIRST and FOLLOW sets for the non-terminals A and B are
(a) FIRST(A) = { a,b,2 } = FIRST(B)
FOLLOW(A) = { a,b}
FOLLOW(B) = { a,b,$ }
(b) FIRST(A) = { a,b,$ }
FIRST(B) = { a,b,2 }
LD
FOLLOW(A) = { a,b}
FOLLOW(B) = { $ }
(c) FIRST(A) = { a,b,2 } = FIRST(B)
FOLLOW(A) = { a,b}
FOLLOW(B) = f
(d) FIRST(A) = { a,b} = FIRST(B)
FOLLOW(A) = { a,b}
FOLLOW(B) = { a,b}
O
41. [ Parsers | GATE 2012 ] For the grammar below, a partial LL(1) parsing table is
also presented along with the grammar. Entries that need to be filled are indicated
as E1, E2, and E3. 2 is the empty string, $ indicates end of input, and, | separates
alternate right hand sides of productions.
IF
S ! aAbB | bAaB | 2
A ! S
B ! S
N
E3: S ! 2
(c) E1: S ! aAbB,S ! 2
E2: S ! bAaB,S! 2
E3: B ! S
(d) E1: A ! S,S ! 2
E2: B ! S,S ! 2
E3: B ! S
42. [ Compilers | GATE 2011 ] The lexical analysis for a modern computer language
such as Java needs the power of which one of the following machine models in a
necessary and sufficient sense?
LD
(a) parsing of the program
O
44. [ Parsers | GATE 2011 ] Consider two binary operators ’↑’ and ’↓’ with the
precedence of operator ↓ being lower than that of the operator ↑. Operator ↑ is
right associative while operator ↓, is left associative. Which one of the following
represents the parse tree for expression (7↓3↑4↑3↓2)?
IF
N
A
(a)
M
(b)
(c)
LD
(d)
O
IF
45. [ Register-Allocation | GATE 2011 ] Consider evaluating the following expres-
sion tree on a machine with load-store architecture in which memory can be ac-
cessed only through load and store instructions. The variables a, b, c, d and e
initially stored in memory. The binary operators used in this expression tree can
be evaluate by the machine only when the operands are in registers. The instruc-
N
(a) 2
(b) 9
(c) 5
(d) 3
46. [ Compilers | GATE 2010 ] Which data structure in a compiler is used for man-
aging information about variables and their attributes?
(a) Abstract syntax tree
(b) Symbol table
(c) Semantic stack
LD
(d) Parse Table
47. [ Run-Time-Environments | GATE 2010 ] Which languages necessarily need
heap allocation in the runtime environment?
(a) Those that support recursion
(b) Those that use dynamic scoping
(c) Those that allow dynamic data structures
(d) Those that use global variables
O
48. [ Register-Allocation | GATE 2010 ]
variables a, b, c, d, e, f.
The program below uses six temporary
IF
a = 1
b = 10
c = 20
d = a+b
e = c+d
N
f = c+e
b = c+e
e = b+ f
d = 5+e
r e t u r n d+ f
A
Assuming that all operations take their operands from registers, what is the mini-
mum number of registers needed to execute this program without spilling?
(a) 2
M
(b) 3
(c) 4
(d) 6
49. [ Parsers | GATE 2010 ] The grammar S ! aSa| bS| c is
(a) LL(1) but not LR(1)
(b) LR(1) but not LR(1)
(c) Both LL(1) and LR(1)
(d) Neither LL(1) nor LR(1)
50. [ Compilers | GATE 2009 ] Match all items in Group 1 with correct options from
those given in Group 2
Group 1 Group 2
P. Regular e x p r e s s i o n 1. Syntax a n a l y s i s
Q. Pushdown automata 2. Code g e n e r a t i o n
R. Dataflow a n a l y s i s 3. Lexical analysis
S. Register allocation 4. Code o p t i m i z a t i o n
LD
(d) P-2, Q-1, R-4, S-3
51. [ Parsers | GATE 2009 ] Which of the following statements are TRUE?
I.There exist parsing algorithms for some programming languages whose com-
plexities are less than (n3 ).
II.A programming language which allows recursion can be implemented with
static storage.
III.No L-attributed definition can be evaluated in the framework of bottom-up
parsing.
O
IV.Code improving transformations can be performed at both source language and
intermediate code level.
(a) I and II
IF
(b) I and IV
(c) III and IV
(d) I, III and IV
52. [ Parsers | GATE 2008 ] Which of the following describes a handle (as applicable
N
to LR-parsing) appropriately?
(a) It is the position in a sentential form where the next shift or reduce operation
will occur.
(b) It is non-terminal whose production will be used for reduction in the next step.
A
(c) It is a production that may be used for reduction in a future step along with
a position in the sentential form where the next shift or reduce operation will
occur.
(d) It is the production p that will be used for reduction in the next step along with
M
a position in the sentential form where the right hand side of the production
may be found.
53. [ Compilers | GATE 2008 ] Some code optimizations are carried out on the
intermediate code because
(a) They enhance the portability of the compiler to other target processors
(b) Program analysis is more accurate on intermediate code than on machine code
(c) The information from dataflow analysis cannot otherwise be used for opti-
mization
(d) The information from the front end cannot otherwise be used for optimization
LD
vation records
V.Programming languages which permit a function to return a function as its result
cannot be implemented with a stack-based storage allocation scheme for activation
records
(a) II and V only
(b) I, III and IV only
(c) I, II and V only
(d) II, III and V only
O
55. [ Parsres | GATE 2008 ] An LALR(1) parser for a grammar G can have shift-
reduce (S-R) conflicts if and only if
(a) the SLR(1) parser for G has S-R conflicts
IF
(b) the LR(1) parser for G has S-R conflicts
(c) the LR(0) parser for G has S-R conflicts
(d) the LALR(1) parser for G has reduce-reduce conflicts
N
56. [ Parsers | GATE 2007 ] Which one of the following is a top-down parser?
(a) Recursive descent parser.
(b) Operator precedence parser.
(c) An LR(k) parser.
A
S −−> i C t S S 1 | a
S 1 −−> eS | 2
C −−> b
LD
59. [ Grammar | GATE 2007 ] Consider the CFG with { S,A,B} as the non-terminal
alphabet, { a,b} as the terminal alphabet, S as the start symbol and the following
set of production rules:
S ! aB S ! bA
B ! b A ! a
B ! bS A ! aS
B ! aBB A ! bAA
(a) aaaabb
(b) aabbbb
O
Which of the following strings is generated by the grammar?
IF
(c) aabbab
(d) abbbba
60. [ Grammar | GATE 2007 ] Consider the CFG with { S,A,B} as the non-terminal
alphabet, { a,b} as the terminal alphabet, S as the start symbol and the following
set of production rules:
N
S ! aB S ! bA
B ! b A ! a
B ! bS A ! aS
B ! aBB A ! bAA
A
For the correct answer strings to Q.78, how many derivation trees are there?
(a) 1
(b) 2
M
(c) 3
(d) 4
61. [ Parsers | GATE 2006 ] Consider the following grammar.
S ! S * E
S ! E
E ! F + E
E ! F
F ! id
( i ) S ! S * .E
( ii ) E ! F. + E
( i i i ) E ! F + .E
Given the items above, which two of them will appear in the same set in the
canonical sets-of-items for the grammar?
LD
(d) None of the above
62. [ Code-Optimization | GATE 2006 ] Consider these two functions and two state-
ments S1 and S2 about them
i n t work1 ( i n t * a , i n t i , i n t j ) i n t work2 ( i n t * a , i n t i , i n t j )
{ {
i n t x = a [ i +2 ] ; i n t t1 = i +2;
a[ j ] = x + 1 ; i n t t 2 = a[ t 1 ] ;
r e t u r n a [ i +2 ] − 3 ; a[ j ] = t 2 + 1 ;
}
O }
return t2 − 3;
S1: The transformation form work1 to work2 is valid, i.e., for any program state
IF
and input arguments, work2 will compute the same output and have the same
effect on program state as work1
S2: All the transformations applied to work1 to get work2 will always improve the
performance (i.e reduce CPU time) of work2 compared to work1
In the predictive parser table, M, of the grammar the entries M[ S,id] and M[ R,$ ]
respectively.
S ! ER
R ! * E{ p r i n t ( " * " ) ; } R| 2
E ! F + E { print ( " + " ) ; } | F
F ! ( S ) | id { p r i n t ( id . value ) ; }
Here id is a token that represents an integer and id.value represents the corre-
sponding integer value. For an input ’2 * 3 + 4’, this translation scheme prints
(a) 2 * 3 + 4
(b) 2 * +3 4
(c) 2 3 * 4 +
LD
(d) 2 3 4+*
65. [ Code-Optimization | GATE 2006 ] Consider the following C code segment.
f o r ( i = 0 , i < n ; i ++)
{
f o r ( j = 0 ; j < n ; j ++)
{
i f ( i% 2)
}
{
}
O
x += ( 4 * j + 5 * i ) ;
y += ( 7 + 4 * j ) ;
IF
}
(a) ambiguous
(b) left-recursive
(c) right-recursive
M
(d) an operator-grammar
67. [ Grammar | GATE 2005 ] Consider the grammar:
E ! E + n | E * n | n
(d) n, E + n and E * n
68. [ Parsers | GATE 2005 ] Consider the grammar:
S ! (S) | a
Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar be
n1 , n2 and n3 respectively. The following relationship holds good:
(a) n1 < n2 < n3
(b) n1 = n3 < n2
(c) n1 = n2 = n3
LD
(d) n1 n3 n2
69. [ Compilers | GATE 2005 ] Consider line number 3 of the following C-program.
i n t main ( ) { / * Line 1 * /
i n t I , N; / * Line 2 * /
f r o ( I = 0 , I < N, I + + ) ; / * Line 3 * /
}
E ! number E . v a l = number . v a l
| E ’+ ’ E E(1) . v a l = E(2) . v a l + E> sup > ( 3 ) . v a l
| E ’* ’ E E( 1 ) . v a l = E( 2 ) . v a l * E( 3 ) . v a l
The above grammar and the semantic rules are fed to a yacc tool (which is an
A
LALR(1) parser generator) for parsing and evaluating arithmetic expressions. Which
one of the following is true about the action of yacc for the given grammar?
(a) It detects recursion and eliminates recursion
(b) It detects reduce-reduce conflict, and resolves
M
(c) It detects shift-reduce conflict, and resolves the conflict in favor of a shift over
a reduce action
(d) It detects shift-reduce conflict, and resolves the conflict in favor of a reduce
over a shift action
71. [ Parsers | GATE 2005 ] Consider the following expression grammar. The seman-
tic rules for expression calculation are stated next to each grammar production.
E ! number E . v a l = number . v a l
| E ’+ ’ E E(1) . v a l = E(2) . v a l + E> sup > ( 3 ) . v a l
| E ’* ’ E E( 1 ) . v a l = E( 2 ) . v a l * E( 3 ) . v a l
Assume the conflicts in Part (a) of this question are resolved and an LALR(1)
parser is generated for parsing arithmetic expressions as per the given grammar.
Consider an expression 3 * 2 + 1. What precedence and associativity properties
does the generated parser realize?
(a) Equal precedence and left associativity; expression is evaluated to 7
(b) Equal precedence and right associativity; expression is evaluated to 9
(c) Precedence of ’*’ is higher than that of ’+’, and both operators are left associa-
tive; expression is evaluated to 7
(d) Precedence of ’+’ is higher than that of ’*’, and both operators are left associa-
tive; expression is evaluated to 9
LD
72. [ Parsers | GATE 2004 ] Which of the following grammar rules violate the re-
quirements of an operator grammar? P,Q,R are nonterminals, and r,s,t are termi-
nals.
(i) P ! Q R
(ii) P ! Q s R
(iii) P ! 2
(iv) P ! Q t R r
(a) (i) only
(b) (i) and (iii) only
(c) (ii) and (iii) only
O
IF
(d) (iii) and (iv) only
73. [ Compilers | GATE 2004 ] Consider a program P that consists of two source
modules M1 and M2 contained in two different files. If M1 contains a reference to
a function defined in M2 , the reference will be resolved at
N
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 &
4.
(a) 200
(b) 180
(c) 160
(d) 40
LD
76. [ Grammar | GATE 2004 ] Consider the following grammar G:
S ! bS | aA| b
A ! bA| aB
B ! bB| aS | a
Let Na (w) and Nb (w) denote the number of a’s and b’s in a string w respectively.
The language L(G) ✓ { a, b} + generated by G is
(a) { w| Na (w) > 3Nb (w)}
(b) { w| Nb (w) > 3Na (w)} O
(c) { w| Na (w) = 3k, k 2 { 0, 1, 2, ...} }
IF
(d) { w| Nb (w) = 3k, k 2 { 0, 1, 2, ...} }
77. [ Grammar | GATE 2003 ] Which of the following suffices to convert an arbitrary
CFG to an LL(1) grammar?
(a) Removing left recursion alone
N
states and the LALR parser for G has n2 states. The relationship between n1 and
n2 is:
(a) n1 is necessarily less than n2
(b) n1 is necessarily equal to n2
M
LD
S’ ! e S | 2
E ! b
In the predictive parse table. M, of this grammar, the entries M[ S’, e] and M[ S’, $
] respectively are
(a) { S’! e S} and { S’! 2 }
(b) { S’! e S} and { }
(c) { S’! 2 } and { S’! 2 }
The grammar is
(a) LL(1)
N
shown below.
S ! T R
R ! + T { p r i n t ( ’ + ’ ) ; } R| 2
T ! num { p r i n t ( num . v a l ) ; }
M
Here num is a token that represents an integer and num .val represents the corre-
sponding integer value. For an input string ’9 + 5 + 2’, this translation scheme will
print
(a) 9 + 5 + 2
(b) 9 5 + 2 +
(c) 9 5 2 + +
(d) + + 9 5 2
84. [ Syntax-Directed-Translation | GATE 2003 ] Consider the syntax directed defi-
nition shown below.
S ! id : = E { gen ( id . p l a c e = E . p l a c e ; ) ; }
E ! E1 + E2 { t = newtemp ( ) ;
gen ( t = E1 . p l a c e + E2 . p l a c e ; ) ;
E . place = t }
E ! id { E . p l a c e = id . p l a c e ; }
Here, gen is a function that generates the output code, and newtemp is a function
that returns the name of a new temporary variable on every call. Assume that ti’s
are the temporary variable names generated by newtemp. For the statement ’X: =
Y + Z’, the 3-address code sequence generated by this definition is
(a) X = Y + Z
LD
(b) t1 = Y + Z; X = t1
(c) t1 = Y; t2 = t1 + Z; X = t2
(d) t1 = Y; t2 = Z; t3 = t1 + t2 ; X = t3
85. [ Run-Time-Environments | GATE 2003 ] Which of the following is NOT an
advantage of using shared, dynamically linked libraries as opposed to using stati-
cally linked libraries?
O
(a) Smaller sizes of executable files
(b) Lesser overall page fault rate in the system
(c) Faster program startup
IF
(d) Existing programs need not be re-linked to take advantage of newer versions
of libraries
86. [ Descriptive | GATE 2002 ] (a) Construct all the parse trees corresponding to i
+ j * k for the grammar
E ! E+E
N
E ! E*E
E ! id
(b) In this grammar, what is the precedence of the two operators * and +?
(c) If only one parse tree is desired for any string in the same language, what
A
LD
(a) Compute the FIRST and FOLLOW sets for E and A.
(b) Complete the LL(1) parse table for the grammar.
(a) Theory Explanation is given below.
90. [ Syntax-Directed-Translation | GATE 2001 ] The syntax of the repeat-until state-
ment is given by the gollowing grammar
S ! r e p e a t S1 u n t i l E
O
Where E stands for expressions, S and S1 stand for statement. The non-terminals
S and S1 have an attribute code that represents generated code. The nonterminal
E has two attributes. The attribute code represents generated code to evaluate
the expression and store its truth value in a distinct variable, and the attribute
varName contains the name of the variable in which the truth value is stored? The
IF
truth-value stored in the variable is 1 if E is true, 0 if E is false.
Give a syntax-directed definition to generate three-address code for the repeatuntil
statement. Assume that you can call a function newlabel( ) that returns a distinct
label for a statement. Use the operator ’
’ to concatenate two strings and the function gen(s) to generate a line containing
N
the string s.
(a) Theory Explanation is given below.
91. [ Grammar | GATE 2001 ] (a) Remove left-recursion from the following grammar:
S ! Sa | Sb | a | b
A
Construct all possible parse trees for the string abab. Is the grammar ambiguous?
(a) Theory Explanation is given below.
92. [ Compilers | GATE 2000 ] The number of tokens in the following C statement.
printf (" i = % d, &i = % x" , i , &i ) ;
is
(a) 3
(b) 26
(c) 10
(d) 21
93. [ Parsers | GATE 2000 ] Which of the following derivations does a top-down
parser use while parsing an input string? The input is assumed to be scanned in
left to right order.
(a) Leftmost derivation
(b) Leftmost derivation traced out in reverse
(c) Rightmost derivation
(d) Rightmost derivation traced out in reverse
94. [ Grammar | GATE 2000 ] Given the following expression grammar:
LD
E ! E * F | F + E | F
F ! F − F | id
T ! F { T . val = F . val}
F ! 2 { F . v a l = 2}
F ! 4 { F . v a l = 4}
(a) Using this SDTS, construct a parse tree for the expression
A
4-2-4*2
and also compute its E.val.
(b) It is required to compute the total number of reductions performed to parse a
given input. Using synthesized attributes only, modify the SDTS given, without
M
changing the grammar, to find E.red, the number of reductions performed while
reducing an input to E.
(a) Theory Explanation is given below.
96. [ Parsers | GATE 1999 ] Which of the following is the most powerful parsing
method?
(a) LL (1)
(b) Canonical LR
(c) SLR
(d) LALR
97. [ Compile | GATE 1999 ] The number of tokens in the Fortran statement DO 10
I = 1.25 is
(a) 3
(b) 4
(c) 5
(d) None of the above
98. [ Run-Time-Environments | GATE 1998 ] In a resident - OS computer, which of
the following systems must reside in the main memory under all situations?
(a) Assembler
LD
(b) Linker
(c) Loader
(d) Compiler
99. [ Parsers | GATE 1998 ] Which of the following statements is true?
(a) SLR parser is more powerful than LALR
O
(b) LALR parser is more powerful than Canonical LR parser
(c) Canonical LR parser is more powerful than LALR parser
(d) The parsers SLR, Canonical CR, and LALR have the same power
100. [ Compilers | GATE 1998 ] Type checking is normally done during
IF
(a) lexical analysis
(b) syntax analysis
(c) syntax directed translation
N
Z : : = id
LD
104. [ Run-Time-Environments | GATE 1997 ] Heap allocation is required for lan-
guages
(a) that support recursion
(b) that support dynamic data structures
(c) that use dynamic scope rules
(d) None of the above
105. [ Assembler | GATE 1996 ]
1. Object code generation
2. Literals added to literal table
3. Listing printed
O
The pass number for each of the following activities
IF
4. Address resolution of local symbols That occur in a two pass assembler respec-
tively are
(a) 1, 2, 1, 2
(b) 2, 1, 2, 1
N
(c) 2, 1, 1, 2
(d) 1, 2, 2, 2
106. [ Macros | GATE 1996 ] Which of the following macros can put a micro assembler
into an infinite loop?
A
(i) .MACRO M1 X
. I F EQ, X ; i f X=0 then
M1 X + 1
.ENDC
. I F NE X ; I F X 6= 0 then
M
LD
(c) Names and locations of all external symbols defined in the object module
(d) Absolute addresses of internal symbols
108. [ Parsers | GATE 1995 ] A shift reduce parser carries out the actions specified
within braces immediately after reducing with the corresponding rule of grammar
S ! xxW { p r i n t " 1 " }
S ! y { print "2"}
W ! Sz { p r i n t " 3 " }
O
What is the translation of xxxxyzz using the syntax directed translation scheme
described by the above rules?
IF
(a) 23131
(b) 11233
(c) 11231
(d) 33211
N
S ! aSB | d
B ! b
The number of reduction steps taken by a bottom-up parser while accepting the
string aaadbbb is _______.
(a) 7
112. [ Run-Time-Environment | GATE 2020 ] Consider the following statements.
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need
heap storage for memory allocation in the run-time environment.
LD
III. Errors violating the condition ’any variable must be declared before its use’ are de-
tected during syntax analysis. Which of the above statements is/are TRUE?
(a) II only
(b) I only
(c) I and III only
(d) None of I, II and III
O
113. [ Synthesized-Attribute | GATE 2020 ] Consider the productions A! PQ and
A! XY. Each of the five non-terminals A, P, Q, X, and Y has two attributes: s is a
synthesized attribute, and i is an inherited attribute. Consider the following rules.
Rule 1 : P . i = A. i + 2 , Q. i = P . i + A. i , and A. s = P . s + Q. s
Rule 2 : X . i = A. i + Y . s and Y . i = X . s + A. i
IF
Which one of the following is TRUE?
(a) Only Rule 2 is L-attributed.
(b) Neither Rule 1 nor Rule 2 is L-attributed.
N
end ;
var p t r : l i n k ;
begin
new ( p t r ) ;
ptr := n i l ;
. ptr^ . d : = 5 . 2 ;
write ln ( ptr )
end .
LD
(d) loader
(e) none of the above
116. [ Parsers | GATE 1992 ] Consider the SLR(1) and LALR (1) parsing tables for a
context free grammar. Which of the following statements is/are true?
(a) The go to part of both tables may be different.
(b) The shift entries are identical in both the tables.
O
(c) The reduce entries in the tables may be different.
(d) The error entries in the tables may be different.
(e) B, C and D.
IF
117. [ Operands | GATE 1991 ] The arithmetic expression : (a + b) * c - d / e * * f is
to be evaluated on a two-address machine, where each operands, the number of
registers required to evaluate this expression is ______. The number of memory
access of operand is __________.
(a) 3, 4
N
119. [ Linker-Loader | GATE 1991 ] Choose the correct alternatives (more than one
may be correct) and write the corresponding letters only: A "link editor" is a
program that:
(a) matches the parameters of the macro-definition with locations of the parame-
M
(a) Recursive descent parsing cannot be used for grammar with left recursion.
(b) The intermediate form the representing expressions which is best suited for
code optimization is the post fix form.
(c) A programming language not supporting either recursion or pointer type does
not need the support of dynamic memory allocation.
(d) Although C does not support call by name parameter passing, the effect can
be correctly simulated in C.
(e) No feature of Pascal violates strong typing in Pascal.
(f) A and D
LD
121. [ Match-the-Following | GATE 1990 ] Match the pairs in the following questions:
(a) P o i n t e r data type (p) Type c o n v e r s i o n
(b) Activation record (q) Dynamic data s t r u c t u r e
(c) Repeat − u n t i l (r) Recursion
(d) Coercion (s) Non− d e t e r m i n i s t i c loop
124. [ Compilers | GATE 1987 ] In a compiler the module the checks every character
of the source text is called:
(a) The code generator.
A
LD
128. [ Compilers | ISRO-2018 ] Which of the following comparisons between static
and dynamic type checking is incorrect?
(a) Dynamic type checking slows down the execution
(b) Dynamic type checking offers more flexibility to the programmers
(c) In contrast to Static type checking, dynamic type checking may cause failure
in runtime due to type errors
(a) Consist of a definition of a variable and all its uses, reachable from that defini-
tion
(b) Are created using a form of static code analysis
(c) Are prerequisite for many compiler optimization including constant propaga-
A
LD
usually produces no executable code when compiled?
(a) declaration
(b) assignment statements
(c) input and output statements
(d) structural statements
135. [ Symbol-Table | ISRO-2016 ] The access time of the symbol table will be loga-
rithmic if it is implemented by
(a) Linear list
(b) Search tree
O
IF
(c) Hash table
(d) Self organization list
136. [ Parsers | ISRO-2016 ] Recursive descent parsing is an example of
(a) Top-down parsers
N
LD
(a) Only II is correct
(b) Both I and II are correct
(c) Only I is correct
(d) Both I and II are incorrect
141. [ Assembler | ISRO-2016 ] A simple two-pass assembler does which of the
following in the first pass:
O
(a) Checks to see if the instructions are legal in the current assembly mode
(b) It allocates space for the literals.
(c) It builds the symbol table for the symbols and their values.
IF
(d) All of these
142. [ Code-Optimization | ISRO CS 2011 ] In compiler terminology reduction in
strength means
(a) Replacing run time computation by compile time computation
N
(a) A
(b) B
(c) C
(d) S
145. [ Parsers | ISRO CS 2013 ] Shift reduce parsing belongs to a class of
(a) bottom up parsing
(b) top down parsing
(c) recursive parsing
(d) predictive parsing
LD
146. [ Parsers | ISRO CS 2013 ] Which of the following productions eliminate left
recursion in the productions given below:
S ! Aa | b
A ! Ac | Sd | 2
(a) S ! Aa | b
A ! bdA’
A’ ! A’c
| A’ba | A | 2
(b) S ! Aa | b
A ! A’ |
bdA’,
O
IF
A’ ! cA’
| adA’ | 2
(c) S ! Aa | b
A ! A’c |
A’d
N
A’ ! bdA’
| cA | 2
(d) S ! Aa | b
A ! cA’ |
adA’ | bdA’
A
A’ ! A | 2
(4) t3=t2
(5) a[ t3] =0
(6) i=i+1;
(7) if i< 15 goto(2)
(a) 33
(b) 44
(c) 43
(d) 34
LD
149. [ Nielit Scentist-B [ 02-12-2018] ] __number of queues are needed to implement
symbol and is acting as permanent database
(a) Variable Table
(b) Terminal Table
(c) Keyword Table
(d) Identifier Table
LD
(b) Canonical LR parsing table
(c) LALR parsing table
(d) None of these
156. [ Micro-Program | Nielit Scientist-C 2016 march ] Micro program is
(a) the name of source program in micro computers
(b) the set of instructions indicating the primitive operations in a system
(c) 2n-1
(d) 2n
158. [ Compilers | Nielit Scientist-B CS 22-07-2017 ] In a compiler, keywords of a
A
LD
161. [ Assembler | Nielit Scientist-B CS 2016 march ] In a single pass assembler,
most of the forward references can be avoided by putting the restriction
(a) on the number of strings/lifereacs
(b) that the data segment must be defined after the code segment
(c) on unconditional rump
(d) that the data segment be defined before the code segment
O
162. [ Parsers | UGC-NET CS 2018 DEC Paper-2 ] The grammar S ! (S) | SS | 2 is
not suitable for predictive parsing because the grammar is
(a) An Operator Grammar
(b) Right Recursive
IF
(c) Left Recursive
(d) Ambiguous
163. [ Assembler | NieLit STA 2016 March 2016 ] Pseudo-instructions are
(a) assembler directives
N
(b) instructions in any program that have no corresponding machine code instruc-
tion
(c) instruction in any program whose presence or absence will not change the
output for any input
A
S! A | B
A! a | c
B! b | c
LD
(c) Loop Optimization
(d) Data flow analysis
166. [ Basics | Nielit Scientist-B CS 4-12-2016 ] The structure or format of data is
called:
(a) Syntax
(b) Struct
(c) Semantic
(d) none of the above
O
167. [ Code-Optimization | Nielit Scientist-B CS 4-12-2016 ] The graph that shows
IF
basic blocks and their successor relationship is called:
(a) DAG
(b) Control graph
(c) Flow graph
N
LD
(c) + and - have same precedence
(d) + has higher precedence than *
172. [ Compilers | ISRO CS 2015 ] The number of tokens in the following C statement
is
printf("i=% d, &i=% x", i&i);
(a) 13
(b) 6
(c) 10
O
IF
(d) 0
173. [ Parsers | ISRO CS 2015 ] Which grammar rules violate the requirement of the
operator grammar? A, B, C are variables and a, b, c are terminals 1) A ! BC 2) A
! CcBb 3) A ! BaC 4) A ! 2
(a) 1 only
N
174. [ Parsers | ISRO CS 2015 ] Which one of the following is a top-down parser?
(a) Recursive descent parser
(b) Shift left associative parser
M
(a) LALR parser is more powerful and costly as compare to other parsers
(b) All CFG’s are LP and not all grammars are uniquely defined
(c) Every SLR grammar is unambiguous but not every unambiguous grammar is
SLR
(d) LR(K) is the most general backtracking shift reduce parsing method
177. [ Parsers | JT(IT) 2018 PART-B Computer Science ] With respect to compiler
design, "recursive descent" is a ____ parsing technique that reads the inputs from
____.
(a) top-down, right to left
LD
(b) top-down, left to right
(c) bottom up, right to left
(d) bottom up, left to right
178. [ Parsers | JT(IT) 2018 PART-B Computer Science ] Which of the following is
NOT a bottom up, shift reduce parser?
(a) LR parser
(b) LL parser
(c) SLR parser
(d) LALR parser
O
IF
179. [ Nielit Scientist-B 17-12-2017 ] Which of the following is machine independent
optimization?
(a) Loop optimization
(b) Redundancy Elimination
N
(c) Folding
(d) All of the options
180. [ Nielit Scientist-B 17-12-2017 ] Which of the following statements is/ are false?
A
(a) S1 only
M
182. [ Parsers | JT(IT) 2018 PART-B Computer Science ] Which of the following
phases of the compilation process is also known as parsing?
(a) Lexical analysis
(b) Code optimization
(c) Syntax analysis
(d) Semantic analysis
183. [ Linker | KVS 22-12-2018 Part-B ] Resolution of externally defined symbols is
performed by____
LD
(a) Linker
(b) Loader
(c) Compiler
(d) Editor
184. [ Compilers-and-Parsers | KVS 22-12-2018 Part-B ] Which of the following are
language processor?
(a) Assembler and editor
(b) Compiler and word processor
(c) Only Assembler and compiler
O
IF
(d) Assembler,Compiler and Interpreter
185. [ Syntax-Directed-Translation | Nielit Scientific Assistance CS 15-10-2017 ] Syn-
thesized attribute can easily be simulated by an
(a) LL grammar
N
LD
O
IF
(a) (a)-(iii), (b)-(iv), (c)-(ii), (d)-(i)
(b) (a)-(iv), (b)-(iii), (c)-(ii), (d)-(i)
(c) (a)-(ii), (b)-(iv), (c)-(i), (d)-(iii)
N
(b) Scalability
(c) Capability
(d) Loading
M
191. [ Compilers | UGC NET CS 2017 Jan -paper-2 ] Consider the following state-
ments related to compiler construction :
I. Lexical Analysis is specified by context-free grammars and implemented by
pushdown automata.
II. Syntax Analysis is specified by regular expressions and implemented by finite-
state machine.
Which of the above statement(s) is/are correct ?
(a) Only I
(b) Only II
(c) Both I and II
LD
193. [ Linker-Loader | UGC NET CS 2016 Aug- paper-2 ] Which of the following are
the principles tasks of the linker?
I. Resolve external references among separately compiled program units.
II. Translate assembly language to machine code.
III. Relocate code and data relative to the beginning of the program.
IV. Enforce access-control restrictions on system libraries
(a) I and II
(b) I and III
(c) II and III
(d) I and IV
O
IF
194. [ Code-Optimization | UGC NET CS 2016 July- paper-2 ] In _______, the bodies
of the two loops are merged together to form a single loop provided that they do
not make any references to each other.
(a) Loop unrolling
N
195. [ Linker-Loader | UGC NET CS 2016 July- paper-2 ] Which of the following is
not typically a benefit of dynamic linking?
I. Reduction in overall program execution time.
II. Reduction in overall space consumption in memory.
III. Reduction in overall space consumption on disk.
M
(a) I and IV
(b) I only
(c) II and III
(d) IV only
196. [ Parsers | UGC NET CS 2016 July- paper-2 ] Which of the following is FALSE?
(a) The grammar S ! a Sb | bSa| SS| 2 , where S is the only non-terminal symbol
and 2 is the null string, is ambiguous.
LD
(d) that reorders operations to allow multiple computations to happen in parallel
198. [ Pre-Processor | UGC NET CS 2015 Jun- paper-2 ] The translator which per-
forms macro calls expansion is called:
(a) Macro processor
(b) Micro preprocessor
(c) Macro preprocessor
(d) Dynamic Linker
O
199. [ Parsers | UGC NET CS 2015 Jun- paper-2 ]
false?
Which one from the following is
IF
(a) LALR parser is Bottom up parser
(b) A parsing algorithm which performs a left to right scanning and a right most
deviation is RL (1)
(c) LR parser is Bottom up parser.
N
(d) In LL(1), the 1 indicates that there is a one - symbol look - ahead.
200. [ Phases-of-Compilers | UGC NET CS 2015 Jun- paper-2 ] Which phase of
compiler generates stream of atoms?
(a) Syntax Analysis
A
201. [ Assembler | UGC NET CS 2004 Dec-Paper-2 ] Which activity is not included
in the first pass of two pass assemblers ?
(a) Build the symbol table
(b) Construct the intermediate code
(c) Separate mnemonic opcode and operand fields
(d) None of the above
202. [ Code-Optimization | UGC NET CS 2004 Dec-Paper-2 ] Code optimization is
responsibility of :
(a) Application programmer
LD
(d) None of these
(e) A,B and C
204. [ Assembler | UGC NET CS 2004 Dec-Paper-2 ] In two pass assembler the
symbol table is used to store :
(a) Label and value
(b) Only value
(c) Mnemonic
(d) Memory Location O
205. [ Parsers | UGC NET CS 2005 Dec-Paper-2 ]
(a) Leftmost derivation
A Top-down Parser generates :
IF
(b) Rightmost derivation
(c) Rightmost derivation in reverse
(d) Leftmost derivation in reverse
N
(c) Editor
(d) Assembler
207. [ Assembler | UGC NET CS 2005 Dec-Paper-2 ] Which activities is not included
in the first pass of two pass assembler ?
M
LD
210. [ Symbol-Table | UGC NET CS 2005 june-paper-2 ] Symbol Table can be used
for :
(a) Checking type compatibility
(b) Suppressing duplication of error message
(c) Storage allocation
(d) All of these
O
211. [ Compilers | UGC NET CS 2006 Dec-paper-2 ] A compiler for a high level
language that runs on one machine and produces code for a different machine is
called :
(a) Optimizing
IF
(b) One pass compiler
(c) Cross compiler
(d) Multipass compiler
212. [ Parsers | UGC NET CS 2006 Dec-paper-2 ] The ’K’ in LR(R) cannot be :
N
(a) 0
(b) 1
(c) 2
A
LD
(a) LALR
(b) LR
(c) SLR
(d) LLR
217. [ Parsers | UGC NET CS 2006 June-Paper-2 ] The action of passing the source
program into the proper syntactic class is known as :
(a) Syntax analysis
(b) Lexical analysis
(c) Interpretation analysis
O
IF
(d) Uniform symbol generation
218. [ Run-Time-Environment | UGC NET CS 2006 June-Paper-2 ] The dynamic
binding occurs during the :
(a) Compile time
N
following :
(a) Shift step that advances in the input stream by K(K > 1) symbols and Reduce
step that applies a completed grammar rule to some recent parse trees, joining
them together as one tree with a new root symbol.
M
(b) Shift step that advances in the input stream by one symbol and Reduce step
that applies a completed grammar rule to some recent parse trees, joining them
together as one tree with a new root symbol.
(c) Shift step that advances in the input stream by K(K = 2) symbols and Reduce
step that applies a completed grammar rule to form a single tree.
(d) Shift step that does not advance in the input stream and Reduce step that
applies a completed grammar rule to form a single tree.
220. [ Parsers | UGC NET CS 2014 Dec-Paper-2 ] Which of the following is true ?
(a) Canonical LR parser is LR (1) parser with single look ahead terminal
(b) All LR(K) parsers with K > 1 can be transformed into LR(1) parsers.
(c) Both (A) and (B)
(d) None of the above
221. [ Symbol-table | UGC NET CS 2014 Dec-Paper-2 ] In a two-pass assembler,
symbol table is
(a) Generated in first pass
(b) Generated in second pass
(c) Not generated at all
LD
(d) Generated and used only in second pass
222. [ Debugger | UGC NET CS 2014 Dec-Paper-2 ] Debugger is a program that
(a) allows to examine and modify the contents of registers
(b) does not allow execution of a segment of program
(c) allows to set breakpoints, execute a segment of program and display contents
of register
(d) All of the above
O
223. [ Parsers | UGC NET CS 2014 June-paper-2 ] A grammar G is LL(1) if and only
if the following conditions hold for two distinct productions
A!a|b
IF
1. First ( a ) \ First ( b ) 6= { a} where a is some terminal symbol of the grammar.
2. First ( a ) \ First ( b ) 6= l
III. First ( a ) \ Follow (A) = F if l 2 First ( b )
N
(a) I and II
(b) I and III
(c) II and III
(d) I, II and III
A
224. [ Parsers | UGC NET CS 2014 June-paper-2 ] Which of the following suffices to
convert an arbitrary CFG to an LL(1) grammar ?
(a) Removing left recursion alone
M
LD
A! a | c
B! b | c
Where { S,A,B} is the set of non-terminals, { a,b,c} is the set of terminals.
Which of the following statement(s) is/are correct ?
S 1 : LR(1) can parse all strings that are generated using grammar G.
S 2 : LL(1) can parse all strings that are generated using grammar G.
229. [ Parsers | UGC NET CS 2018 JUNE Paper-2 ] A bottom-up parser generates :
(a) Leftmost derivation in reverse
(b) Right-most derivation in reverse
M
231. [ Grammars | UGC NET CS 2012 Dec-Paper-2 ] Given the following expressions
of a grammar
E!E*F/F+E/F
F ! F - F / id
Which of the following is true ?
LD
232. [ Parsers | UGC NET CS 2012 Dec-Paper-2 ] Which of the following is true while
converting CFG to LL(I) grammar ?
(a) Remove left recursion alone
(b) Factoring grammar alone
(c) Both of the above
(d) None of the above
S1: SLR uses follow information to guide reductions. In case of LR and LALR
parsers, the lookaheads are associated with the items and they make use of the left
context available to the parser.
S2: LR grammar is a larger subclass of context free grammar as compared to that
SLR and LALR grammars.
A
LD
(a) Program with wheels
(b) Independent from its authors
(c) Independent of platform
(d) None of the above
238. [ Symbol-Table | UGC NET CS 2011 June-Paper-2 ] Which of the following
permanent database that has an entry for each terminal symbol ?
(a) Literal table
(b) Identifier table
(c) Terminal table
O
IF
(d) Source table
239. [ Assembler | UGC NET CS 2011 June-Paper-2 ] In which way(s) a macro pro-
cessor for assembly language can be implemented ?
(a) Independent two-pass processor
N
S1 ) Sc ) SAC ) SaSbc
Thus, SaSbc is a right sentential form, and its handle is
(a) SaS
(b) bc
(c) Sbc
(d) aSb
242. [ Grammars | UGC NET CS 2013 June-paper-2 ] The equivalent production rules
corresponding to the production rules
LD
S!Sa 1 | S a 2 | b 1 | b 2 is
(a) S ! b 1 |b2,A!a1A|a2A|l
(b) S ! b 1 | b 2 | b 1 A | b 2 A, A ! a 1 A | a 2 A
(c) S ! b 1 |b2,A!a1A|a2A
(d) S ! b 1 | b 2 | b 1 A | b 2 A, A ! a 1 A | a 2 A | l
243. [ Parsers | UGC NET CS 2013 June-paper-2 ] Which is the correct statement(s)
for Non Recursive predictive parser ?
O
S1 : First( a ) = { t | a ) *t b for some string b } ) *t b
S2 : Follow(X) = { a | S) * a Xa b for some strings a and b }
IF
(a) Both statements S1 and S2 are incorrect.
(b) S1 is incorrect and S2 is correct.
(c) S1 is correct and S2 is incorrect.
(d) Both statements S1 and S2 are correct.
N
244. [ Macros | UGC NET CS 2010 Dec-Paper-2 ] ’Macro’ in an assembly level pro-
gram is _______.
(a) sub program
(b) a complete program
A
(c) Registers
(d) None of the above
247. [ Parsers | UGC NET CS 2010 June-Paper-2 ] Which of the following expression
is represented by the parse tree ?
LD
(a) (A + B) * C
(b) A + * BC
(c) A + B * C
(d) A * C + B
O
248. [ Compiler-Design | UGC NET CS 2010 June-Paper-2 ] Consider the following
IF
left associative operators in decreasing order of precedence :
- subtraction (highest precedence)
* multiplication
$ exponentiation (lowest precedence)
What is the result of the following expression ?
N
3 - 2 * 4 $ | * 2**3
(a) - 61
(b) 64
A
(c) 512
(d) 4096
249. [ Phases-of-Compilers | UGC NET CS 2010 June-Paper-2 ] Which of the follow-
ing is used for grouping of characters into tokens(in a computer)?
M
(a) A parser
(b) Code optimizer
(c) Code generator
(d) Scanner
250. [ Compilers | UGC NET CS 2009-June-Paper-2 ] A compiler that runs on one
machine and produces code for a different machine is called:
(a) Cross compilation
(b) One pass compilation
LD
252. [ Parsers | UGC NET CS 2009 Dec-Paper-2 ] Which of the following grammar is
LR (1) ?
(a) A ! a A b, A ! b A b, A ! a , A ! b
(b) A ! a A a, A ! a A b, A ! c
(c) A ! A + A, A ! a
(d) Both (A) and (B)
O
253. [ Syntax-Directed-Translation | UGC NET CS 2009 Dec-Paper-2 ] A shift-reduce
parser carries out the actions specified within braces immediately after reducing
with the corresponding rule of the grammar.
S ! x x W [ print "1"]
S ! y [ print "2"]
IF
W ! S2 [ print "3"]
what is the translation of "x x x x y z z" ?
(a) 1 1 2 3 1
N
(b) 1 1 2 3 3
(c) 2 3 1 3 1
(d) 2 3 3 2 1
A
(c) LR grammar
(d) None of the above
255. [ Assembler | UGC NET CS 2008 Dec-Paper-2 ] An assembly program contains
:
(a) imperative and declarative statements
(b) imperative statements and assembler directives
(c) imperative and declarative statements as well as assembler directives
(d) declarative statements and assembler directives
256. [ Assembler | UGC NET CS 2008 Dec-Paper-2 ] Which of the following are As-
sembler Directives ?
(i) EQU
(ii) ORIGIN
(iii) START
(iv) END
LD
(d) (i), (ii), (iii) and (iv)
257. [ Assembler | UGC NET CS 2008-june-Paper-2 ] Assembler program is :
(a) dependent on the operating system
(b) dependent on the compiler
(c) dependent on the hardware
(d) independent of the hardware
LD
(a) start address of the available main memory
(b) total size of the program
(c) actual address of the data location
(d) absolute values of the operands used
264. [ Parsers | UGC NET CS 2007-Dec-Paper-2 ] Top-down parsers are predictive
parsers, because :
(a) next tokens are predicted. O
(b) length of the parse tree is predicted beforehand
(c) lowest node in the parse tree is predicted.
IF
(d) next lower level of the parse tree is predicted.
265. [ Code-Optimization | UGC NET CS 2007-Dec-Paper-2 ] In the context of com-
piler design, "reduction in strength" refers to :
N
266. [ Parsers | UGC NET CS 2007 June-Paper-2 ] The parsing technique that avoids
backtracking is :
(a) Top - down parsing
M
268. [ Symbol-Table | UGC NET CS 2007 June-Paper-2 ] Symbol table can be used
for :
(a) Checking type compatibility
(b) Suppressing duplication of error message
(c) Storage allocation
(d) All of these above
269. [ Run-Time-Environment | UGC NET CS 2017 Nov- paper-3 ] Heap allocation
is required for languages that
(a) use dynamic scope rules
LD
(b) support dynamic data structures
(c) support recursion
(d) support recursion and dynamic data structures
270. [ Code-Optimization | UGC NET June-2019 CS Paper-2 ] Replacing the expres-
sion 4*2.14 by 8.56 is known as
(a) Constant folding
(b) Induction variable
(c) Strength reduction
(d) Code reduction
O
IF
271. [ Symbol-Table | UGC NET June-2019 CS Paper-2 ] Which data structure is
used by the compiler for managing variables and their attributes?
(a) Binary tree
(b) link list
N
(b) 6
(c) 3
(d) 7
II) Top-down parser works on left recursive, unambiguous and deterministic gram-
mar
LD
III) LL(I) is a non-recursive descent parser
(a) Only II
(c) ll and IV
(a) First(E)={ id, (,2 } ,follow(E)={ 2 ,) } , First(F)={ id,),$ } , Follow(F)={ *,$ ,(}
(c) First(E)={ id, (,2 } ,follow(E)={ 2 ,) } , First(F)={ id,)} , Follow(F)={ *,$ ,(,+ }
S-> (L)/a
L-> L.S/S
(a) 8
(b) 9
(c) 10
LD
(d) 11
278. [ Lexical-Analyzer | ISRO CS 2020 ] The number of tokens in the following C
code segment is
switch(inputvalue)
{
case 1;b=c*d; break;
Default : b = b++ ; break;
}
(a) 27
(b) 29
(c) 26
O
IF
(d) 24
279. [ Assembler | ISRO CS 2020 ] In a two-pass assembler, resolution of subroutine
calls and inclusion of labels in the symbol table is done during
(a) Second pass
N
282. [ Compilers | ISRO CS 2020 ] Which one indicate a technique of building cross
compilers?
(a) Beta cross
(b) Canadian cross
(c) Mexican cross
(d) X-cross
283. [ Parsers | ISRO CS 2020 ] Given the grammar
s! T*S | T
T!U+T|U
LD
U!a|b
Which of the following statements is wrong?
O
284. [ Parsers | APPSC-2016-DL-CS ] Consider the grammar with non-terminals N =
{ S,C,S1} , terminals T = { a,b,i,t,e} , with S as the start symbol, and the following
set of rules:
IF
S – > iCtSS1| a
S1 – > eS | *
C–>b
The grammar is NOT LL(1) because:
N
LD
287. [ Synthesized-and-L-Attribute | APPSC-2016-DL-CS ] In a bottom-up evalua-
tion of a syntax directed definition, inherited attributes can
(a) Always be evaluated
(b) Be evaluated only if the definition is L- -attributed
(c) Be evaluated only if the definition has synthesized attributes
(d) Never be evaluated
288. [ Parsers | APPSC-2016-DL-CS ]
state in shift-reduce parsing?
O Which one of the following is True at any valid
(a) Viable preflxes appear only at the bottom of the stack and not inside
(b) Viable prefixes appear only at the top of the stack and not inside
IF
(c) The stack contains only a set of viable prefixes
(d) The stack never contains viable prefixes
289. [ Parsers | CIL 2020 ] Consider the following grammar
N
S ! m | mn | mno
LD
(d) Canonical LR parser is more powerful than LALR parser
293. [ Parsers | CIL 2020 ] Which grammar rules violate the requirement of the oper-
ator grammar? A,B,C are variables and a,b,c are terminals.
I . A ! BC
I I . A ! CcBb
I I I . A ! BaC
IV . A ! 2
(a) I only
(b) I and II
(c) I and III
O
IF
(d) I and IV
294. [ Parsers | CIL 2020 ] Write true (T) / false (F) for each of the following state-
ments:
A. Symbol table is used only in the first phase of a compiler.
N
B. A pretty printer analyses a program and prints it in such a way that the struc-
ture of the program becomes early visible.
C. YACC build up LALR parsing table
D. If a grammar is LALR(1), it is not necessarily SLR(1)
(a) T T F T
A
(b) F T T T
(c) T T T F
(d) F T T F
M
S −−> AbBaCc | 2
A −−> aAb | ba
B −−> bBC | cb
C −−> cCa | ac
LD
(c) { a,2 }
(d) { a,b,c,2 }
297. [ Parsers | CIL 2020 ] The following grammar is:
S ! Aa | b Ac | dc | bda
A ! a
(b) Quadruples
(c) Indirect triples
(d) All will occupy same space
302. [ Compilers | TNPSC-2012-Polytechnic-CS ] Macro-expansion type parameter
passing is called as
(a) Call-by value
(b) Call-by reference
(c) Copy-restore
LD
(d) Call-by name
303. [ Ambiguous-and-Unambiguous-Grammar | TNPSC-2012-Polytechnic-CS ] A
given grammar is said to be ambiguous if
(a) Two or more productions have the same non-terminal on the left hand side
(b) A derivation tree has more than one associated sentence
(c) There is a sentence with more than one derivation tree corresponding to it
(b) Is a permanent table of division rules in the form of patterns for matching with
the uniform symbol table to discover syntactic structure
(c) Consists of full or partial list of the tokens as they appear in the program,
created by Lexical Analysis and used for syntax analysis and interpretation
(d) A permanent table which lists all key words and special symbols of the lan-
guage in symbolic form
307. [ Run-Time-Environment | APPSC-2012-DL-CS ] Heap allocation is required
for language
(a) That support recursion
LD
(d) Rightmost Derivation traced out in reverse
309. [ Phases-of-Compilers | APPSC-2012-DL-CS ] The output of a lexical analyzer
is
(a) Machine Code
(b) Intermediate Code
(c) A Stream of Tokens
(d) A Parse Tree O
310. [ Parsers | TNPSC-2017-Polytechnic-CS ] The grammar A! AA| (A)| 2 is not
suitable for predictive parsing because the grammar is:
IF
(a) Ambiguous
(b) Left - Recursive
(c) Right Recursive
N
(b) awk
(c) bison
(d) yacc
M
S ! L| a L ! LS | S
(a) S1 ! .S,$
S! .AS,$ / a/b
S! .b,$ /a/b
A! .SA, a/b
A! .a,a /b
(b) S1 ! .S,$
S! .AS,$ s/ b
S! .b,$ / b
LD
(c) S1 ! .S,$
S! .AS,$ / a/b
S! .AS,$ / a/b
S! .b,$ / a/b
(d) S1 ! .S,$
S! .AS,$
S! .b,$
O
314. [ Ambiguous-and-Unambiguous-Grammar | UGC NET CS 2014 June-paper-3 ]
Given the following two grammars :
G1 : S ! AB | aaB A ! a | Aa B ! b
IF
G2 : S ! a S b S | b S a S | l
x = x * (a + b) - 5;
(a) 12
(b) 11
(c) 10
(d) 07
LD
O
IF
N
A
M
(a) a
(b) b
(c) c
(d) d
(e) e
317. [ Parsers | TIFR PHD CS & SS 2012 ] Consider the parse tree
LD
Assume that * has higher precedence than +, - and operators associate right to left
(i.e. a + b + c =(a + (b + c))). Consider
(i) 2 + a - b
(ii) 2 + a - b * a + b
(iii) (2 + ((a - b) * (a + b)))
(iv) 2 + (a - b) * (a + b)
The parse tree corresponds to
(a) Expression (i)
(b) Expression (ii)
(c) Expression (iv) only
(d) Expression (ii), (iii) and (iv)
O
IF
(e) Expressions (iii) and (iv) only
318. [ Parsers | TIFR PHD CS & SS 2012 ] Which of the following correctly describes
LR(k) parsing?
(a) The input string is alternately scanned left to right and right to left with k
N
reversals.
(b) Input string is scanned once Left to Right with rightmost derivation and k
symbol look-ahead
(c) LR(k) grammers are expressively as powerful as context-free grammers.
A
Which of the following lexical entities can be derived from < word > ?
I. word
II. words
III. c22
(a) None of I, II or III
(b) I and II only
(c) I and III only
(d) II and III only
(e) I, II and III
LD
1.2 Solutions
LD
314. D
217. B 231. B 245. C 259. B 273. B 287. D 301. C
315. A
218. B 232. D 246. B 260. A 274. A 288. C 302. C
219. B 233. B 247. A 261. A 275. B 289. B 303. C 316. B
O
IF
N
A
M