Compiler design miscellaneous


Compiler design miscellaneous

  1. Which of the following statements are true?
    1. There exist parsing algorithms for some programming languages whose complexities ar less than θ (n3).
    2. A programming language which allows recursive can be implemented with static storage allocation.
    3. No L-attributed definition can be evaluated in the framework of bottom-up parsing.
    4. Code improving transformations can be performed at both source language and intermediate code level.









  1. View Hint View Answer Discuss in Forum

    The time bounds for the parser are the same as those of the recognizer, while the space bound goes up to n 3 in general in order to store the parse trees. In fact it would probably be most efficient to implementthe algorithm to do just a look-ahead of 1. To implement the full look-ahead for any k would be more costly inprogramming effort and less efficient overall since so few programming languages need the extra lookahead. Improving transformations are performed on a target-specific representation of the program. for both existing and proposed architectures, to gather trace information for code improvements are often applied to a high-level intermediate language though it can be applied to the source level also but it can impact the effectiveness of code improvements
    I. Statement is true since there are some parsers which take O(n log2n) time for parsing.
    II. Completely false, since there is no use of stack which is required for recursion.
    III. False
    IV. True since both types of optimizations are applied

    Correct Option: B

    The time bounds for the parser are the same as those of the recognizer, while the space bound goes up to n 3 in general in order to store the parse trees. In fact it would probably be most efficient to implementthe algorithm to do just a look-ahead of 1. To implement the full look-ahead for any k would be more costly inprogramming effort and less efficient overall since so few programming languages need the extra lookahead. Improving transformations are performed on a target-specific representation of the program. for both existing and proposed architectures, to gather trace information for code improvements are often applied to a high-level intermediate language though it can be applied to the source level also but it can impact the effectiveness of code improvements
    I. Statement is true since there are some parsers which take O(n log2n) time for parsing.
    II. Completely false, since there is no use of stack which is required for recursion.
    III. False
    IV. True since both types of optimizations are applied


  1. Which of the following describes a handle (as applicable to LR-parsing) appropriately?









  1. View Hint View Answer Discuss in Forum

    It is a production p that may be used for reduction in afuture step along with a position in the sentential form where, the right hand side of the production may befound. A “handle” of a string is a substring that matches the RHS of a production and whose reduction to the nonterminal (on the LHS of the production) represents one step along the reverse of a rightmost derivation toward reducing to the start symbol. If S → * αAw → * αbw, then A → β in the position following a is a handle of αβw. In such a case, it is suffice to say that the substring β is a handle of αβw, if the position of β and the corresponding production are clear. Consider the following grammar: E → E + E | E * E | (E) | id and a right-most derivation is as follows: E → E + E → E + E * E → E + E * id3 → E + id2 * id3 → id1 + id2 * id3

    Correct Option: D

    It is a production p that may be used for reduction in afuture step along with a position in the sentential form where, the right hand side of the production may befound. A “handle” of a string is a substring that matches the RHS of a production and whose reduction to the nonterminal (on the LHS of the production) represents one step along the reverse of a rightmost derivation toward reducing to the start symbol. If S → * αAw → * αbw, then A → β in the position following a is a handle of αβw. In such a case, it is suffice to say that the substring β is a handle of αβw, if the position of β and the corresponding production are clear. Consider the following grammar: E → E + E | E * E | (E) | id and a right-most derivation is as follows: E → E + E → E + E * E → E + E * id3 → E + id2 * id3 → id1 + id2 * id3



  1. An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts, if and only, if









  1. View Hint View Answer Discuss in Forum

    LALR parser is reduced form of CLR or LR(1) parser, LALR parser uses the LR(1) items of CLR parser & of any shift reduce conflicts are there then it is due to LR(1) parser.

    Correct Option: B

    LALR parser is reduced form of CLR or LR(1) parser, LALR parser uses the LR(1) items of CLR parser & of any shift reduce conflicts are there then it is due to LR(1) parser.


  1. In the correct grammar above, what is the length of the derivation (number of steps starting from S) to generate the string albm with l ≠ m?









  1. View Hint View Answer Discuss in Forum

    It is very clear from the previous solution that the no. of steps required depend upon the no. of a' s & b ' s which ever is higher & exceeds by 2 due to S " AC CB & C"!
    So max(l, m) + 2
    Hence (a) is correct option.

    Correct Option: A

    It is very clear from the previous solution that the no. of steps required depend upon the no. of a' s & b ' s which ever is higher & exceeds by 2 due to S " AC CB & C"!
    So max(l, m) + 2
    Hence (a) is correct option.



  1. Which one of the following grammars generates the language L = {ai bj} i ≠ j]?









  1. View Hint View Answer Discuss in Forum

    In the language language L = {ai bj | i ≠ j} The expression i ≠ j indicates that language L is a language in which number of a ≠ number of b. Here, we need to search for a language in which number of a ≠ number of b.
    Considering the options:
    Options (a)
    S → AC | CB
    C → aCb | a| b
    A → aA | ∈
    B → Bb | ∈
    (a), S → (C) B → a(b) → aBb → ab
    Here, the number of a = number of b, hence, it is not the required grammar.
    Option (b)
    S → as | Sb | a | b
    S → as → abB
    Here, number of a = number of b, hence it is not the required grammar.
    Option (c)
    S → AC | CB
    C → aC b| ∈
    A → aA | ∈
    B → Bb | ∈
    S(C)B → acbB → ab
    Here, number of a = number of b, hence it is not the required grammar.
    Option (d)
    S → AC | CB
    C → aC b| ∈
    A → aA | a
    B → Bb | b
    Consider the production
    S → AC | CB
    Applying, C → ∈
    We get S → A|B
    Now, applying A or B, S generates a^n.b^n. So, L = {ai bj | i ≠ j}
    Now, consider the production, S → AC | CB. If the production C → acb is applied then, it generates a^n,b^n.
    Now, applying either A or B it will give that number of a ≠ number of b.

    Correct Option: D

    In the language language L = {ai bj | i ≠ j} The expression i ≠ j indicates that language L is a language in which number of a ≠ number of b. Here, we need to search for a language in which number of a ≠ number of b.
    Considering the options:
    Options (a)
    S → AC | CB
    C → aCb | a| b
    A → aA | ∈
    B → Bb | ∈
    (a), S → (C) B → a(b) → aBb → ab
    Here, the number of a = number of b, hence, it is not the required grammar.
    Option (b)
    S → as | Sb | a | b
    S → as → abB
    Here, number of a = number of b, hence it is not the required grammar.
    Option (c)
    S → AC | CB
    C → aC b| ∈
    A → aA | ∈
    B → Bb | ∈
    S(C)B → acbB → ab
    Here, number of a = number of b, hence it is not the required grammar.
    Option (d)
    S → AC | CB
    C → aC b| ∈
    A → aA | a
    B → Bb | b
    Consider the production
    S → AC | CB
    Applying, C → ∈
    We get S → A|B
    Now, applying A or B, S generates a^n.b^n. So, L = {ai bj | i ≠ j}
    Now, consider the production, S → AC | CB. If the production C → acb is applied then, it generates a^n,b^n.
    Now, applying either A or B it will give that number of a ≠ number of b.