[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: interesting push parser use case
From: |
lfinsto1 |
Subject: |
Re: interesting push parser use case |
Date: |
Sun, 9 Sep 2007 11:03:13 +0200 (CEST) |
User-agent: |
SquirrelMail/1.4.9a |
> On Sat, 8 Sep 2007, Bob Rossi wrote:
>
>> The first issue is that I probably need a way to tell the parser that
>> I'm done giving it tokens. That way, it will finish all of it's rules.
>> Is there already a way to do this?
>
> Yacc-generated parsers expect the last token in the input stream to be
> token 0. In the .output file, it's called $end.
You can also just call `return <integer value>' from the action of any
rule. This will cause `yyparse' to return to its caller. Of course, if
you're allocating memory on the heap, you will have to make sure you
recover it, so as to avoid memory leaks.
>
>> The second issue is slightly more fuzzy. Essentially, after each token I
>> give to the parser, it would probably be useful to know if it just
>> finished a particular rule, and if so, which rule.
>
> Could you use %parse-param to pass a pointer to a variable to be set by
> the semantic action of that rule?
>
Yes. Personally, I think this would be overkill in most situations, but
if it's useful to you I don't see any problem with it. I do recommend
using a pointer to an object of a `struct' or `class' type, so you could
use the object passed as a parameter to `yyparse' (and `yylex') for other
purposes, too.
I would also wrap the code for setting it in #ifdef WHATEVER ... #endif,
so that it's conditionally compiled. This way, you could build the
program without the overhead of this feature, if you don't always need it.
Laurence Finston