help-bison
[Top][All Lists]
Advanced

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

Re: Bison & flex on start conditions


From: Henrik Sorensen
Subject: Re: Bison & flex on start conditions
Date: Mon, 16 Jan 2006 21:55:24 +0000
User-agent: KMail/1.8.3

On Monday 16 January 2006 16.46, Steve Murphy wrote:
> On Mon, 2006-01-16 at 08:56 +0000, Evan Lavelle wrote:
> > Henrik Sorensen wrote:
> > > For the pl1 problem, I cheated a bit with flex, and when certain
> > > conditions are met I simply save all the token met, and then change
> > > them to what I need before returning the tokens to bison. If you are
> > > interested in more feel free to contact me, or better look at the code
> > > (pl1gcc.sourceforge.net).
> >
> > This is great if you can do it, but it means that you're doing the
> > parsing in lex ('when certain conditions are met'). 
Agree. But this is really basic, and if it would have been more complex, I 
could have written a separate bison grammar to check for whatever conditions 
I need. Btw, This is how the pl1 preprocessor will be implemented, just one 
scanner but different grammars for the parsing.
> > If your analysis is 
> > so complex that you can't do it in lex, then you really need to do it in
> > bison, where you run into the potential look-ahead problem. What makes
> > the problem even worse is that you're not even guaranteed that there
> > *is* a look-ahead token: sometimes there is, sometimes there isn't.
> >
> > Evan
>
> Bingo!
>
> There are times you can set things up in flex to recognize the start
> condition. That's trivial! But when you have to store up a lot of
> material in flex, and then return tokens in any of N different ways,
> then yes, you are implementing the grammar in the flex scanner to some
> degree. 
Well to the extend you can write the regular expression this is ok.
> Really, in many context-dependant grammars, the grammar is the 
> pudding in which the different contexts are embedded, and the grammar is
> best and simplest place to specify which set of tokens it would like to
> see parsed. And because flex and bison have no way to communicate on
> this issue, we end up going to sometimes ridiculous (and most likely
> buggy) lengths to work around the problem.

murf, Evan

Do you have any references to some more concrete projects or samples ?
I am really interesting in this. 

>
> Am I dreaming wildly impossible dreams?
>
> murf
Henrik




reply via email to

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