help-bison
[Top][All Lists]
Advanced

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

Re: Getting a Counter


From: Akim Demaille
Subject: Re: Getting a Counter
Date: Fri, 1 Oct 2021 08:42:47 +0200

Hi,

> Le 1 oct. 2021 à 07:16, Guenther Sohler <guenther.sohler@gmail.com> a écrit :
> 
> Hi,
> In my parser i don't want flex to return comments in my code as flex tokens.
> Instead i want to store them in a different list together with their
> position.
> 
> Lateron i am using their position to included them in the code again.
> For that reason i am interested to know the Token position in the parsed
> stream.
> Ideally i need the number in the exact same scope as its displayed during
> ambiguity resolution.
> After some googling i could not find such a feature.
> Does anybody know such a variable next to yylval or yytext ?

If your question is how to deal with that in the parser (this is bison-help), 
then you may either use a custom definition of locations and store that in 
yylloc, or declare yystype a struct, something like

struct {
  const char* comments;
  int file_pos;
  union {
    const char* sval;
    int ival;
  };
}

and store whatever you need in there.

If you're asking about how can the scanner track positions, then this is not 
the right place.  But I would probably use YY_USER_ACTION to add in each rule 
something like pos = end_pos; end_pos += yyleng.

Cheers!


reply via email to

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