edited by
10,997 views
32 votes
32 votes

Consider the following expression grammar $G$:

  • $E \rightarrow E-T \mid T$
  • $T \rightarrow T + F \mid F$
  • $F \rightarrow (E) \mid id$

Which of the following grammars is not left recursive, but is equivalent to $G$?

  1. $E \rightarrow E-T \mid T$

    $T  \rightarrow T +F \mid F$

    $F \rightarrow (E) \mid id$
  2. $E \rightarrow TE’$

    $E’ \rightarrow -TE’ \mid \epsilon$

    $T \rightarrow T + F \mid F$

    $F \rightarrow (E) \mid id$

  3. $E \rightarrow TX $

    $X \rightarrow -TX \mid \epsilon$

    $T \rightarrow FY$

    $Y \rightarrow +FY \mid \epsilon$

    $F \rightarrow (E) \mid id$

  4. $E \rightarrow TX \mid (TX)$

    $X \rightarrow -TX \mid +TX \mid \epsilon$

    $T \rightarrow  id$

edited by

7 Answers

0 votes
0 votes
here we need to remove left recursion

E->TE'

E'->-TE'/ epsilon

T->FT'

T->+FT'/ epsilon

F->(E)/id

above by applying rule

A->Ax/y then

A->yA'

A'->xA'/ epsilon

were by expansion of the same we got the same strings.
0 votes
0 votes
option C
0 votes
0 votes

Options A and B shows left recursion, while option D can’t make a parse tree for the following input for which the given CFG can make.

Answer:

Related questions

39 votes
39 votes
5 answers
1
Madhav asked Feb 14, 2017
9,651 views
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:$$\begin{array}{|l|l|}\hline \text{P. Syntax t...
20 votes
20 votes
8 answers
2
Arjun asked Feb 14, 2017
7,844 views
Which of the following statements about parser is/are CORRECT?$\text{Canonical LR}$ is more powerful than $\text{SLR}$$\text{SLR}$ is more powerful than $\text{LALR}$$\te...
47 votes
47 votes
6 answers
4
Madhav asked Feb 14, 2017
17,959 views
Consider the recurrence function$$T(n) = \begin{cases} 2T(\sqrt{n})+1, & n>2 \\ 2, & 0 < n \leq 2 \end{cases}$$Then $T(n)$ in terms of $\Theta$ notation is$\Theta(\log \l...