bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: default %printer/%destructor


From: Hans Aberg
Subject: Re: FYI: default %printer/%destructor
Date: Wed, 22 Nov 2006 20:55:57 +0100

On 22 Nov 2006, at 20:28, Paul Eggert wrote:

I sort-of liked ".", but it isn't really component selection,

I took it from attribute grammrs in Waite & Goos.

and
anyway that collides with existing practice, which allows "." in
identifiers (POSIX requires support for this), so that's out.  Of the
other characters unused by ISO EBNF, ":", "%", and "_" are also
reserved by POSIX.  "$", "\", and "<" have special meanings in Solaris
10 /usr/ccs/bin/yacc (for example, "$" is a valid character in
identifiers), so it's better not to use them in case we ever want to
support those special meanings compatibly.  That leaves "!+@&#>/^`~".

I suggested "/".

How about this notation, which is in something of a different and
more-restricted style?

  a#1: a#2 b c d;

The '#1' and '#2' serve to disambiguate the 'a's.  In the action, one
writes $a#1 to get the value for the first a, and $a#2 for the second.
One writes @a#1 and @a#2 for locations.  One writes $b and @b for b's
action and location, and similarly for c and d.

The idea is to avoid renumbering problems, and therefore use names alone. But any symbol would be OK.


For example, instead of this:

  exp(result):
      NUM
        { $result = $NUM; }
    | '-' exp(subtrahend) %prec NEG
        { $result = - $subtrahend; }
    | '(' exp(subexpression) ')'
        { $result = $subexpression; }
    | exp(augend) '+' exp(addend)
        { $result = $augend + $addend; }
    | exp(minuend) '-' exp(subtrahend)
        { $result = $minuend - $subtrahend; }
    | exp(multiplicand) '*' exp(multiplier)
        { $result = $multiplicand * $multiplier; }
    | exp(numerator) '/' exp(denominator)
        { $result = $numerator / $denominator; }
    | exp(base) '^' exp(exponent)
        { $result = pow ($base, $exponent); }

you write this:

  exp:
      NUM               { $$ = $NUM; }
    | '-' exp %prec NEG { $$ = - $exp; }
    | '(' exp ')'       { $$ = $exp; }
    | exp#1 '+' exp#2   { $$ = $exp#1 + $exp#2; }
    | exp#1 '-' exp#2   { $$ = $exp#1 - $exp#2; }
    | exp#1 '*' exp#2   { $$ = $exp#1 * $exp#2; }
    | exp#1 '/' exp#2   { $$ = $exp#1 / $exp#2; }
    | exp#1 '^' exp#2   { $$ = pow ($exp#1, $exp#2); }

This can become cumbersome when writing:

  exponential:
      INTEGRAL_NUMBER           { $$ = $INTEGRAL_NUMBER; }
    | '-' exponential %prec NEGATION    { $$ = - $exponential; }
    | '(' exponential ')'       { $$ = $exponential; }
| exponential#1 '+' exponential#2 { $$ = $exponential#1 + $exponential#2; } | exponential#1 '-' exponential#2 { $$ = $exponential#1 - $exponential#2; } | exponential#1 '*' exponential#2 { $$ = $exponential#1 * $exponential#2; } | exponential#1 '/' exponential#2 { $$ = $exponential#1 / $exponential#2; } | exponential#1 '^' exponential#2 { $$ = pow ($exponential#1, $exponential#2); }

Instead of the simpler:

  exponential:
      INTEGRAL_NUMBER#x         { $$ = $x; }
    | '-' exponential#x %prec NEGATION  { $$ = - $x; }
    | '(' exponential#x ')'     { $$ = $x; }
    | exponential#x '+' exponential#y   { $$ = $x + $y; }
    | exponential#x '-' exponential#y   { $$ = $x - $y; }
    | exponential#x '*' exponential#y   { $$ = $x * $y; }
    | exponential#x '/' exponential#y   { $$ = $x / $y; }
    | exponential#x '^' exponential#y   { $$ = pow($x, $y); }

If it's important to say a value can be unused, that could be written
"a#-", or something like that.

I think this sounds interesting.

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]