help-bison
[Top][All Lists]
Advanced

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

Re: mapping token identifier to value


From: Akim Demaille
Subject: Re: mapping token identifier to value
Date: Mon, 17 Dec 2018 06:28:21 +0100

Hi!

> Le 14 déc. 2018 à 14:21, r0ller <address@hidden> a écrit :
> 
> Hi Akim,
> 
> I'm trying to get rid of numbering tokens and let bison do that but it seems 
> to be more difficult than I thought. Although, I managed to come up with an 
> idea as I'm anyway generating the bison source I could generate a map like:
> 
>     std::map<std::string, unsigned int> symbol2token={
>             { "t_Con", yy::parser::token::t_Con },
>             ...
>     };
> 
> and could then get the values simply by:
> 
> symbol2token.find("t_Con")->second;
> 
> However, still wanted to ask if there's any better solution maybe one that I 
> overlooked and is provided by bison itself;)

I personally would go for this solution.  I agree it is tedious,
but that's anyway what happens in a typically scanner in Lex.  And
that's probably something you already do somewhere, but with your
own token numbers assigned by hand, so it's probably not very
different.


reply via email to

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