• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Parsing and Syntax directed translation

Question 51

The language L, defined by the following grammar allows use of real or integer data in expressions and assignment statements.
(assign-stmt):: = (LHS):= (E)
(E)          :: = (E) + (T) | (T)
(T)          :: = (T) * (V) | (V)
(V)          :: = id | ((E))
(LHS)        :: = id
It is required to convert expression and assignment strings of L into postfix strings that use the type-specific operators (+, i), (+, r), (*, i), (*, r), (:=, i) and (:=, r). Write a syntax directed translation scheme to convert expression and assignment strings into the post-fix form. You may assume that the name and type of a variable can be obtained by making the function calls \'give-type (id)\' and \'give-name (id)\' respectively.

    Question 52

    The grammar whose productions are
     <stmt> → if id then <stmt>
     <stmt> → if id then  <stmt> else <stmt>
     <stmt> → id := id
    is ambiguous because a) the sentence  if a then if b then c:= d  has two parse trees b) the left most and right most derivations of the sentence  if a then if b then c:= d  give rise to different parse trees c) the sentence  if a then if b then c:= d else c:= f  has more than two parse trees d) the sentence  if a then if b then c:= d else c:= f  has two parse trees
    • a
    • b
    • c
    • d

    Question 53

    Consider the syntax-directed translation schema (SDTS) shown below:
    E → E + E         {print “+”}
    E → E ∗ E         {print “.”}
    E → id            {print id.name}
    E → ( E )
    
    An LR-parser executes the actions associated with the productions immediately after a reduction by the corresponding production. Draw the parse tree and write the translation for the sentence (a+b)(c+d), using the SDTS given above.

      Question 54

      Consider the following grammars (S1) :
      A --> aBCD
      B --> bc|c
      C --> d|∈
      D -> b
      
      (S2) :
      A --> aBCD
      B --> bc|∈
      C --> d|c
      D -> b
      
      (S3) :
      A --> aBCD
      B --> bc|∈
      C --> d|∈
      D -> b
      
      (S4) :
      A --> aBCD
      B --> bc|c
      C --> d|c
      D -> b
      
      Which of the following grammar has same follow set for variable B?
      • Only (S1), (S2) and (S3), (S4)
      • Only (S1), (S3) and (S2), (S4)
      • Only (S2), (S3) and (S1), (S4)
      • None of the above

      Question 55

      Which is True about SR and RR-conflict:
      • If there is no SR-conflict in CLR(1) then definitely there will be no SR-conflict in LALR(1).
      • RR-conflict might occur if lookahead for final items(reduce-moves) is same.
      • Known that CLR(1) has no RR-conflict, still RR-conflict might occur in LALR(1).
      • All of the above.

      Question 56

      Consider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #. 10 Which one of the following is correct for the given parse tree?
      • $ has higher precedence and is left associative; # is right associative
      • # has higher precedence and is left associative; $ is right associative
      • $ has higher precedence and is left associative; # is left associative
      • # has higher precedence and is right associative; $ is left associative

      Question 57

      Which of the following statements is/are TRUE ? (i) The grammar S → SS | a is ambiguous (where S is the start symbol). (ii) The grammar S → 0S1 | 01S | e is ambiguous (the special symbol e represents the empty string and S is the start symbol). (iii) The grammar (where S is the start symbol).
      S → T/U
      T → x S y ? xy ? e
      U → yT
      
      generates a language consisting of the string yxxyy.
      • Only (i) and (ii) are TRUE
      • Only (i) and (iii) are TRUE
      • Only (ii) and (iii) are TRUE
      • All of (i), (ii) and (iii) are TRUE

      Question 58

      Given the following expression grammar:
      E → E ∗ F ∣ F + E ∣ F
      F → F − F ∣ id
      
      Which of the following is true?
      • * has higher precedence than +
      • - has higher precedence than *
      • + and - have same precedence
      • + has higher precedence than *

      Question 59

      Which grammar rules violate the requirement of the operator grammar? A, B, C are variables and a, b, c are terminals
      1) A → BC
      2) A → CcBb
      3) A → BaC
      4) A → ε
      
      • 1 only
      • 1 and 2 only
      • 1 and 3 only
      • 1 and 4 only

      Question 60

      Yacc stands for
      • yet accept compiler constructs
      • yet accept compiler compiler
      • yet another compiler construct
      • yet another compiler compiler

      There are 85 questions to complete.

      Last Updated :
      Take a part in the ongoing discussion