|flex states vs. bison lookahead email@example.com (1999-08-27)|
|Re: flex states vs. bison lookahead firstname.lastname@example.org (Armel) (1999-09-05)|
|Date:||5 Sep 1999 02:42:08 -0400|
Paul van Bemmelen a écrit ...
>I have a flex scanner that contains a number of states, and action
>code in the bison parser that can trigger a flex state change.
>How can I know that when bison reads a lookahead token, it is the
>correct one? Because of bison action code, that may trigger a flex
>state change, the scanner may not be in the correct state for the
Don't if it will be the very thing you wanted to know but here's how an LALR
parser works :
Imagine you ve got a rule :
A := B C a
B := /* nothing */
C := c
Yacc will know he has found the B only after the 'c' was read. So if you
change the state of your lexer when reading 'c' you'll have :
on the string : 'ca'
State 0 1 1 1
Next Character to lex c a / /
Lookahead / c a /
Rule found / B C A
OK ? in fact, the state of the lexer is more or less always one state after
the you expected if you had used an LL parser (but you can't have the power
of LALR without that).
Obviously, making just states with Lex does a (very simple) LL parser (if
you don't use right context in your reg exprs).
Return to the
Search the comp.compilers archives again.