I would like to suggest a small change to the notation of parameterized
productions, specifically when parameters appear as subscripts of
nonterminals in a production's RHS.
For concreteness, consider the nonterminal N with parameter P.
My suggestion is to change the notation as follows:
N[?P] -> N[P]
N[P] -> N[+P]
N -> N[~P]
Two reasons:
(1)
I think this notation would make parameterized productions somewhat easier
for readers to understand, mainly by leveraging their knowledge of how
parameters work in mathematics and programming languages.
(a) Changing N[?P] to N[P] ...
Generally, when a function wants to "pass down" the value of one of its
parameters, it simply references the parameter.
(b) Changing
N[P] to N[+P]
N to N[~P]
This re-uses the RHS-prefix notation [+P] and [~P], since the meanings are
parallel: as RHS-prefixes, they 'check' for the presence/absence of a
parameter; as RHS-subscripts, they could *assert* the presence/absence
of a parameter (for the RHS-use of a nonterminal).
In an analogy with a programming language, we could imagine that each
parameter has two possible values, '+' and '~'. Then a RHS-prefix is
analogous to a boolean expression in a guard:
[+P] is analogous to (P == '+')
[~P] (P == '~')
and (with my above suggestion) a RHS-subscript is analogous to a named
argument:
N[+P] is analogous to N(P = '+')
N[~P] N(P = '~')
(You could *state* a similar analogy using the current notation, but I think
it'd be less mnemonic, and wouldn't have the parallel with RHS-prefixes.)
(Conceivably, you could allow "N" as an shorthand for "N[~P]", but I don't
think I'd encourage it.)
(2)
In addition to making parameterized productions easier to understand,
I think it would also clarify references to parameterized nonterminals
*outside* productions.
Currently, when we say "N[P]" outside a production, it's unclear whether we
mean:
(a) all variants of N-parameterized-by-P
(= what "N[P]" means when it appears in a production's *LHS*); or
(b) the particular variant in which parameter P is present/used/on
(= what "N[P]" currently means when it appears in a production's *RHS*).
With my suggested notation, we can distinguish these as "N[P]" vs "N[+P]".
Similarly, when we say "N" outside of a production, we almost always mean:
(a) any variant of N-parameterized-by-P,
but it's possible we might want to mean:
(b) the particular variant in which parameter P is absent/unused/off.
With my suggested notation, we can denote the latter as "N[~P]".
---------
(By the way, this appears to be my 1000th bug at bugs.ecmascript.org!)
(In reply to comment #1)
> (By the way, this appears to be my 1000th bug at bugs.ecmascript.org!)
Thanks a lot!!!!!!!!
Keep them coming.
Allen
deferred to ES7