Re: repetition

>> Later, “hints for implementors” observes that
>>
>>   a*"#"
>>
>> can be rewritten. For example:
>>
>> X: a*"#" .
>>
>> can be rewritten as
>>
>> X: Y .
>> -Y: a+"#" ; .
>
> which smells to my way of thinking?
> That *insists* on at least one 'a' which seems incorrect?

No, it doesn’t. Observe that “;” separates alternatives so

-Y: a+"#" ; .

reads as (a+"#") OR ().

>> All of this has turned out to be an interesting challenge for me to
>> implement because I don’t think the PEP parser can be made to accept
>> “nothing” as an alternative. Instead, I think (I think!) I’ve modified
>> it so that it understands an optional terminal or nonterminal. So I’ll
>> end up rewriting it something like this:
>>
>> X: Y .
>> -Y: Z? .
>> -Z: a, A .
>> -A: ("#", a, A)? .
>
> Is this expansion on X: a*"#" .  ?
>
> In which case I've the same objection as above?

Z is an “a” followed by an “A”. An “A” is a optional so it can be
nothing. If it isn’t nothing it’s “#” followed by “a” followed by “A”.
And we recurse there with that “A” being replaced by either nothing or
another occurrence of “#” followed by “a” followed by “A”.

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Thursday, 16 December 2021 12:45:24 UTC