开发者

transform grammar problem

开发者 https://www.devze.com 2023-02-08 01:52 出处:网络
S -> aB | lamda B -> bB B i开发者_如何学Pythons a useless production. Now after its removal
S -> aB | lamda
B -> bB

B i开发者_如何学Pythons a useless production. Now after its removal

S -> a | lamda

Is this correct ?


production S -> aB does not terminate. Because B -> bB does not terminate. So the production S -> aB is useless.

the answer should be

S -> lambda


Boy it's been a long time since I've looked at CFG's. B produces an infinite series of b's, does it not (b*?)

Assuming b* means an infinite series of B's I think I would reduce to:

S -> ab* | λ

EDIT:

Yes, my answer above is wrong. The definition of a "useless production" is a production that is never used in the derivation of a terminal string. Since B is non-terminal it can be removed thus S -> λ.

+1 to the answer by user574183.

0

精彩评论

暂无评论...
验证码 换一张
取 消