> On 11 Oct 2016, at 10:24, guillaume marques <guillaume.marq...@epita.fr> 
> wrote:

> I have a little question regarding an example in the Bison's documentation.
> 
> In the Section 7.2 Lexical Tie-ins, how come the provided example does what
> it is explained to do?
> 
> I understand the principle of the flags...

Bison implements an extra implicit rule:
expr: HEX ’(’ X1 expr ’)’
...
;

X1:
  /* empty */ { hexflag = 1; }
;

Because this rule is empty, and the parser may or may not make a lookahead, the 
result can be unexpected.

> ...but I don't understand how Bison can
> understand  when to parse the integer as an hexadecimal over an identifier
> since we never say, when the flag is nonzero, that we should parse an 
> hexadecimal,
> and when it is zero, to parse an identifier.
> 
> I only see that the flags are set but not used.

It is handled by the lexer (cf. the last sentence of that paragraph):

In appropriate places, the variable is read, and different lexing takes place. 
Flex admits start conditions that can be set before the lexing begins. 



_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to