Given the following grammar, why is Z said to be not nullable

X -> Y | a
Y -> c | epsilon
Z -> X Y Z | d
有帮助吗?

解决方案

Because it does not contain epsilon (null). For example, Y is nullable because Y can be defined as epsilon. As is X, because X is defined as either Y or a. If we set Y to epsilon, then X is also epsilon.

Interestingly, if Z were defined as only X Y, then there is the possibility for Z to also be nullable, because X and Y can both be set to epsilon (as above) thus making Z epsilon, but because Z must end in Z, which eventually must end in the terminal d (why?), Z is not nullable.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top