help-bison
[Top][All Lists]
Advanced

[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: Mon, 21 Jan 2008 16:23:24 -0500
User-agent: Mutt/1.5.15+20070412 (2007-04-11)

On Sun, Jan 20, 2008 at 09:48:11AM +0000, Daniel Kraft wrote:
>>> 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;
>>>   }
>>> ;
>> 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.
>
> Thanks for the hint, it looks neat as far as I have seen yet!  But I'm not 
> yet sure how this will help me exactly; will yypush_parse return without 
> this YYPUSHMORE whenever it encounters the start symbol (or any symbol?), 
> so I can process it in my code and continue calling yypush_parse 
> afterwards, with the state including all look-ahead conserved?

Well, I actually hit this situation, and it's something I have to think
about for my own project. Basically, say you are looking to match a high
level rule over and over. The Bison parser will never want to stop
getting input, until you feed it EOF or some other token that stops the
parsing. So, it's most likely correct that you will continuing getting
YYPUSHMORE.

If you care, you can see I asked the exact same question here,
  http://lists.gnu.org/archive/html/help-bison/2007-09/msg00000.html
The answer is basically (which I haven't tried yet, yes I'm busy!),
  Could you use %parse-param to pass a pointer to a variable to be set by 
  the semantic action of that rule?

So basically, the idea is that you would pass in another structure to
the parsing function, and when the grammar recognized that a rule was 
matched from a particular token, it could set the output paramater. This
shoudl be thread safe as well.
  
> BTW, how does one bootstrap the autotools stuff for bison?  Trying myself 
> with aclocal; automake -a; autoheader; autoconf (like this) gives me errors 
> in the resulting configure related to gl_* symbols; I suspect that autoconf 
> is missing some m4-files or the like?

Well, I've never attempted to do it manually. I just run the script
'bootstrap'. I haven't done this in a few months, so, hopefully it's
still the same.

Bob Rossi




reply via email to

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