0

Compiler Design

Attempted 0/25 Correct 0 Score 0

Identify the odd one out.

  1. Global common subexpression

  2. Copy propagation

  3. Register allocation

  4. Code motion


Correct Option: C
Explanation:

a, b and d are ways of code optimization, register allocation happens in code generation stage, so the option c is the odd one.

Number of states for a grammar in SLR parser and LALR is

  1. double of the other

  2. somewhat dependent on each other

  3. independent

  4. dependent on grammar


Correct Option: B
Explanation:

LALR parsers offer many of the advantages of SLR and canonical - LR parsers, by combining the states that have the same kernels (sets of items, ignoring the associated look ahead sets). In this, the number of states is the same or that of the SLR parser.   

Match the following. (Choose the most appropriate option) (A) S – Attributed Definition (i) Synthesized attribute (B) L _ Attributed Definition (ii) Inherited attributed

  1. A – i, B – ii

  2. A – ii, B – i

  3. A – i, B – i, B – ii

  4. A – i, B – ii, A – ii


Correct Option: C
Explanation:

In an S – attributed syntax directed translation all attributes are synthesized. In an L – attributed definition attributes may be inherited or synthesized.

Consider the following grammar:A $\rightarrow$ BCC $\rightarrow$ +$A| \epsilon$B $\rightarrow$ id In the predictive parser table, m, of grammar the entire M [A, id] and M [C, $] respectively, is

  1. {A $\rightarrow$ BC} and {C $\rightarrow$$\epsilon$}

  2. {A $\rightarrow$ BC} and { }

  3. {A $\rightarrow$ BC} and {C $\rightarrow$+A}

  4. {B $\rightarrow$ id} and {C $\rightarrow$ $\epsilon$}


Correct Option: C
Explanation:

First (A) = first (B) = id     First (C) = {+, $\epsilon$}$\therefore$ For the production A$\rightarrow$ BC, as terminal id is in the first (A), M [A, id] = {A $\rightarrow$ BC}As $\epsilon$ is in first (C), M [C, \$] = {C$\rightarrow$+A} 

Expression corresponding to this DAG is

  1. a + a * (b - c) + (b - c) *d

  2. a + a × (b - c) + (b - c) * (e/f)

  3. a*a + (b - c) + (b - c) * (e/f)

  4. a + a* (b - c) + (b + c) * (e/f)


Correct Option: B
Explanation:

The grammar E $\rightarrow$E + E |E*E|(E)| id is

  1. left recursive

  2. ambiguous

  3. both (1) and (2)

  4. none of these


Correct Option: C
Explanation:

E$\rightarrow$E + Eand E$\rightarrow$E*E are left recursive. This grammar permits two distinct leftmost derivations for the sentence id + id *idE$\Rightarrow$E + E                      E$\Rightarrow$E*E  $\Rightarrow$id + E                        $\Rightarrow$E + E*E  $\Rightarrow$id + E*E                  $\Rightarrow$id + E*E  $\Rightarrow$id + id*E                  $\Rightarrow$id + id*E  $\Rightarrow$id + id*id                  $\Rightarrow$id + id*ESo it is ambiguous also.

Which of the following statements is false about viable prefixes?

  1. SLR passing is based on the fact that LR(0) automata recognize viable prefixes.

  2. It is always possible to add terminal symbols to the end of a viable prefix to obtain a right- sentential form.

  3. Both (1) and (2)

  4. None of the above


Correct Option: C
Explanation:

Explanation  A viable prefix is a prefix of a right sentential form that does not continue part the right end of the right handle of that sentential form. By this definition, b is true. Option 'a' is the basic property of SLR passing. So option 'a' and 'b' are true.Incorrect answer (b):  This option is eliminated because the concept is not correct. Incorrect answer (c): This option is eliminated because the concept is not correct.Incorrect answer (d): Not possible.

Which of the following is generally not present in activation record?

  1. Access link

  2. List of all processes in system

  3. Saved machine status

  4. Control link


Correct Option: B
Explanation:

List of all processes in system is not present in activation record.

