> 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 _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison