Professional Documents
Culture Documents
In a single pass assembler, most of the forward references can be avoided by putting the restriction
a) On the number of strings/life reacts
b) Code segment to be defined after data segment
c) On unconditional rump
d) None of the mentioned
Answer b
Answer: A
7. Pass I
a) Assign address to all statements
b) Save the values assigned to all labels for use in pass 2
c) Perform some processing
d) All of the mentioned
ANSWER D
8. Which table is a permanent database that has an entry for each terminal symbol?
a) Terminal Table
b) Literal Table
c) Identifier Table
d) None of the mentioned
ANSWER A
8. The table created by lexical analysis to describe all literals used in the source
program is
a) Terminal table
b) Literal table
c) Identifier table
d) Reductions
Answer: b
10. Which is not true about syntax and semantic parts of a computer language?
a) Semantics is checked mechanically by a computer
b) Semantics is the responsibility of the programmer
c) All of the mentioned
d) None of the mentioned
Answer: d
2. Which of the following statement is true?
a) SLR powerful than LALR
b) LALR powerful than Canonical LR parser
c) Canonical LR powerful than LALR parser
d) The parsers SLR= Canonical LR=LALR
ANSWER Answer: c
ANSWER D
6. The graph that shows basic blocks and their successor relationship is called
a) Dag
b) Flow Graph
c) Control Graph
d) Hamilton Graph
Answer: b
Answer: c
Answer: a
Answer: c
Answer: c
4. Scissoring enables
a) A part of data to be displayed
b) Entire data to be displayed
c) Full data display on full screen
d) No data to be displayed
Answer: a
Answer: b
Answer: b
ANSWER A
8. Which of the following module does not incorporate initialization of values changed by
the module?
a) Non reusable module
b) Serially reusable module
c) Re-enterable module
d) All of the mentioned
Answer: a
Answer: d
10. The best way to compare the different implementations of symbol table is to compare
the time required to
a) Add a new name
b) Make an enquiry
c) Add a new name and make an enquiry
d) All of the mentioned
ANS D
3. S -> C C
C -> eC | d
The grammar is
a) LL (1)
b) SLR (1) but not LL (1)
c) LALR (1) but not SLR (1)
d) LR (1) but not LALR (1)
Answer: c
4. S -> id: = E ”
newtemp ();
gen(t . place . place;); .place t} ”
.place .place;}
For the statement ‘X: = Y + Z ’,
the 3-address code sequence generated by this definition is
a) X = Y + Z
b) t1 = Y + Z; X t1
c) t1 = Y; t2 = t1 + Z; X = t2
d) t1 = Y; t2 = Z; t3 + t2; X = t3
Answer d
5. If the programming language uses static scoping and call by need parameter passing
mechanism, the values printed by the above program are
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105
Answer d
6. If dynamic scoping is used and call by name mechanism is used, the values printed
will be
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105
Answer b
7.
P x =new Q();
Q y =new Q();
P z =new Q();
x. f (1);((P) y). f (1);
z.f(1);
The output is
a) 1 2 1
b) 2 1 1
c) 2 1 2
d) 2 2 2
Answer:d
7. Which of the following is NOT an advantage of using shared, dynamically linked
libraries as compared to statically linked libraries?
a) Smaller sizes of executable
b) Lesser overall page fault rate in the system
c) Faster program start-up
d) Existing programs need not be re-linked to take advantage of newer versions of
libraries
Answer c
Answer: b
Answer: b
3. S -> (S)| a
Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar n1
n2 and n3 respectively.
a) n1 < n2 < n3
b) n1 = n3 < n2
c) n1 = n2 = n3
d) n1 $ n3 $ n2
Answer b
Int main()
{ int 1,N;
Fro (I,1 N,1);
}
Identify the compiler’s response about this line while creating the object-module
a) No compilation error
b) Only a lexical error
c) Only syntactic errors
d) Both lexical and syntactic errors
Answer c
4. 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
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
Answer: c
5. 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 ‘x’ is higher than that of ‘+’, and both operators are left
associative; expression is evaluated to 7
d) Precedence of ‘ # ‘ is higher than that of ‘#’, and both operators are left
associative; expression is evaluated to 9
Answer: B
6. In the predictive parser table, M , of the grammar the entries M [ S, id] and M [
R,$] respectively
a) {S ” FR} and {R ” ε}
b) {S ” FR} and {}
c) {S ” FR} and {R ” * S}
d) {F ” id} and {R ” ε}
Answer : A
Consider the following LR(0) items corresponding to the grammar above
(i) S -> S * .E
(ii) E -> F . + E
(iii) 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?
a) (i) and (ii)
b) (ii) and (iii)
c) (i) and (iii)
d) None of these
Answer c
Here id is a taken that represents an integer and id. value represents the
corresponding integer value. For an input ‘2 * 3 + 4’, this translation scheme
prints
a) 2 * 3 + 4
b) 2 * + 3 4
c) 2 3 * 4 +
d) 2 3 4 + *
Answer b
Answer d
Answer b
3. S->bA S->aB
A->a B->b
A->aS B->bS
A->bAA B->aBB
Which of the following strings is generated by the grammar?
a) aaaabb
b) aabbbb
c) aabbab
d) abbbba
Answer c
4. S->bA S->aB
A->a B->b
A->aS B->bS
A->bAA B->aBB
Answer d
6. Some code optimizations are carried out on the intermediate code because
a) They enhance the portability of the complier to other target processors
b) Program analysis is name accurate on intermediate code than on machine
code
c) The information from data flow analysis cannot otherwise be used for
optimization
d) The information from the front end cannot otherwise be used for optimization
Answer: b
Answer a
8. An LALR(1) parser for a grammar can have shift-reduce (S-R) conflicts if and only
if
a) The SLR(1) parser for G has S-R conflicts
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
Answer: b
Answer: b
10. What data structure in a complier is used for managing information about
variables and their attributes?
a) Abstract syntax tree
b) Symbol table
c) Semantic stack
d) Parse table
Answer: b
1. Which languages necessarily need heap allocation in the runtime
environment?
a) Those that support recursion
b) Those that use dynamic scoping
c) Allow dynamic data structure
d) Those that use global variables
Answer: c
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a
grammar with no epsilon- and unit-production (i.e., of type A -> є and A -> a) to parse a string
with n tokens?
Ans n-1
Ans 1, 2, 3, and 4
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. is the empty string, $ indicates
end of input, and, | separates alternate right hand sides of
productions.
Answer A
Consider the date same as above question. The appropriate entries for E1, E2, and E3
are
Answer C
Match all items in Group 1 with correct options from those given in Group 2.
Group 1 Group 2
P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
S. Register allocation 4. Code optimization
Answer
Answer I and IV
It is the production p that will be used for reduction in the next step along with a position
in the sentential form where the right hand side of the production may be found
An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if
Answer the LR(1) parser for G has S-R conflicts
Answer it is ambiguous
Consider the grammar defined by the following production rules, with two operators ∗
and +
S --> T * P
T --> U | T * U
P --> Q + P | Q
Q --> Id
U --> Id
Answer 2 3 4+*
The grammar A → AA | (A) | ε is not suitable for predictive-parsing because the grammar is
Answer ambiguous
Answer n1 = n3 < n2
Consider the following expression grammar. The semantic rules for expression
calculation are stated next to each grammar production.
E → number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val
The above grammar and the semantic rules are fed to a yacc tool (which is an 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?
Answer It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce
action
Consider the following expression grammar. The semantic rules for expression
calculation are stated next to each grammar production.
E → number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val
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?
Answer Equal precedence and right associativity; expression is evaluated to 9
Which of the following grammar rules violate the requirements of an operator grammar
? P, Q, R are nonterminals, and r, s, t are terminals.
1. P → Q R
2. P → Q s R
3. P → ε
4. P → Q t R r
Consider the grammar with the following translation rules and E as the start symbol.
E → E1 # T { E.value = E1.value * T.value }
| T{ E.value = T.value }
T → T1 & F { T.value = T1.value + F.value }
| F{ T.value = F.value }
F → num { F.value = num.value }
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4.
Answer 160
Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2
states. The relationship between n1 and n2 is:
Answer n1 is necessarily equal to n2
Answer 9 5 + 2 +
Answer t1 = Y + Z; X = t1
Which one of the following is True at any valid state in shift-reduce parsing?
Answer The stack contains only a set of viable prefixes
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the
following is True?
Answer The maximum number of successors of a node in an AST and a CFG depends on the
input program
Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A}
and terminals {a, b}}. Using the above SDTS, the output
printed by a bottom-up parser, for the input aab is
Answer 2 3 1
Which one of the following grammars is free from left recursion?
Answer B
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal
and a and b are terminals.
S→aS∣A
A→aAb∣bAa∣ϵ
For the correct answer in Q75, how many steps are required to derive the string and how many
parse trees are there?
Answer 6 and 1
Answer a
Which of the following is essential for converting an infix expression to the postfix from efficiently
?
Answer An operator stack
Answer
Consider the following parse tree for the expression a#b$c$d#e#f, involving two binary
operators $ and #.
Answer $ has higher precedence and is left associative; # is right associative
Match the description of several parts of a classic optimizing compiler in List - I, with the names
of those parts in List -
II:
Answer (1)
Consider the following statements 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 ?
Which of the following statement(s) regarding a linker software is/are true ? I A function of a
linker is to combine several object modules into a single load module. II A function of a linker is
to replace absolute references in an object module by symbolic references to locations in other
modules.
Answer Only I
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 → ε
Answer 1 and 4 only
A parsing algorithm which performs a left to right scanning and a right most deviation is RL (1)
How many tokens will be generated by the scanner for the following statement ? x = x ∗ (a + b)
– 5;
Answer 12
Incremental-Compiler is a compiler
Answer compiles only those portion of source code that have been modified.