help-bison
[Top][All Lists]
Advanced

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

Re: Strange behavior


From: Hans Aberg
Subject: Re: Strange behavior
Date: Fri, 30 Apr 2004 18:46:26 +0200

At 17:22 +0200 2004/04/30, Laurent Deniau wrote:
>>  >> The strings are only exported to the parser to
>>  >> a table used for error message printouts, which has strings in it
>> anyway.
>>  >
>>  >But you still need to write the rule with LP and RP.
>>
>> No, use the strings in the rule. This makes the grammar much more readable:
>>
>>  >direct_abstract_declarator
>>  >       : LP abstract_declarator RP
>>
>> Instead of this, write:
>>
>> %token LP "("
>> %token RP ")"
>> ...
>> %%
>> ...
>>   direct_abstract_declarator:
>>       "(" abstract_declarator ")"
>>
>> Then, except for parser error messages, "(" and ")" are only used
>> internally in Bison. These strings do not have to be what the lexer scans
>> for, as it will return RP and LP.
>
>I do not catch completly your point.
>
>First I use '(' and ')' which is as clear as "(" and ")" but uses
>character instead of string. So no problem with that specific case.
>
>Second, you say that "(" and ")" could be used directly in a rule?

Single and double quotes have different meanings in Bison: A single quote,
like '(' and ')' will use the ASCII (if that is the encoding your platform
uses) character codes as token numbers. The double quotes, like "(" and
")", if written as
  %token LP "("
  %token RP ")"
will be synonyms for the token names given in the token declaration. These
strings are also used in error messages.

> I
>thought that the rules where described using tokens or rules (internaly
>treated as non terminal token) and tokens were int (or unsigned int)
>with specific unique id assigned by Bison.

So Bison will convert a string so %token declared found in a rule into its
token number.

Character tokens and such strings will be converted into the same integral
type used for the Bison uses for token numbers. (I think that in later
Bison versions, this integral type can be altered as well.)

  Hans Aberg






reply via email to

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