help-bison
[Top][All Lists]
Advanced

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

Re: Using bison (or bisonc++) to create parser for command completion


From: José Alburquerque
Subject: Re: Using bison (or bisonc++) to create parser for command completion
Date: Wed, 04 Feb 2009 14:47:19 -0500
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

Hans Aberg said the following:
On 4 Feb 2009, at 17:06, José Alburquerque wrote:
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



Thanks a lot for your answers.  Again, much appreciated.

--
José Alburquerque
address@hidden





reply via email to

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