bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistency between %token and %associativity


From: Hans Aberg
Subject: Re: Inconsistency between %token and %associativity
Date: Sat, 13 Oct 2001 15:57:42 +0200

At 13:56 +0200 2001/10/13, address@hidden wrote:
>but another solution is of course fixing the doc.  What do you people prefer?

I have the idea of restyling Bison so it becomes more logical in its
structure. This includes fixing such problems you are mentioning, perhaps
require an explicit symbol for the empty string and disallowing the ";"
termination, and other changes such as making output files have a ".y" or
nothing, making characers print out and a %unicode option making token
numbers start at (say) 2^24 + 1.

One could start with such things now, or waiting until one is sure that the
other problems with 1.29 have been fixed.

One would then have to add options like "--syntax" or %... in order to
ensure backwards compatibility.

>the declarations (%token vs %associativity) are *not* the same.  If you write
>
>%token FOO "foo"
>%left  BAR "bar"
>
>then you have defined *three* tokens: FOO == "foo", and BAR, *and* "bar".

As for this problem itself, the Bison refcard says that the associativity
commands are the same as %token, a token declaration, except that they in
addition defines associativity of the token.

So from this point of view, it sounds best to make sure that a token symbol
appears exactly once, either in a %token declaration or an %<associativity>
declaration, and any duplicates causes an error.

Thus in the example above, one would only define two tokens, FOO with the
alternate name "foo" and BAR with the alternate name "bar".

Writing
  %token FOO "foo"
  %token bar "bar"
  %left BAR "bar"
would then be an error, as one tries to define "bar" twice, and so would
  %token FOO
  %left FOO
as each terminal should be declared exactly once.

There is an alternate version, and that is to require only %token to define
terminals, and the let %<associativity> only to add the associativy (and
precedence). In this case only writing
  %left BAR
with no
  %token BAR
would generate an error.

  Hans Aberg





reply via email to

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