retagged by
911 views
5 votes
5 votes

Consider these three grammars.

Which of the following statements is not true?

(A) If w can be generated by G1, then it can be generated by G2.

(B) If w can be generated by G2, then it can be generated by G3.

(C) If w can be generated by G3, then it can be generated by G1.

(D) If w can be generated by G2, then it can be generated by G1.

retagged by

1 Answer

Best answer
5 votes
5 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 | ε

hence C is the answer .
Answer:

Related questions

4 votes
4 votes
3 answers
1
smartmeet asked Feb 7, 2017
798 views
Given TMs and L = {x/Every halts on input x } which of the following is true about L?(A) L is recursively enumerable but not recursive(B) L is Recursive but not Context...
2 votes
2 votes
1 answer
2
smartmeet asked Feb 7, 2017
914 views
A B-tree of order m is a tree which satisfies the following properties:Every node has at most m children.Every node (except root) has at least ⌈m/2⌉ children maximi...