Match the following.

 
i. Token a. Character i, f, letter followed by latter and digits etc
ii. Pattern b. if, id, comparison
iii. Lexeme c. if, pi, < =
  1. i – b, ii – a, iii – c

  2. i – b, ii – c, iii – a

  3. i – c, ii – a, iii – b

  4. i – c, ii – b, iii - a


Correct Option: A
Explanation:

The token name is on abstract symbol representing a kind of lexical unit i.e. a particular keyword or a sequence of input characters denoting on identifier. A pattern is a description of the form that the lexeme of a token may take. A lexeme is a sequence of characters that matches pattern of a token.

A$\rightarrow$BCC $\rightarrow$ + B {print ('+'); }C|$\epsilon$ B$\rightarrow$ D* B {print ('*')i}|D D$\rightarrow$ (A)|id {print (id.value); } For an input '5 + 6*7' this translation scheme prints

  1. 5 + 6 *7

  2. 5 + *6 7

  3. 5 6 + 7*

  4. 5 6 7 *+


Correct Option: D
Explanation:

Explanation                 = 5 + 6   7= id + id * id= D + D * D                                       print 5 6 7= D + D * B                                       print 5 6 7$\because B \rightarrow D * B, C \rightarrow \epsilon$=D + B C                 print 5 6 7* +                                   = B C                                    = A

Consider the following statements. (i) Every SLR (1) grammar is unambiguous (ii) There are many unambiguous grammars that are not SLR (1)

  1. i - True, ii - True

  2. i - True, ii - False

  3. i - False, ii - True

  4. i - False, ii - False


Correct Option: A
Explanation:

Basic properties of SLR (1) grammar of both of them are true.

Eliminate left recursion S $\rightarrow$ Aa|b A $\rightarrow$Ac|Sd|f

  1. $S \rightarrow Aa | b \\ A \rightarrow bdA'| fA' \\A | \rightarrow cA'| adA'| \epsilon$

  2. $S \rightarrow Aa | b \\ A \rightarrow cdA'| dA' \\ A' \rightarrow bA'| adA' |\epsilon $

  3. $S\rightarrow Aa|b \\ A\rightarrow bdA'|fA'$

  4. $S \rightarrow Aa| b$ $A \rightarrow bdA'|fA'$ $A'\rightarrow cA'|adA'$


Correct Option: A
Explanation:

$A\rightarrow Ac|Sd|f \rightarrow Ac|Aad|bd|f $ Eliminating the immediate left recursion in A $A \rightarrow bdA'| fA'$ $A| \rightarrow |adA' | \epsilon$ So the resulting grammar is option A.   

Computer value of 5 # 9 and 3 is

  1. 6

  2. 7

  3. 8

  4. 9


Correct Option: C
Explanation:

Find the false statement.

  1. No left recursive or ambiguous grammar can be LL(1)

  2. The class of grammars that can be parsed using LR methods is a proper subset of the class of grammars that can be the passed by LL method

  3. LR parsing is non - back tracking method

  4. LR methods can describe more languages than LL - grammars


Correct Option: B
Explanation:

Grammar passed by LR methods is a proper superset of the class of grammar parsed with LL method

Follow (E) is

  1. { )}

  2. {$}

  3. both (1) and (2)

  4. none of the above


Correct Option: C
Explanation:

Since, E is the start symbol, follow (E ) must contain $. The production body (E) explains why the right parenthesis is in follow (E ).

The grammar

  1. is ambiguous

  2. is unambiguous

  3. cannot be decided

  4. generates two parse trees for one input string


Correct Option: B
Explanation:

Every SLR(1) grammar is unambiguous.

The grammar $S \rightarrow SA|A$ $A \rightarrow a$

  1. SLR (1) but not LL (1)

  2. SLR (1) and LL (1)

  3. Not SLR (1), not LL (1)

  4. Not SLR (1), but LL (1)


Correct Option: A
Explanation:

For LL(1) grammar, for no terminal 'a', do both '$\alpha$' and '$\beta$' derive strings beginning with a. Here, the production S $\rightarrow$A and A $\rightarrow$a both derive strings beginning with a. So it is not LL (1).Now, the canonical collection of sets of LR (0) items for grammar is  There is no conflict in the LR (0) items. So, it is in SLR (i). So option (a) is correct.

