help-bison
[Top][All Lists]
Advanced

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

Re: How do lexical tie-ins work?


From: Joel E. Denny
Subject: Re: How do lexical tie-ins work?
Date: Fri, 23 Apr 2010 15:12:17 -0400 (EDT)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

On Fri, 23 Apr 2010, Zachary Carter wrote:

> I'm curious on how Bison's algorithm works wrt lexical tie-ins[1]. The
> situation appears to me as a bit of a catch-22. The parser checks the
> lookahead token to decide when to reduce (right?)

Not always.  If the parser doesn't need a lookahead because there's only 
one possible parser action, then it doesn't fetch a lookahead from the 
scanner.

> but the semantic action
> may alter the scanner so that the next token shifted is actually different
> than what the lookahead token had been. It seems counter intuitive, but is
> that really how it works?

No, the semantic action would have to modify the stored lookahead (yychar) 
not the scanner behavior (using hexflag, for example) to make that happen.

> [1]: http://www.gnu.org/software/bison/manual/bison.html#Lexical-Tie_002dins

Here's the relevant production from that example:

  expr: HEX '(' { hexflag = 1; } expr ')' { hexflag = 0; $$ = $4; }

The assumption is that, after HEX '(', the mid-rule is the only possible 
action, so hexflag = 1 is set before the next token after '(' is fetched.




reply via email to

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