"Joel E. Denny" <[EMAIL PROTECTED]> writes:
> And what if X is an alternation of symbols with different types?
Its type would be their discriminated union.
> I still wonder if ISO EBNF is the right language. Aren't most
> Lex and Yacc users more familiar with notations like "(...)*", "(...)?",
> and "(...)+"?
Yes, quite likely. I wouldn't be a slave to ISO EBNF (particularly
since we're already incompatible with it :-), but it can't hurt to be
inspired by it.
> The argument there isn't about the choice of "/" or "#" or "()" or "[]".
> It's about the choice of "!" (or "-" in the current discussion) to mean
> nothing. I prefer the empty string to mean nothing.
OK, how about this idea? If rules use the syntax S$A to mean that the
symbol S has a value that can be called $A within an action, then
let's use plain S to mean the symbol doesn't have a value. That's
even shorter, and simpler. So, something like this:
exp:
NUM$a { $$ = $a; }
| '-' exp$a %prec NEG { $$ = - $a; }
| '(' exp$a ')' { $$ = $a; }
| exp$a '+' exp$b { $$ = $a + $b; }
| exp$a '-' exp$b { $$ = $a - $b; }
| exp$a '*' exp$b { $$ = $a * $b; }
| exp$a '/' exp$b { $$ = $a / $b; }
| exp$a '^' exp$b { $$ = pow ($a, $b); }
We issue a diagnostic if the user attempts to combine this new
notation with the old $1, $2, $3 notation.