Related articles |
---|
flex states vs. bison lookahead bemmelen@iwma08.wt.tno.nl (1999-08-27) |
Re: flex states vs. bison lookahead webid@asi.fr (Armel) (1999-09-05) |
From: | "Armel" <webid@asi.fr> |
Newsgroups: | comp.compilers |
Date: | 5 Sep 1999 02:42:08 -0400 |
Organization: | WebID |
References: | 99-08-106 |
Keywords: | yacc, parse |
Hello,
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
>lookahead...!?
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 */
| b
C := c
| cd
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
comp.compilers page.
Search the
comp.compilers archives again.