[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parsing from continuous stream
From: |
Bob Rossi |
Subject: |
Re: Parsing from continuous stream |
Date: |
Sat, 19 Jan 2008 15:46:50 -0500 |
User-agent: |
Mutt/1.5.15+20070412 (2007-04-11) |
On Sat, Jan 19, 2008 at 05:33:32PM +0000, Daniel Kraft wrote:
> Hi,
>
> I'm trying to use GNU bison to parse from a "continuous" stream, that is, I
> do want to implement a program similar to a shell: parse one "command" at
> a time, process it, and continue until end-of-stream is encountered.
>
> However, I do want my parser to return the parsed tree to the calling
> program to process it on each step, so ideally I'd like bison to return
> from yyparse() when a complete instance of the start symbol is read, but it
> seems it does not do this (waits for special 0-token, as far as I found
> out)--to counter-act, I currently do something like this:
>
> start_symbol:
> real_start_symbol
> {
> storeValueForProcession($1);
> YYACCEPT;
> }
> ;
>
> This works, except that the YYACCEPT seems to discard the current
> look-ahead-token if some has been read, meaning it is missing from the
> input when parsing the next step.
>
> I'm aware that I could do the processing right inside the bison action
> instread of returning the token value, but this is something I'd like to
> avoid because it does not fit in well with my current design. Is there
> some way I can make bison return whenever the start-symbol is successfully
> reduced and keep its stack and the like so I can continue parsing the next
> instance of it with the next call to yyparse()?
Aha, Yes!
Use the push parser that I have just implemented in Bison. You will be
the first beta tester. The documentation should be in CVS and you need a
CVS version of bison.
Bob Rossi