Test 1 Compiler Design | Computer Science
Description: GATE Previous year Topic Wise Questions and Answers | Compiler Design | |
Number of Questions: 29 | |
Created by: Aliensbrain Bot | |
Tags: Compiler Design GATE CS |
Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
In a bottom-up evaluation of a syntax directed definition, inherited attributes can
Which of the following statements is FALSE?
Consider the grammar shown below. S $\rightarrow$ C C C $\rightarrow$ c C | d This grammar is
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for that grammar has n2 states. Which of the following statements about the relationship between n1 and n2 is true?
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions. global int i = 100, j = 5; void P(x) { int i = 10; print(x + 10); i = 200; j = 20; print (x); } main() {P(i + j);}
If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions. global int i = 100, j = 5; void P(x) { int i = 10; print(x + 10); i = 200; j = 20; print (x); } main() {P(i + j);}
If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are
Consider the translation scheme shown below. S $\rightarrow$T R R $\rightarrow$ + T {print('+');} R|$\epsilon$ T $\rightarrow$ num {print (num.val);} Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will print
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries?
Consider the following translation scheme. S$\rightarrow$ER R$\rightarrow$E {print (''); R}$\epsilon$ E $\rightarrow$F + E {print ('+');} F F$\rightarrow$ (S) | id {print (id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4', this translation scheme prints
Consider the following grammar. S $\rightarrow$S * E S $\rightarrow$E E $\rightarrow$F + E E $\rightarrow$F F $\rightarrow$id Consider the following LR (0) items corresponding to the grammar above. (i) S $\rightarrow$ S *.E (ii) E $\rightarrow$ F. + E (iii) E $\rightarrow$ 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?
In the correct grammar above, what is the length of the derivation (number of steps starring from S) to generate the string al bm with l $\ne$ m?
Which one of the following is a top-down parser?
Some code optimizations are carried out on the intermediate code because
Consider the following grammar: S $\rightarrow$FR R$\rightarrow$* S|$\epsilon$ F$\rightarrow$id In the predictive parser table, M, of the grammar the entries M [S, id] and M [R,$] respectively.
Consider the following two statements: P: Every regular grammar is LL(1) Q: Every regular set has a LR(1) grammar Which of the following is TRUE?
Consider the syntax directed definition shown below, S $\rightarrow$ id : = E {gen (id.place = E.place;);} E $\rightarrow$ E1 + E2 {t = newtemp( ); gen(t = E1.place + E2.place;); E.place = t;} E $\rightarrow$ id {E.place = id.place;}
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
An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if
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:
S $\rightarrow$iCtSS1 | a S1 $\rightarrow$ eS |$\epsilon$ C $\rightarrow$ b
The grammar is NOT LL(1) because:
Which of the following are true? I. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions III. Recursion in programming languages cannot be implemented with dynamic storage allocation IV. Nesting procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation 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
Consider the following class definitions in a hypothetical Object Oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, though the syntax is similar.
Class P {
Class Q subclass of P {
void f(int i) {
void f(int i) {
print(i);
print(2 * i);
}
}
}
}
Now consider the following program fragment: Px = new Q() Qy = new Q(); Pz = new Q(); x.f(1); ((P)y).f(1); z.f(1); Here ((P)y) denotes a typecast of y to P. The output produced by executing the above program fragment will be
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$\rightarrow$ a B S $\rightarrow$bA B $\rightarrow$b A$\rightarrow$ a B $\rightarrow$bS A $\rightarrow$aS B $\rightarrow$aBB S$\rightarrow$ bAA
Which of the following strings is generated by the grammar?
Which of the following describes a handle (as applicable to LR-parsing) appropriately?
Which of the following statements are TRUE? I. There exist parsing algorithms for some programming languages whose complexities are less than $\theta$(n3). II. A programming language which allows recursion can be implemented with static storage allocation. III. No L-attributed definition can be evaluated in the framework of bottom-up parsing. IV. Code improving transformations can be performed at both source language and intermediate code level.
Which one of the following grammars generates the language L = {ai bj i ¹ j}?
In a simplified computer the instructions are: OP Rj , Ri - Performs Rj OP Ri and stores the result in register . Ri OP m, Ri - Performs val i OP Ri and stores the result in Ri. val denotes the content of memory location m. MOV m, Ri - Moves the content of memory location m to register Ri MOV Ri , m - Moves the content of register Ri to memory location m. The computer has only to registers, and OP is either ADD or SUB. Consider the following basic block: t1 = a + b t2 = c + d t3 = e - t2 t4 = t1 - b Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
Consider the following C code segment.
for (i - 0, i < n; i++) {
for (j = 0; j < n; j++) {
if (i % 2) {
x += (4 * j + 5 * i);
y += (7 + 4 * j);
}
}
}
Which one of the following is false?
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 $\rightarrow$ aB S $\rightarrow$ bA B $\rightarrow$ b A $\rightarrow$ a B $\rightarrow$ bS A $\rightarrow$ aS B $\rightarrow$ aBB S $\rightarrow$ bAA
How many derivation trees are there?
Consider the grammar shown below S $\rightarrow$i E t S S' | a S' $\rightarrow$ e S |$\epsilon$ E $\rightarrow$ b In the predictive parse table, M, of this grammar, the entries M[S' , e] and M[ S' ,$] respectively area