help-bison
[Top][All Lists]
Advanced

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

Re: glr parser and getting semantic values from the lexer


From: Akim Demaille
Subject: Re: glr parser and getting semantic values from the lexer
Date: Mon, 21 Dec 2020 17:30:46 +0100


> Le 20 déc. 2020 à 21:55, Jot Dot <jotdot@shaw.ca> a écrit :
> 
> I feel real dumb asking this but,
> 
> How do you pass values back from the lexer when using %glr-parser?

First of all, you need to understand that when you are in nondeterministic mode,
the actions are delayed, the scanner and the parser are no longer running in
lock step.  In other words, no lexical tie-ins in nondeterministic sections
of a GLR parse.

> I know I must use POD data types.
> In the .y file, I am using:
> 
> %define api.value.type union
> %token <int64_t> CONSTANT
> 
> and in the lexer file:
> {inum}        {       // Integer
>               int64_t number = strtol(yytext, NULL, 10);
>               ??? = number; // What do I do here?

https://www.gnu.org/software/bison/manual/html_node/Type-Generation.html

>               return MyPrefix::MyParser::token::CONSTANT;
>       }
> 
> yylval is not defined. I have read you shouldn't really modify it anyways,
> for reasons mentioned in the manual (which make sense).

It is up to you to define it in the scanner.  See api.pure for examples.
And also, have a look at the examples in examples/c++.

Cheers!


reply via email to

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