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 18:37:40 +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

Here is another attempt at analyzing what is going on:

Put in variable defaults in a C-function:
  int add(int(), int y) {
    return add + y;
  }

  int() add(int x, int y) {
    add = x + y;
  }
Only the last one might have some acceptance.

Now, in the case what is the name of the function? If a CFG rule is written
  x -> x_1 ... x_k
then it seems that the name is "->", i.e., one has in reality
  ->(x, x_1, ..., x_k)
In other words, the values, semantic, location, possibly more are not functions of the grammar variables in the rules, but really of the rule position. The grammar variables already act as plugin values in these rules.

This last principle might explain why it is so hard to get a good way of naming the default variables. It makes me worry whether the idea is right.

Therefore I end up with an outline of a proposal as follows:

* Rule variables can be named using a "/".
* Actions can be named using a "#".
* The empty rule can be given the name "0". If the compiler should require this use (resp. absence of it), there are options %empty- named (resp. %empty-not-named). * The Bison compiler has an option where warnings against unused variables can be turned on. When on, the behavior of this option can be fine tuned using option %unused, %used, (or %unused-value, %used- value) applicable to rule variables and their subcomponents, as well as on tokens.

So it would look like

%empty-named
%used-value INTEGRAL_NUMBER

  expression-sequence:
      0
    | expression-sequence ',' expression
  ;

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

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

Etc.

  Hans Aberg






reply via email to

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