retagged by
930 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

820
views
3 answers
4 votes
smartmeet asked Feb 7, 2017
820 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...
922
views
1 answers
2 votes
smartmeet asked Feb 7, 2017
922 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...
465
views
0 answers
0 votes
smartmeet asked Feb 7, 2017
465 views
The intended purpose of this code is to precompute all the primes less than N. When it is finished executing, for r ∈ [2, N), bits[r] is supposed to equal 1 if and only...
456
views
1 answers
0 votes
smartmeet asked Feb 7, 2017
456 views
Consider a data type whose elements are integers and whose operations are INSERT, DELETE, and FINDCLOSEST, with FINDCLOSEST(y) defined to be some element x in the curren...
Total PHP MySQL Other RAM
Time (ms) % Time (ms) % File count Time (ms) % Query count Time (ms) % Amount %
Setup 4.5 5% 2.5 3% 72 2.0 2% 2 0.0 0% 569k 45%
Control 15.0 19% 1.7 2% 4 13.8 18% 12 0.0 0% 246k 19%
View 1.9 2% 1.9 2% 12 0.0 0% 0 0.0 0% 126k 10%
Theme 48.2 64% 5.3 7% 16 43.0 57% 3 0.0 0% 296k 23%
Stats 5.6 7% 0.1 0% 0 5.6 7% 1 0.0 0% 0k 0%
Total 75.3 100% 11.6 15% 104 64.3 85% 18 0.0 0% 1239k 100%