What does this general grammar do?
S -> LR
L -> L0Y
L -> LX
X1 -> 1X
X0 -> 0X
X0 -> 1Y
Y1 -> 0Y
YR -> R
L -> epsilon
R -> epsilon
the start symbol is S. I tried to generate string from this grammar and I got every binary numbers. but I think it does something specific.
terminals: 0,1
start: S
Let’s split the grammar:
This will generate a string in the form
L, string ofXand0Y,R.Treat
XandYas acting on the binary string:Xwill propagate to the right, then change a0to1and all subsequent1s to0s. In effect, a singleXincrements the binary number without changing its string length (or gets stuck).A leading
Ywill rewrite the string of all1s to all0s (or gets stuck).Treat the rules for
Las the possible actions on the right part of the string.L => L0Ywill reset the string from all ones to all zeroes and increase its length by one.L => LXwill increment any other number, but fails if the value is at the maximum.These two actions together are sufficient to generate (inefficiently) all strings of zeroes and ones (including the empty string).
will only clean up the sentinels.
one possible description of the language within four words:
set of all strings