Programming languages are often described using an extended form of context-free grammar, where square brackets are used to denote an optional construct. For example, A → B[C]D says that an A can be replaced by a B and a D, with an optional C between them. This notation does not allow us to describe anything but context-free languages, since an extended production can always be replaced by several conventional productions.
Suppose a grammar has the extended productions:
A → B[CD]EF | BC[DE]F
Convert this pair of extended productions to conventional productions. Identify, from the list below, the conventional productions that are equivalent to the extended productions above.
a) A → BCDEF | BEF
b) A → BA1F
A1 → CD | DE | ε
c) A → BA1EF | BCA2F
A1 → CD | ε
A2 → DE | ε
d) A → BA1EF | BCA2F
A1 → CD
A2 → DE
What is the answer? Explain me Plz
Expert Answer
A → B[CD]EF | BC[DE]F
says that an A can be replaced by a B and a EF, with an optional CD between them or A can be replaced by a BC and a F, with an optional DE between them.
Conventional productions that is equivalent to the productions above :-
c) A → BA1EF | BCA2F
A1 → CD | ε
A2 → DE | ε
Hint :-
a is not possible because A → BCDEF is not always a production
b is not possible because A → BA1EF | BCA2F; A1 → CD | ε; A2 → DE | ε; does not give B[CD]EF | BC[DE]F
d is also not possible because it does not have ε
only option c gives A → B[CD]EF | BC[DE]F