# Recent questions and answers in Compiler Design

1
Consider the translation scheme shown below. S $\rightarrow$ T R R $\rightarrow$ + T {print(‘+’);} R$\mid \varepsilon$ 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 $9 + 5 + 2$ $9 \ 5 + 2 +$ $9 \ 5 \ 2 + +$ $+ + 9 \ 5 \ 2$
2
For a C program accessing $\mathbf{X[i] [j] [k]}$, the following intermediate code is generated by a compiler. Assume that the size of an integer is $32$ bits and the size of a character is $8$ bits. t0 = i ∗ 1024 t1 = j ∗ 32 t2 = k ∗ 4 t3 = t1 + t0 t4 = t3 + t2 t5 = X[t4] ... $\mathbf{X}$ is declared as "char $\mathbf{X[4] [32] [8]}$ . $\mathbf{X}$ is declared as "char $\mathbf{X[32] [16] [2]}$ .
3
Consider the grammar $S \rightarrow bSe$ $S \rightarrow PQR$ $P \rightarrow bPc$ $P \rightarrow \varepsilon$ $Q \rightarrow cQd$ $Q \rightarrow \varepsilon$ $R \rightarrow dRe$ $R \rightarrow \varepsilon$ where $S, P, Q, R$ are non-terminal symbols with $S$ being the start symbol ... $i, j, k, m$? Find the smallest string that has two parse trees.
4
The grammar $S\rightarrow AC\mid CB$ $C\rightarrow aCb\mid \epsilon$ $A\rightarrow aA\mid a$ $B\rightarrow Bb\mid b$ generates the language $L=\left \{ a^{i}b^{j}\mid i\neq j \right \}$. In this grammar what is the length of the derivation (number of steps starting from $S$) to generate the string $a^{l}b^{m}$ with $l\neq m$ $\max (l,m) + 2$ $l + m + 2$ $l + m + 3$ $\max (l,m) + 3$
5
In a compiler, keywords of a language are recognized during parsing of the program the code generation the lexical analysis of the program dataflow analysis
6
How to solve any dynamic scoping question . Plz describe in detail.
7
In a two-pass assembler, resolution of subroutine calls and inclusion of labels in the symbol table is done during second pass first pass and second pass respectively second pass and first pass respectively first pass
1 vote
8
In operator precedence parsing we have the rule that production cannot have two adjacent non-terminals or an epsilon production, so this production, S--> ab is allowed but not S--> AB, A->a and B->b, though they are giving us the same output. Why so?
9
Which of the following is machine independent optimization? Loop optimization Redundancy Elimination Folding All of the option
1 vote
10
How will the compiler detect whether "if" is a keyword or an identifier? Please tell me the concept behind this.
11
fro(int I=0; I <5;I++); what kind of compilation error is this ?
1 vote
12
A given grammar is called ambiguous if two or more productions have the same non-terminal on the left hand side a derivation tree has more than one associated sentence there is a sentence with more than one derivation tree corresponding to it brackets are not present in the grammar
13
In a compiler, keywords of a language are recognized during parsing of the program the code generation the lexical analysis of the program dataflow analysis
14
The identification of common sub-expression and replacement of run time computations by compile-time computations is: Local optimization Constant folding Loop Optimization Data flow analysis
15
16
I think answer should be 13. We got 13 tokens printf ( "string" ++ & & * * * a ) ;
17
Which of the following is the most general phase-structured grammar? (a) regular (b) context-free (c) context-sensitive (d) none of the above
18
19
20
21
int main() { int 1a, b; Printf("\nGate 2018"); Printf("%d",x); } How many types of error are there in this code?
22
23
Every LL(1) grammar is ______ A.SLR(1) B.LALR(1) C.LR(1) D.Both B & C
24
grammar is CLR(1) or not? if yes then how?
25
I know the parsing logic of bottom up parsers, that they start from the terminal and reduce it to the start symbol. But what really confuses me is the construction of LR(0)/LR(1) sets : Eg : S->Sa|a Then in LR(0) set : S'->.S S->.Sa S->.a Now the dot is in front of S , so shouldn't the S production be generated again and again and make it go to an inf. loop?
26
Consider the following grammar (the start symbol is $E$) for generating expressions. $E \rightarrow T - E \mid T + E \mid T$ $T \rightarrow T * F \mid F$ $F \rightarrow 0 \mid1\mid 2\mid 3\mid 4\mid 5\mid 6\mid 7\mid 8\mid 9$ With respect to this grammar, which of the following trees is the valid evaluation tree for the expression $2*3*4 - 5*6+7$?
27
Every LL(1) grammer is LALR(1) TRUE OR FALSE Every LL(1) grammer is CLR(1) TRUE OR FALSE AS I think 2nd is True and 1st is False if I am wrong please let me correct.
28
Consider the grammar given below S⟶ SS | a | ∈ The number of inadequate states in the DFA of LR(1) items is (a) 1 (b) 2 (c) 3 (d) 4
29
The output of lexical analyzer is: A set of regular expressions Strings of character Syntax tree Set of tokens
30
In two pass assembler the symbol table is used to store : Label and value Only value Mnemonic Memory Location
31
In a single pass assembler, most of the forward references can be avoided by putting the restriction on the number of strings/lifereacts. that the data segment must be defined after the code segment. on unconditional rump. that the data segment be defined before the code segment.
32
A top down parser generates Left most derivation Right most derivation Left most derivation in reverse Right most derivation in reverse
33
Which of the following statement(s) regarding a linker software is/are true ? A function of a linker is to combine several object modules into a single load module. A function of a linker is to replace absolute references in an object module by symbolic references to locations in other modules. Only I Only II Both I and II Neither I nor II
34
Consider the following statements related to compiler construction: Lexical Analysis is specified by context-free grammars and implemented by pushdown automata. Syntax Analysis is specified by regular expressions and implemented by finite-state machine. Which of the above statement(s) is/are correct? Only I Only II Both I and II Neither I nor II
35
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\to\epsilon$ and $A \to a)$ to parse a string with $n$ tokens? $n/2$ $n-1$ $2n-1$ $2^n$
1 vote
36
Rewrite the following SDT: $A\rightarrow A\{a\}B\mid AB\{b\}\mid 0$ $B\rightarrow B\{c\}A\mid BA\{d\}\mid 1$ so that the underlying grammar becomes non-left-recursive. Here, $a, b, c$, and $d$ are actions, and $0$ and $1$ are terminals.
1 vote
37
https://gateoverflow.in/43605/gate1991-10c in the answer given .....it will generate a parenthesis like (id - id / id) right? will not that be redundant ?
The least number of temporary variables required to create a three-address code in static single assignment form for the expression $q + r / 3 + s - t * 5 + u * v/w$ is__________________.
Construct a syntax-directed translation scheme that translates arithmetic expressions from infix notation into prefix notation in which an operator appears before its operands; e.g., $-xy$ is the prefix notation for $x - y$. Give annotated parse trees for the inputs $9-5+2$ and $9-5*2$.