edited by
846 views
3 votes
3 votes

Consider these three grammars.$$\begin{array}{|c|c|c|} \hline \textbf{Grammar G1:} & \textbf{Grammar G2:} & \textbf{Grammar G3:}  \\ \hline E\rightarrow E+T \mid T  & E\rightarrow E + T \mid T & E\rightarrow TR \mid R \\ \hline T\rightarrow T \ast v \mid v & T\rightarrow vR & R\rightarrow +T R \mid \varepsilon \\ \hline  & R\rightarrow \ast v R\mid\varepsilon & T\rightarrow T v\mid v   \\\hline\end{array}$$ Which of the following statements is NOT true?

  1.      If $w$ can be generated by $G1$, then it can be generated by $G2$.
  2.      If $w$ can be generated by $G1$, then it can be generated by $G3$.
  3.      If $w$ can be generated by $G2$, then it can be generated by $G1$.
  4.      If w can be generated by $G3$, then it can be generated by $G1$.
edited by

1 Answer

1 votes
1 votes
In G1, T can take the form of v * v * v * v * v ....

In G2, R can take the form * v * v * v ...,  

so T can take the form of v * v * v * v ....

Thus, in both G1 and G2, E can take the form v * v * v + v * v * v * v + v * v ....

These are the algebraic expressions involving only addition and multiplication.

In G3, T can take the form v * v * v * v, so R can take the form + v * v + v * v. Thus, through the production E ! T R, E can take the form of any arithmetic expression.

However, E can also take the form of non-arithmetic expressions,

as with E --> R --> + T R --> + v R --> + v + T R ---> + v + v R --> + v + v.

In addition, G3 can generate ε , which G1 and G2 cannot.

Thus, while G1 and G2 generate the same language,

G3 generates a somewhat larger language. Incidentally, G1 demonstrates left-recursion because it contains productions of the form X --> X  α ( in addition to non-problematic productions of the form   X --> β ).

Left recursion can be eliminated by introducing a helper non-terminal R and changing the grammar to read

X --> β R
R --> α R | ε
Answer:

Related questions

2 votes
2 votes
1 answer
1
Bikram asked Jan 24, 2017
444 views
In $1991$, produce growers began using a new and inexpensive pesticide. This provoked many objections that growers would damage both the environment and the produce they ...
4 votes
4 votes
2 answers
2
Bikram asked Jan 24, 2017
490 views
The value of the expression $1 - 6 + 2 - 7 + 3 - 8 +$……… to $100$ terms is __________.
2 votes
2 votes
2 answers
3
Bikram asked Jan 24, 2017
370 views
Choose a pair that has most similar relationship to the given pair :Bird : EagleReptile : CreeperDisease : PlagueVitamin : IodinePage : Break