質問

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