help-bison
[Top][All Lists]
Advanced

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

RE: Query about error recovery in bison


From: Ranjeeta
Subject: RE: Query about error recovery in bison
Date: Thu, 26 Aug 2004 15:13:33 +0530

Hi Hans Aberg,

Thanx for the prompt reply.
I have some more questions to ask. Please have a look at them too.


At 10:25, 2004/08/24, Hans Aberg wrote:
(snip)
> You should upgrade to at least Bison 1.75 (there are also at
> least some beta 1.875x). These later versions will require
> the macro program M4 to be installed as well.

>From the very beginning we are use Bison 1.24. The set up of the higher
versions are bit different from Bison 1.24 so I was not going for the
higher versions. Do you think I will face any problem with 1.24 version?
I mean any known bugs in this version?

> >     I want that I should specify the production rules for
> the inputs which
> >are valid to the assembler. The other inputs should be automatically
> >treated as invalid and parser should call yyerror. But this is not
> >happening. Sometimes parser terminates without calling yyerror. This
> >usually happens when the illegal input is the 1st input or it is
> >preceded by some other invalid input line. Can any one
> suggest me why?
>
> When the parser detects a parse error, if you have set
>     #define YYERROR_VERBOSE 1
> the parser will write a segment about the parse error (which
> tokens were to be expected) and then call yyerror with that
> string as an argument.

Yes I tried using #define YYERROR_VERBOSE 1. It seems it will work but
then I have some doubts too.  Following is the code for yyerrlab:

yyerrlab:   /* here on detecting error */
  if (! yyerrstatus)
    /* If not already recovering from an error, report this error.  */
    {
      ++yynerrs;
#ifdef YYERROR_VERBOSE
      yyn = yypact[yystate];
      if (yyn > YYFLAG && yyn < YYLAST)
        {
          int size = 0;
          char *msg;
          int x, count;
          count = 0;
          /* Start X at -yyn if nec to avoid negative indexes in
yycheck.  */
          for (x = (yyn < 0 ? -yyn : 0);
               x < (sizeof(yytname) / sizeof(char *)); x++)
            if (yycheck[x + yyn] == x)
              size += strlen(yytname[x]) + 15, count++;
          msg = (char *) malloc(size + 15);
          if (msg != 0)
            {
              .....
                ....
                yyerror(msg);                   ======> Error issued 1st
time.
              free(msg);
            }
          else
            yyerror ("parse error; also virtual memory exceeded");
        }
      else
#endif /* YYERROR_VERBOSE */
/*      if(CalledYYParse)*/
        {
                if(*yyssp == 0 && *yyss == 0)
                {
                        return ;
                }
      }
        yyerror("parse error");                 ========> Error is
issued 2nd time.
    }
  goto yyerrlab1;

Code in the #ifdef YYERROR_VERBOSE uses the array of tokes yytname.
yytname is defined under #if YYDEBUG != 0, so I had to use following
code also:
#define YYDEBUG 1

Now I am getting 2 errors for each invalid lines. Please see I have
annotated in the code for the positions from where error is issued. The
reason for this is that code after #endif of #ifdef YYERROR_VERBOSE also
gets executes and hence yyerror is called again.

I think this is a defect in the above code. Is my understanding correct?
Can I remove the 2nd yyerror function call?


With Best Regards,
Ranjeeta Sharma.






reply via email to

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