help-bison
[Top][All Lists]
Advanced

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

Re: Enum for token '0', EOF


From: Frans Englich
Subject: Re: Enum for token '0', EOF
Date: Sat, 8 Jul 2006 15:11:04 +0000
User-agent: KMail/1.8.50

On Wednesday 28 June 2006 15:01, Frans Englich wrote:
> I am using a hand-written tokenizer unfortunately(would be more practical
> to use Flex), and is using yytokentype in order to increase type safety of
> the code.
>
> A problem arrives when I need to return EOF, the '0' token. It requires me
> to engage in static_cast'ing 0 to yytokentype, which is ugly and error
> prone.
>
> Is there any clean solution to this on the Bison side? E.g, can I somehow
> generate a token(such as with %token) for EOF?

As Joel E. Denny answered on bison-patches:

<quote>
> Hm, could you elaborate on this? I would very much like to create a token 
for 
> token '0'(EOF).

%token END 0 "end of file"

You can find that somewhere in the C++ section of the manual.

Do you have any need to put END in your grammar?  Do you have any need to 
give it a semantic value?
</quote>

No, I don't have a need to put END in my grammar nor give it a semantic value, 
but I need to signal it in my hand written tokenizer(and it is messy to cast 
0 to the yytokentype enum).

Thanks for telling me, I didn't know one could specify the token valu, such as 
0 in '%token END 0 "end of file"'.


Cheers,

                Frans




reply via email to

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