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: Hans Aberg
Subject: Re: Query about error recovery in bison
Date: Tue, 24 Aug 2004 18:54:33 +0200

At 15:05 +0530 2004/08/24, Ranjeeta wrote:
>       I am using 1.24 version of Bison. Please let me know if any
>other information is required.

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.

>       I have a query about the way error recovery should be done in
>bison. Here is the description:
>
>       I am writing a parser for an assembler. In assembler we need to
>consider 1 line at a time. No information is required in parser for the
>previous lines. As soon as parser gets an error it will be terminated
>and invoked again for the rest of the file.

My guess is that you will need more in order to handle jumps. But if you
only want to read one line at a time, invoking a new parser each time, then
write a loop that reads one line at a time, and if the line is non-empty,
sends it to your lexer/parser combination. If you are using Flex to
generate the lexer, don't forget to reinitialize the lexer for each
invokation. -- See the Flex manual or ask in  the Help-flex mailing list
  address@hidden
  http://mail.gnu.org/mailman/listinfo/help-flex


>       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.

(When generating errors by hand, there are two macros, YYERROR which does
not call yyerror (thus do it by hand) and YYFAIL which does.)


>       Also according to bison PDF in error recovery chapter (Please
>refer The YACC-compatible Parser Generator 25 February 2002, Bison
>Version 1.35) I read "To prevent an outpouring of error messages, the
>parser will output no error message for another syntax error that
>happens shortly after the first; only after three consecutive input
>tokens have been successfully shifted will error messages resume.".
>       Is it the reason that the parser is not behaving correctly for
>simultaneous invalid inputs? If so I want to control this specification
>as per my requirement. Please suggest me for this too.

It may or may not. It is easy to alter this by changing the skeleton file
(which is in the "data" directory, called yacc.c for the C parser). There
is a label "yyerrlab1:" which alters a variable yyerrstatus. I think you
may try to change the line
    errstatus = 3;
to
    errstatus = 1;
Find a new name for this altered skelton file and call it using the
--skeleton option.

If you decide to send one line at a time to your lexer/parser combination,
reinitializing it for each new line, then you do not need to do this.

  Hans Aberg






reply via email to

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