• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Parsing and Syntax directed translation

Question 31

Consider the syntax directed definition shown below.
S → id : = E  {gen (id.place = E.place;);}
E → E1 + E2   {t = newtemp ( ); gen (t = El.place + E2.place;); E.place = t}
E → id     {E.place = id.place;} 
Here, gen is 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 ti\'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
  • X = Y + Z
  • t1 = Y + Z; X = t1
  • t1 =Y; t2 = t1 + Z; X = t2
  • t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

Question 32

Which of the following statements is false?
  • An unambiguous grammar has same leftmost and rightmost derivation
  • An LL(1) parser is a top-down parser
  • LALR is more powerful than SLR
  • An ambiguous grammar can never be LR(k) for any k

Question 33

Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.

  • Leftmost derivation

  • Leftmost derivation traced out in reverse

  • Rightmost derivation

  • Rightmost derivation traced out in reverse

Question 34

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 35

Which one of the following is True at any valid state in shift-reduce parsing?
  • Viable prefixes appear only at the bottom of the stack and not inside
  • Viable prefixes appear only at the top of the stack and not inside
  • The stack contains only a set of viable prefixes
  • The stack never contains viable prefixes

Question 36

In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is True?

  • In both AST and CFG, let node N2 be the successor of node N1. In the input program, the code corresponding to N2 is present after the code corresponding to N1

  • For any input program, neither AST nor CFG will contain a cycle

  • The maximum number of successors of a node in an AST and a CFG depends on the input program

  • Each node in AST and CFG corresponds to at most one statement in the input program

Question 37

Match the following:
      List-I                  List-II
A. Lexical analysis       1. Graph coloring
B. Parsing                2. DFA minimization
C. Register allocation    3. Post-order traversal
D. Expression evaluation  4. Production tree
Codes:
    A B C D
(a) 2 3 1 4
(b) 2 1 4 3
(c) 2 4 1 3
(d) 2 3 4 1
  • a
  • b
  • c
  • d

Question 38

Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order?
  • SLR, LALR
  • Canonical LR, LALR
  • SLR, canonical LR
  • LALR, canonical LR

Question 39

Consider the following grammar G.
  S → F ⎪ H
  F → p ⎪ c
  H → d ⎪ c 
Where S, F and H are non-terminal symbols, p, d and c are terminal symbols. Which of the following statement(s) is/are correct?
S1: LL(1) can parse all strings that are generated using grammar G.
S2: LR(1) can parse all strings that are generated using grammar G. 
  • Only S1
  • Only S2
  • Both S1 and S2
  • Neither S1 and S2

Question 40

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b}}. gt46 Using the above SDTS, the output printed by a bottom-up parser, for the input aab is
  • 1 3 2
  • 2 2 3
  • 2 3 1
  • Syntax Error

There are 85 questions to complete.

Last Updated :
Take a part in the ongoing discussion