Re: Identification of root rule

>> In a tiny number of extreme cases where the root is used in the body
>> of the grammar, you can add:
>>
>>  -root: program.
>>
>> (where 'program' is the real root') and all is well.
>
> That's what I had in mind as a form of interfering in a big way with the
> design of the grammar.  It also feels very odd to me in a language one
> of whose big selling points is that a processor can handle any
> context-free grammar, not just a subset of them.  "Any context free
> grammar, as long as the start symbol is not recursive" just doesn't have
> the same ring for me.

Indeed. Yuck.

> I suppose we might ease the usability issue by a more complicate rule
> for implementors, along the lines of:
>
>   - If the processor supports an invocation-time option to give the
>     start symbol, use that symbol.
>     
>   - Otherwise, if the start symbol is explicitly declared in the prolog,
>     use that symbol.
>
>   - Otherwise, if there is one and only one nonterminal not referred to
>     from any other nonterminal, use that nonterminal as the start
>     symbol.
>
>   - Otherwise, use the first nonterminal in the grammar.
>
> If the user with the declare-before-use instinct had a non-recursive
> start symbol, and no other unreferenced symbols, then this would have
> worked for them.

I’m okay with those rules. I think I might be inclined to go with only
three rules, just to be a little simpler:

1. Processor supported invocation-time option. (I’m tempted to argue
that we don’t need and/or shouldn’t say anything about this; processors
with options can do what they like. Insert my favorite remark re:
warnings, “a processor can warn that the moon is full if they like”.)

2. Use the rule explicitly identified in the prolog.

3. Use the first rule.

Since there isn’t always a unique start rule, explaining the part about
using it if it’s unique but then suddenly switching to the first rule if
it isn’t seems like it could be confusing.

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Thursday, 19 October 2023 15:24:03 UTC