help-bison
[Top][All Lists]
Advanced

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

Re: Any Method of reading the token values off the stack


From: Tim Zimmerlin
Subject: Re: Any Method of reading the token values off the stack
Date: Wed, 5 May 2004 21:49:05 -0400

Hans,

I understand that the state is embedded together with the symbol values on the stack; however, I do not know the memory structure. We know that an LALR(1) parser generated by bison supplies the $1, $2, etc. values from the stack somehow to the actions of the rules.

I would like some API that I can call from the actions of the rules. Error recovery needs only "read access" in order to output the token values in their proper order for later manual editing. After encountering an error, the parser resynchronizes (I hope). I intend to let the normal error recovery pop all the incorrect symbols off the stack to get to a recovery state.

Is there some way within the actions to determine the number of symbols & the symbol values? The symbol values held in the stack are lost during normal error recovery, leaving a hole around the error in the input sequence of symbols.

I hesitate to modify the stack because I hope it is not necessary. I hesitate to create a separate parse structure due to performance.

Thanks,
Tim Zimmerlin

On May 5, 2004, at 1:22 PM, Hans Aberg wrote:

At 23:23 -0400 2004/05/04, Tim Zimmerlin wrote:
In my error recovery processing, I want to read the token values in
FIFO order off the stack, in yyerror(), before flushing it as part of
the default "error" rule processing

Does bison provide direct stack access functions/macros? I would like
to know how many tokens are on the stack. I would like to read them in
FIFO rather than LIFO order to save them as originally read.

Bison produces an LALR(1) parser, which on its stack only contains
arbitrarily numbered LALR(1) states, represented by integral values. These
state numbers are described in the .output file that Bison writes when
invoking the --verbose option. They represent something more complicated
than just token values: so called sets of items, where an item is
essentially a parser rule with a dot indicating how far the parsing has
proceeded.

So the parser stack never contains any tokens. If you need to use such
info, you must put it there yourself.

  Hans Aberg







reply via email to

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