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 22:52:33 +0100

On 22 Nov 2006, at 20:55, Hans Aberg wrote:

This can become cumbersome when writing:

  exponential:
...
It should have been:

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

And the simpler:

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

Another idea (which I mentioned earlier) might be allowed to lift the action definitions out of the grammar definition, and be put elsewhere, say another file. Grammars with complicated actions might then become readable, and the grammar need not be recompiled when only the actions are altered (if put into another file).

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.

Warnings against unused variables is usually a compiler feature, not a language feature. So this suggestion breaks that principle, if it now is worth holding onto. :-)

Otherwise, I think getting variable names is quite important, as it is easy to do mistakes with the numberings when altering a rule. I would have less use for the unused variable warnings. I think a use of such a feature might be to turn it on sometimes, to check for problems, but otherwise having it off.

  Hans Aberg






reply via email to

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