On 4 Feb 2009, at 17:06, José Alburquerque wrote:
I'm guessing that bisonc++ also generates a .output file. Would you
or anyone else know?
It is an unrelated program. Bison now has lalr1 skeletons for C++ and
Java.
One problem is that the LALR(1) parsing algorithm that Bison uses
makes state compaction which may admit some reductions before a
state where the error/lookahead tokens appears. So this method may
note be correct - strictly speaking, one should use LR(1). But the
problem may not be too severe.
Are there other tools that work with LR(1)? Maybe I can look into
those if they exist. Thanks for your answers. Really appreciate it.
The problems is that also those may do some compaction - they just
guarantee compiling all LR(1) grammar.
It might be possible to do a correct token completion also by looking
down the reductions. Only that no one has implemented it yet.
Basically, you need an array indexed on the states telling which
tokens are legal. You might backtrack around what the Bison parser
writes as:
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
The parser function yyparse() has a segement:
/* Read a lookahead token. */
if (yychar == yyempty_)
{
YYCDEBUG << "Reading a token: ";
yychar = yylex (&yylval);
}
My guess is that you want to be able to stop right before the
yychar = yylex (&yylval);
line and produce a list of valid tokens.
If you look at the code following it, it looks as though the state
information is seqeunced in YYTABLE, and the segment is found using
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
So perhaps, it might be possible to extract the information from the
already present arrays.
Also, the has been a "push parser" implemented into Bison, which I
think is letting the lexer supply tokens one-by-one, and the Bison
parser processes as much as it can. - Perhaps this is what you need.
Hans
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison