Compiler design miscellaneous


Compiler design miscellaneous

  1. The grammar S → aSa | bS| c is









  1. View Hint View Answer Discuss in Forum

    S → aSa | bS | C
    The above grammar is LL (1) because,
    First [aSa] ∩ first [bS] = (a) ∩ (b) = φ
    First [bS] ∩ first [c] = (b) ∩ (c) = φ
    First [c] ∩ first [aSa] = (c) ∩ (a) = φ
    As the above grammar is LL (1), also LR (1) because LL (1) grammar is always LR (1) grammar.

    Correct Option: C

    S → aSa | bS | C
    The above grammar is LL (1) because,
    First [aSa] ∩ first [bS] = (a) ∩ (b) = φ
    First [bS] ∩ first [c] = (b) ∩ (c) = φ
    First [c] ∩ first [aSa] = (c) ∩ (a) = φ
    As the above grammar is LL (1), also LR (1) because LL (1) grammar is always LR (1) grammar.


  1. For a C program accessing 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]
    Which one of the following statements about the source code for the C program is









  1. View Hint View Answer Discuss in Forum

    X is declared as “int × [32] [32] [8]”

    Correct Option: A

    X is declared as “int × [32] [32] [8]”



  1. The least number of temporary variables required to create three-address code in static single assignment form for the expression q + r /3 + s – t*5 + u*v /w is ______.









  1. View Hint View Answer Discuss in Forum

    3

    Correct Option: B

    3


  1. The secant method is used to find the root of an equation f(x) = 0. It is started from two distinct estimates xa and xb for the root. It is an iterative procedure involving linear interpolation to a root. The iteration stops if f(xb) is very small and then xb is the solution. The procedure is given below. Observe that there is an expression which is missing and is marked by? Which is the suitable expression that is to be put in place of?
    So that it follows all steps of the secant method?
    Secant
    Initialize : xa, xb, ε , N
    // ε = convergence indicator
    // N = maximum number of iterations
    fb = f(xb)
    i = 0
    while (i < N and |fb | > ε ) do
    i = i + 1// update counter
    xt =? // missing expression for
    xa = xb
    xb = xt // intermediate value
    fb = f(xb) // function value at new xb
    end while
    if |fb | > ε then // loop is terminated with i = N
    write "Non-convergence"
    else
    write "return xb "
    end if









  1. View Hint View Answer Discuss in Forum

    It is secant method direct formula.

    Correct Option: D

    It is secant method direct formula.



  1. Consider the translation scheme shown below:
    S → RT
    R → + T {print (‘+’:) R/ ε
    T → num {print (num. val);}
    Here, num is a taken that represents an integer and num. val represents the corresponding integer value. For an input string ‘9 + 5 + 2’, this translation scheme will print









  1. View Hint View Answer Discuss in Forum

    Let us make the parse tree for 9 + 5 + 2 in top down manner, left first derivation.
    Steps:
    1) Expand S → TR
    2) Apply T → Num...
    3) Apply R → +T...
    4) Apply T → Num...
    5) Apply R → +T..
    6) Apply T → Num..
    7) Apply R → ε (epsilon)
    After printing through the print statement in the parse tree formed you will get the answer as 95 + 2 +

    Correct Option: B

    Let us make the parse tree for 9 + 5 + 2 in top down manner, left first derivation.
    Steps:
    1) Expand S → TR
    2) Apply T → Num...
    3) Apply R → +T...
    4) Apply T → Num...
    5) Apply R → +T..
    6) Apply T → Num..
    7) Apply R → ε (epsilon)
    After printing through the print statement in the parse tree formed you will get the answer as 95 + 2 +