Compiler design miscellaneous


Compiler design miscellaneous

  1. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is









  1. View Hint View Answer Discuss in Forum

    SLR parser is less range of context free languages than LALR but still both n1 & n2 are same for SLR & LALR respectively. Hence (b) is correct option.

    Correct Option: B

    SLR parser is less range of context free languages than LALR but still both n1 & n2 are same for SLR & LALR respectively. Hence (b) is correct option.


  1. Which of the following suffices to convert an arbitrary CFG to an LL (1) grammar?









  1. View Hint View Answer Discuss in Forum

    Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar because: We have following these steps to convert an arbitrary CFG to LL(1) grammar: 1. Remove ambiguity (by taking care of precedence and associatively) 2. Remove Left Recursion (This will come when you remove ambiguity) 3. Make grammar deterministic by Left factoring (In case occur) To convert CFG to LL(1), which is top down parser. If the grammar is ambiguous, is left recursive and has left factoring, then, it is not a LL(1). For LL(1) all the three should be removed.

    Correct Option: D

    Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar because: We have following these steps to convert an arbitrary CFG to LL(1) grammar: 1. Remove ambiguity (by taking care of precedence and associatively) 2. Remove Left Recursion (This will come when you remove ambiguity) 3. Make grammar deterministic by Left factoring (In case occur) To convert CFG to LL(1), which is top down parser. If the grammar is ambiguous, is left recursive and has left factoring, then, it is not a LL(1). For LL(1) all the three should be removed.



  1. Consider the syntax directed definition shown below :

    Here, gen 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 t1 ‘ 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









  1. View Hint View Answer Discuss in Forum

    The production E → E + E is used only one time and hence only one temporary variable is generated.

    Correct Option: B

    The production E → E + E is used only one time and hence only one temporary variable is generated.


  1. Which of the following grammar rules violate the requirement of an operator grammar? P, Q, R are non – terminals, and r, s, t are terminals.
    1. P → Q R
    2. P → Q S R
    3. P → ε
    4. P → Q t R r









  1. View Hint View Answer Discuss in Forum

    1. P → QR is not possible since two NT should include one operator as Terminal.
    2. Correct
    3. Again incorrect.
    4. Correct.
    Hence (b) is correct option.

    Correct Option: B

    1. P → QR is not possible since two NT should include one operator as Terminal.
    2. Correct
    3. Again incorrect.
    4. Correct.
    Hence (b) is correct option.



  1. Consider the grammar rule E → E1 – E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub-expression, in order to get shortest possible code.









  1. View Hint View Answer Discuss in Forum

    E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2 also. So E2 should be evaluated first & then E1, so finally E1 will be in accumulator, otherwise need to use move & load instructions.
    Hence (b) is correct option.

    Correct Option: B

    E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2 also. So E2 should be evaluated first & then E1, so finally E1 will be in accumulator, otherwise need to use move & load instructions.
    Hence (b) is correct option.