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: Sun, 26 Nov 2006 13:30:12 +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, another way analyzing what is going on.

Symuppse the grammar and action language identifiers have different syntax. If the former, but not the latter, accepts "-" in identifiers, then one could write:

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

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

Here, it does not work in the actions, because the variable names contain "-". The reason is that syntax of two different languages (i.e., grammar and action languages) are mixed indiscriminately.

So, strictly speaking, the explicitly indicated variables should follow the action language syntax, though that may not be fully possible. One way to ensure this, though, might be to somehow admit C- strings as variable names. For example:
  expression:
    ...
    | expression/"#1" '+' expression/"#2"   { $#1 + $#2 }
    ...
    ;
if there is an action variable that admits "#" in the variable names.

  Hans Aberg






reply via email to

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