[Top][All Lists]

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

Inconsistency between %token and %associativity

From: akim
Subject: Inconsistency between %token and %associativity
Date: Sat, 13 Oct 2001 13:56:04 +0200
User-agent: Mutt/1.3.22i

Something I like in Bison is the possibility to specify the way tokens
should be displayed in error messages, to be user friendly instead of 
displaying internal details such as the name of the TOKENs.

But there is an inconsistency:

Operator Precedence

   The syntax of a precedence declaration is the same as that of
`%token': either

     %left SYMBOLS...


     %left <TYPE> SYMBOLS...

says the documentation.

But as demonstrated in the example:

Token Type Names

   You can associate a literal string token with a token type name by
writing the literal string at the end of a `%token' declaration which
declares the name.  For example:

     %token arrow "=>"

For example, a grammar for the C language might specify these names with
equivalent literal string tokens:

     %token  <operator>  OR      "||"
     %token  <operator>  LE 134  "<="
     %left  OR  "<="

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".

I'm all for uniformization, i.e., that the example above becomes wrong,
(i.e., triggers an error : OR is already mapped to "||" and "<=" is already
used, since it is read as a request to alias OR and "<=") and has to be written

     %token  <operator>  OR      "||"
     %left   <operator>  LE 134  "<="


     %token  <operator>  OR      "||"
     %token  <operator>  LE 134  "<="
     %left  OR  LE

but another solution is of course fixing the doc.  What do you people prefer?

reply via email to

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