help-bison
[Top][All Lists]
Advanced

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

Re: valid lookahead


From: Nils Hasler
Subject: Re: valid lookahead
Date: Mon, 28 Jan 2002 11:30:24 +0100

thanks,
but this one only tells me its name - I need the constant.

> >>>>> "Nils" == Nils Hasler <address@hidden> writes:
>
> Nils> hi.  I would like to be able to figure out which terminals are
> Nils> valid in any state of my parsing - just like y.output tells
me.
>
> Nils> So where in those tables can I find valid terminals following
my
> Nils> current state.
>
> Have a look at out bison prepare the error message in the
> YYERRROR_VERBOSE case (in the parsers).  Steal the code from there:
>
>
> /*------------------------------------.
> | yyerrlab -- here on detecting error |
> `------------------------------------*/
> yyerrlab:
>   /* If not already recovering from an error, report this error.  */
>   if (!yyerrstatus)
>     {
>       ++yynerrs;
>
> #ifdef YYERROR_VERBOSE
>       yyn = yypact[yystate];
>
>       if (yyn > YYFLAG && yyn < YYLAST)
> {
>   YYSIZE_T yysize = 0;
>   char *yymsg;
>   int yyx, yycount;
>
>   yycount = 0;
>   /* Start YYX at -YYN if negative to avoid negative indexes in
>      YYCHECK.  */
>   for (yyx = yyn < 0 ? -yyn : 0;
>        yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
>     if (yycheck[yyx + yyn] == yyx)
>       yysize += yystrlen (yytname[yyx]) + 15, yycount++;
>   yysize += yystrlen ("parse error, unexpected ") + 1;
>   yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
>   yymsg = (char *) YYSTACK_ALLOC (yysize);
>   if (yymsg != 0)
>     {
>       char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
>       yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
>
>       if (yycount < 5)
> {
>   yycount = 0;
>   for (yyx = yyn < 0 ? -yyn : 0;
>        yyx < (int) (sizeof (yytname) / sizeof (char *));
>        yyx++)
>     if (yycheck[yyx + yyn] == yyx)
>       {
> const char *yyq = ! yycount ? ", expecting " : " or ";
> yyp = yystpcpy (yyp, yyq);
> yyp = yystpcpy (yyp, yytname[yyx]);
> yycount++;
>       }
> }
>       yyerror (yymsg);
>       YYSTACK_FREE (yymsg);
>     }
>   else
>     yyerror ("parse error; also virtual memory exhausted");
> }
>       else
> #endif /* defined (YYERROR_VERBOSE) */
> yyerror ("parse error");
>     }
>   goto yyerrlab1;
>
>
> _______________________________________________
> Help-bison mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/help-bison




reply via email to

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