[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mapping token identifier to value
From: |
r0ller |
Subject: |
Re: mapping token identifier to value |
Date: |
Mon, 17 Dec 2018 09:46:09 +0100 (CET) |
Hi Akim,
Ok, thanks for the feedback! I haven't found any better either so I implemented
it and it seems to work but need to test it thoroughfully. Fortunately, as the
mapping is generated as well, it's not tedious at all:)
Best regards,
r0ller
-------- Eredeti levél --------
Feladó: Akim Demaille < address@hidden (Link -> mailto:address@hidden) >
Dátum: 2018 december 17 06:28:28
Tárgy: Re: mapping token identifier to value
Címzett: r0ller < address@hidden (Link -> mailto:address@hidden) >
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.