Error Recovery in Yacc

Vicki Tardif <>
Wed, 23 Aug 1995 14:31:36 GMT

          From comp.compilers

Related articles
error recovery in yacc (Shiladitya Biswas mt cse) (2003-01-12)
error recovery in yacc mcvax!!jh@seismo.CSS.GOV (1987-08-17)
error recovery in yacc (Gopal Gupta) (1987-08-18)
Re: error recovery in yacc harvard!seismo!sun!academ!nuchat!steve (1987-09-04)
Re: error recovery in yacc ...mcvax!ukc!warwick!julia (1987-09-04)
Error Recovery in Yacc (Vicki Tardif) (1995-08-23)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Vicki Tardif <>
Keywords: yacc, errors, comment
Organization: net.Genesis Corp.
Date: Wed, 23 Aug 1995 14:31:36 GMT


    I am trying to use lex and yacc to write a parser, but I am running
into some problems with the error recovery. I have searched through the
O'Reilly book, but I can't seem to find the answer to my problem.

    Basically, my problem is when the parser comes across a token it
doesn't expect. For example, if I have the rules:

                                | command_sequence command

command: subject verb object

subject: (The list of possible subjects.)

verb: (List of verbs)

object: (List of objects)

    When I run my parser on a file, if it is looking for a subject and
it comes across something else (like a verb), the parser doesn't
recognize any more rules (even if there are valid commands after the
error) until it completes on a rule which started before the error.

    I would like to store the offensive token and put the parser into a
state where it can continue happily, but unfortunately, I can't find
any resources which discuss this. Does anyone know how to achieve
this, or is there a better way to recover from this error? I suppose
I could use the brute force method of adding tons of rules to handle
the offensive tokens, but if possible, I would like to use a more
elegant solution.

  - Vicki

Vicki Tardif ----------------------------------- voice: (617) 577-9800
net.Genesis fax: (617) 577-9850
56 Rogers St
Cambridge, MA 02142 ---------------------------
[Yacc error recovery is a losing battle if you want to do much more than
resync at a punctuation mark. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.