• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Parsing and Syntax directed translation

Question 11

Consider the grammar with non-terminals N = {S,C,S1 },terminals T={a,b,i,t,e}, with S as the start symbol, and the following set of rules:

S --> iCtSS1|a
S1 --> eS|ϵ
C --> b

The grammar is NOT LL(1) because:

  • it is left recursive

  • it is right recursive

  • it is ambiguous

  • It is not context-free.

Question 12

Consider the following two statements:
P: Every regular grammar is LL(1)
Q: Every regular set has a LR(1) grammar
Which of the following is TRUE?
  • Both P and Q are true
  • P is true and Q is false
  • P is false and Q is true
  • Both P and Q are false

Question 13

Consider the following grammar.
S -> S * E
S -> E
E -> F + E
E -> F
F -> id
Consider the following LR(0) items corresponding to the grammar above.
(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E 
Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?
  • (i) and (ii)
  • (ii) and (iii)
  • (i) and (iii)
  • None of the above

Question 14

A canonical set of items is given below
S --> L. > R
Q --> R.
On input symbol < the set has
  • a shift-reduce conflict and a reduce-reduce conflict.
  • a shift-reduce conflict but not a reduce-reduce conflict.
  • a reduce-reduce conflict but not a shift-reduce conflict.
  • neither a shift-reduce nor a reduce-reduce conflict.

Question 15

Consider the grammar defined by the following production rules, with two operators ∗ and +
    S --> T * P 
    T --> U | T * U
    P --> Q + P | Q
    Q --> Id
    U --> Id
Which one of the following is TRUE?
  • + is left associative, while ∗ is right associative
  • + is right associative, while ∗ is left associative
  • Both + and ∗ are right associative
  • Both + and ∗ are left associative

Question 16

Consider the following grammar:
S → FR
R → S | ε
F → id
In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, $] respectively.
  • {S → FR} and {R → ε }
  • {S → FR} and { }
  • {S → FR} and {R → *S}
  • {F → id} and {R → ε}

Question 17

Consider the following translation scheme. S → ER R → *E{print("*");}R | ε E → F + E {print("+");} | F F → (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input \'2 * 3 + 4\', this translation scheme prints
  • 2 * 3 + 4
  • 2 * +3 4
  • 2 3 * 4 +
  • 2 3 4+*

Question 18

The grammar A → AA | (A) | ε is not suitable for predictive-parsing because the grammar is

  • ambiguous

  • left-recursive

  • right-recursive

  • an operator-grammar

Question 19

Consider the grammar
E → E + n | E × n | n 
For a sentence n + n × n, the handles in the right-sentential form of the reduction are
  • n, E + n and E + n × n
  • n, E + n and E + E × n
  • n, n + n and n + n × n
  • n, E + n and E × n

Question 20

Consider the grammar
S → (S) | a
Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good
  • n1 < n2 < n3
  • n1 = n3 < n2
  • n1 = n2 = n3
  • n1 ≥ n3 ≥ n2

There are 85 questions to complete.

Last Updated :
Take a part in the ongoing discussion