help-bison
[Top][All Lists]
Advanced

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

Re: Example in Bison's documentation


From: Hans Åberg
Subject: Re: Example in Bison's documentation
Date: Tue, 11 Oct 2016 18:42:50 +0200

> On 11 Oct 2016, at 10:24, guillaume marques <address@hidden> 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. 





reply via email to

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