Q30: Context Free Grammar Example Contd.

This question is in continuation of the previous question 29

Question #30: What is the language of the variable E?

A)     E represents the arithmetic expressions e.g. a+b or a * (a + b) where the symbols can only be a or b.

B)      E represents the arithmetic expressions e.g. a+b or a * (a + b) where the symbols can be 0, 1, a and b, but must start with a or b.

C)      E represents the arithmetic expressions where ‘+’ and ‘*’ can appear equal number of times.

D)     None of the above.

 

Solution:

The above CFG can be used to represent any arithmetic expression involving addition and multiplication. Since E can be derived to I, any arithmetic expression which start with ‘a’ or ‘b’ and having symbols ‘a’, ‘b’, ‘0’ and ‘1’ can be derived. Hence, the correct answer is B.

Leave a comment