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: Fri, 24 Nov 2006 20:07:28 +0100

On 24 Nov 2006, at 18:30, Joel E. Denny wrote:

I still wonder if ISO EBNF is the right language.  Aren't most
Lex and Yacc users more familiar with notations like "(...)*", "(...)?",
and "(...)+"?

Yes, quite likely.  I wouldn't be a slave to ISO EBNF (particularly
since we're already incompatible with it :-), but it can't hurt to be
inspired by it.

Then we need not fuss over [] being for options anymore.

Not for the sake of this standard.

But otherwise, it seems good to do what Flex is already doing. It might be confusing switching syntax.

The argument there isn't about the choice of "/" or "#" or "()" or "[]". It's about the choice of "!" (or "-" in the current discussion) to mean
nothing.  I prefer the empty string to mean nothing.

OK, how about this idea? If rules use the syntax S$A to mean that the
symbol S has a value that can be called $A within an action, then
let's use plain S to mean the symbol doesn't have a value.

What about default names?  Must the user write?

  grammar$grammar: rules$rules decls$decls epilogue$epilogue {
    $grammar = new_grammar ($rule, $decls, $epilogue);
  }
  ;

I prefer:

  grammar: rules decls epilogue {
    $grammar = new_grammar ($rule, $decls, $epilogue);
  }
  ;

If you think those are needed.

Also, why $ now instead of #? $ makes it look like it works for values
and not locations.

This is why I think OO: The variables indicated in the grammar rules really are parser stack locations. From them, one extracts semantic value, location, possibly more.

Therefore, I favor "/" or "#". I think though that the ability to put rule actions outside the rule will help up the readability of the rules. So I arrive at the following (already posted, but possibly lost when the mail server went down):

  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); }

Here, identical actions need only be written once.

  Hans Aberg






reply via email to

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