# Recent questions and answers in Compiler Design

1 vote
1
For a statement $S$ in a program, in the context of liveness analysis, the following sets are defined: $\text{USE}(S)$ : the set of variables used in $S$ $\text{IN}(S)$ : the set of variables that are live at the entry of $S$ $\text{OUT}(S)$ : the set of variables that are live at the ... $) }\cup \text{ OUT ($S_2$)}$ $\text{OUT ($S_1$)} = \text{USE ($S_1$)} \cup \text{IN ($S_2$)}$
2
Linking : cannot be performed before relocation cannot be performed after relocation can be performed both before and after relocation is not required if relocation is performed
3
Whether LR(1) grammar is same as that of CLR(1) grammar. If yes then please explain and if not then what is the difference between them?
4
State whether the following statements are True or False with reasons for your answer: A two pass assembler uses its machine opcode table in the first pass of assembly.
5
State whether the following statements are True or False with reasons for your answer A subroutine cannot always be used to replace a macro in an assembly language program.
6
State whether the following statements are True or False with reasons for your answer A symbol declared as ‘external’ in an assembly language program is assigned an address outside the program by the assembler itself.
7
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 \rightarrow \epsilon$ and $A \rightarrow a$) to parse a string with $n$ tokens? $n/2$ $n-1$ $2n-1$ $2^{n}$
8
Let $G_1 = (N, T, P, S_1)$ be a CFG where, $N=\{S_1, A, B\},T=\{a, b\}$ and $P$ ... $5$ production rules. Is $L_2$ inherently ambiguous?
9
Which of the Statements are True : S1: LR(1) grammar can be LR(0) but not LL(1). S2 : Every regular language is LL(1) S3 : Three address code is linear representation of Syntax Tree.
10
Consider the following statements. $S_1:$ The sequence of procedure calls corresponds to a preorder traversal of the activation tree. $S_2:$ The sequence of procedure returns corresponds to a postorder traversal of the activation tree. Which one of the following options is correct? $S_1$ is true and ... $S_2$ is true $S_1$ is true and $S_2$ is true $S_1$ is false and $S_2$ is false
11
Match the following with respect to activation record fields: A 1 → A, D; 2 → B, C B 1 → A, C; 2 → B, D C 1 → B, C; 2 → A, D D 1 → B, D; 2 → A, C Doubt:- Control link points to caller activation record.Can some one confirm?
12
int main() { int 1a, b; Printf("\nGate 2018"); Printf("%d",x); } How many types of error are there in this code?
1 vote
13
14
1 vote
15
Every LL(1) grammar is ______ A.SLR(1) B.LALR(1) C.LR(1) D.Both B & C
16
What is the value of $X$ printed by the following program? program COMPUTE (input, output); var X:integer; procedure FIND (X:real); begin X:=sqrt(X); end; begin X:=2 FIND(X); writeln(X); end. $2$ $\sqrt{2}$ Run time error None of the above
17
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?
18
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
19
Consider the grammar rule $E \rightarrow E1 - E2$ for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction operation requires the first operand to be in the register. If $E1$ and $E2$ do not have any com­mon ... first Evaluation of $E1$ and $E2$ should necessarily be interleaved Order of evaluation of $E1$ and $E2$ is of no consequence
20
This screenshot is token from the book Ullman, How can following be a lexical error? because "elipseSize" should have a token recorded as an identifier.
21
if there is miss spelling in some keyword in a program then this misspelled keyword will be treated as lexical errors or it will be treated as a new identifier and accepted as a token ?? ex - whiel (1) ; here while is misspelled as whiel
22
Consider the following $\text{ANSI C}$ program: int main () { Integer x; return 0; } Which one of the following phases in a seven-phase $C$ compiler will throw an error? Lexical analyzer Syntax analyzer Semantic analyzer Machine dependent optimizer
1 vote
23
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation $\text{(SDT)}$ ... The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions. The actions will lead to an infinite loop
24
In the context of compilers, which of the following is/are $\text{NOT}$ an intermediate representation of the source program? Three address code Abstract Syntax Tree $\text{(AST)}$ Control Flow Graph $\text{(CFG)}$ Symbol table
25
Consider the following context-free grammar where the set of terminals is $\{a,b,c,d,f\}$ ... $\boxed{1}\;\text{blank} \qquad \boxed{2}\;\text{S} \rightarrow \text{R}f \qquad \boxed{3}\; \text{blank} \qquad \boxed{4}\;\text{blank}$
1 vote
26
Consider the following statements. $S_1:$ Every $\text{SLR(1)}$ grammar is unambiguous but there are certain unambiguous grammars that are not $\text{SLR(1)}$. $S_2:$ For any context-free grammar, there is a parser that takes at most $O(n^3)$ time to parse a string of length $n$. ... $S_2$ is false $S_1$ is false and $S_2$ is true $S_1$ is true and $S_2$ is true $S_1$ is false and $S_2$ is false
1 vote
27
Consider the following $C$ code segment: a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f; In a compiler, this code segment is represented internally as a directed acyclic graph $\text{(DAG)}$. The number of nodes in the $\text{DAG}$ is _____________
28
Consider the following $\text{ANSI C}$ code segment: z=x + 3 + y->f1 + y->f2; for (i = 0; i < 200; i = i + 2) { if (z > i) { p = p + x + 3; q = q + y->f1; } else { p = p + y->f2; q = q + x + 3; } } Assume that the variable $y$ points to ... the form $\textsf{ y ->f1}$ or $\textsf{y ->f2}$) in the optimized code, respectively, are: $403$ and $102$ $203$ and $2$ $303$ and $102$ $303$ and $2$
29
Consider the following augmented grammar with $\{ \#, @, <, >, a, b, c \}$ ... $I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\})$. The number of items in the set $\text{GOTO(GOTO}(I_0<), <)$ is ___________
1 vote
30
Consider the following SDT, S → M {PRINT “2”;} A M → 1 {PRINT “ ”;} A → D {PRINT “1”;} E D → 2 {PRINT “ ”;} E → E {PRINT “ ”;} A E → 3 {PRINT “ ”;} A → S {PRINT “4”;} Y S → 4 {PRINT “ ”;} Y → ∈ {PRINT “ ”;} If the bottom up parsing is used to parse the input string “1234” then the output number produced (without any spaces) is _______
31
The number of tokens in following program? # define M 100 int main ( ) { // declare variables int n = 2020; return n % M; } Your Answer:19 Correct Answer: 16 Status: incorrect
32
Consider the grammar with the following productions. S→aaB/aaC B→b C→c Which of the following option is true ? (A) The grammar is LL(3) (B) The grammar is LL(1) (C) The grammar is LL(2) (D) It can’t be LL(k) grammar for any k, as it contains left factoring.
33
Which of the following is not an intermediate code form? Syntax trees Three address codes Quadrupules Post fix Notation
34
Which of the following are applications of symbol table? Storage allocation Checking type compatibility Suppressing duplicate error messages Choose the correct answer from the options given below: $(a)$ and $(b)$ only $(a)$ and $(c)$ only $(b)$ and $(c)$ only $(a)$ $(b)$ and $(c)$
35
Find the lexicographic ordering of the bit strings given below based on the ordering $0<1$. $001$ $010$ $011$ $0001$ $0101$ Choose the correct answer from the options given below: $001 < 010 < 011 < 0001 < 0101$ $0001 < 001 < 010 < 0101 < 011$ $0001 < 0101 < 001 < 010 < 011$ $001 < 010 < 0001 < 0101 < 011$
36
Which of the following can be accessed by transfer vector approach of linking? External data segments External subroutines Data located in other procedure All of these
37
The most powerful parser is $\text{SLR}$ $\text{LALR}$ Canonical $\text{LR}$ Operator-precedence
$\text{YACC}$ builds up $\text{SLR}$ parsing table Canonical $\text{LR}$ parsing table $\text{LALR}$ parsing table None of these
Context-free grammar can be recognized by finite state automation $2$- way linear bounded automata push down automata both (B) and (C)