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: Sat, 25 Nov 2006 16:37:18 +0100

On 25 Nov 2006, at 03:00, Joel E. Denny wrote:

You would need a rule telling, in the case of multiple occurrences, when the
default names can be used.

I addressed the problem of ambiguous names here:

http://lists.gnu.org/archive/html/bison-patches/2006-11/ msg00039.html

The question of default names is somewhat similar to that one of functions. What about:
int f(int) {
  return f + 1;
}
Here I use the function name as default for the variable name. I do not write this as polemics - the situation is not exactly the same, but similar.

But if "/" (say) is used to indicate a variable, the default naming will need another symbol to indicate the absence of a variable name. It is rather tight to use another symbol than "/", so perhaps "//" then. Thus:
  expression:
      INTEGRAL_NUMBER//                 #identity_INTEGRAL_NUMBER
    | '-' expression/x %prec NEGATION   #neg
    | '(' expression// ')'              #identity_expression
    | expression// '+' expression/y     #add
    | expression/x '-' expression//     #sub
    | expression// '*' expression/y     #mul
    | expression/x '/' expression//     #div
    | expression// '^' expression/y     #pow
  ;

identity_INTEGRAL_NUMBER { $$ = $INTEGRAL_NUMBER; }
neg { $$ = -$expression ; }
identity_expression { $$ = $expression ; }
add { $$ = $expression + $y; }
sub { $$ = $x - $expression; }
mul { $$ = $expression * $y; }
div { $$ = $x / $expression; }
pow { $$ = pow($expression, $y); }

Another idea is to admit say "0" for the empty expansion: it is normal to have a symbol for it in grammars, and the flexible grammar of Bison makes mistakes easy. Otherwise, one might have:

  expression:
      INTEGRAL_NUMBER/0                 #identity_INTEGRAL_NUMBER
    | '-' expression/x %prec NEGATION   #neg
    | '(' expression/0 ')'              #identity_expression
    | expression/0 '+' expression/y     #add
    | expression/x '-' expression/0     #sub
    | expression/0 '*' expression/y     #mul
    | expression/x '/' expression/0     #div
    | expression/0 '^' expression/y     #pow
  ;
...

  Hans Aberg






reply via email to

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