The value printed by the following is $ (( A + B ) * C + ( D * E) + ( F *G)) $

  1. $ ++*+ABC*DE*FG $

  2. $ +*++ABC*DE*FG $

  3. $AB+C*DE*+FG*+$

  4. $ABC+*DE*+FD*+$


Correct Option: A
Explanation:

$(+AB)*C+(*DE)+(*FG)$ $= *+ABC+(*DE)+(*FG)$ $=+ + * + ABC * DE * FG$

While (i < = limit - 2) statement becomes $ \begin{cases} t=\text{limit - 2} \\ \text{While } (i \Leftarrow t) \end{cases} $ This optimization is caused by

  1. copy propagation

  2. code motion

  3. dead code elimination

  4. insufficient information


Correct Option: D
Explanation:

This is an example of loop - invariant code motion. But here no information is provided about the change of loop variable.

Consider the grammar. T$\rightarrow$T*F|F F $\rightarrow$ id For a sentence id1 *id2, the handlers in the right sequential form of the reduction are

  1. id1, F, id2, T *F

  2. id1, id2, T *F

  3. id1, F, T *F

  4. id1, F, id2


Correct Option: A
Explanation:
 
Right sequential form Handle Reduction production
$id_{1}*d_2$ $id_1$ $F \rightarrow id$
$F * d_2$ F $T \rightarrow F$
$T * d_2$ $id_2$ $F \rightarrow id$
$T * F$ $T * F$ $ E \rightarrow T * F $

Consider the grammar with transition rule and E is the start symbol.

E $\rightarrow$ E1 $\ne$ T {E1.value = E1.value + T.value}
|T {E.value = T.value} T $\rightarrow$ T1 & F {T.value = T1.value / F.value}
|F {T.value = F.value} F $\rightarrow$ num {F.value = num.value} Concept E. The value for the root of the parse tree for expression 6 # 4 and 2 # 16 and 4 is

  1. 16

  2. 12

  3. 8

  4. 6


Correct Option: A
Explanation:

Consider the grammar.

First ( E' ) and first ( E ) are respectively

  1. {+, $\epsilon$}, { , id }

  2. {+ , $\epsilon$}, { *, $\epsilon$}

  3. {*, $\epsilon$}, {C, id}

  4. none of these


Correct Option: A
Explanation:

First ($\alpha$), where $\alpha$ is any string of grammar symbols, to be the set of terminals that begin strings derived from$\alpha$. Here,First (E') = {+,$\epsilon$}First (E) = First (T) = First (F) = {C, id}

Choose the most appropriate option. (i) Indirect triples is advantageous than triples. (ii) With indirect triple, an optimizing compiler can move an instruction by reordering the instruction list, without affecting the triples themselves.

  1. i is true but ii is false.

  2. i and ii are true and ii is the cause of i.

  3. i and ii are true but ii is not the cause of i.

  4. Both of them are false.


Correct Option: C
Explanation:

Indirect triple consist of a listing of pointers to triples, rather than a listing of triples themselves.

Left factor the grammar. $A \rightarrow ad|a|ab|abc|b$

  1. $A \rightarrow aA'|b\\A' \rightarrow d| \epsilon |b|bc$

  2. $A \rightarrow aA'| b\\A'\rightarrow d |\epsilon| bA\\A'\rightarrow \epsilon| c$

  3. $A \rightarrow aA'| b\\A'\rightarrow d | bA'\\A\rightarrow c $

  4. $A \rightarrow aA' | b\\A' \rightarrow d | b | bc$


Correct Option: B
Explanation:

Following are the production and the action.

  1. $L\rightarrow E \eta$
  2. $E \rightarrow \{ print('+'); \}E_1 + T$
  3. $E \rightarrow R$
  4. $E \rightarrow \{ print('+'); \}T_1 + F$
  5. $T\rightarrow F$
  6. $F\rightarrow (E)$
  7. $F\rightarrow \text{digit \{print (digit lexval)\} }$
    This is syntax directed translation for
  1. prefix to infix

  2. infix to prefix

  3. postfix to infix

  4. infix to postfix


Correct Option: B
Explanation:

It is very clear from the productions 2 and 4. 

- Hide questions