Re: YACC error handling

heirich@cs.ucsd.edu (Alan Heirich)
29 Jul 89 18:39:43 GMT

          From comp.compilers

Related articles
Re: YACC error handling heirich@cs.ucsd.edu (1989-07-29)
yacc error handling ajayk@microsoft.com (Ajay Kalhan) (1999-11-19)
Re: yacc error handling ajayk@microsoft.com (Ajay Kalhan) (1999-11-21)
Re: yacc error handling ewbank@lucent.com (Bryan Ewbank) (1999-11-23)
Re: yacc error handling zalman@netcom11.netcom.com (Zalman Stern) (1999-11-28)
Re: yacc error handling mschweis@u.arizona.edu (Michael C Schweisguth) (1999-12-07)
Re: yacc error handling wfahle@bigfoot.com (Bill Fahle) (1999-12-24)
| List of all articles for this month |

From: heirich@cs.ucsd.edu (Alan Heirich)
Newsgroups: comp.compilers
Date: 29 Jul 89 18:39:43 GMT
Organization: EE/CS Dept. U.C. San Diego

A correspondent asked about automatic error diagnostics in YACC-generated
parsers. I've modified the sources to an old version of YACC to provide two
things:


    -- automatic description of states, shifts, reductions, and error
          resynchronization during execution
    -- a function to produce a descriptive string of all of the lookahead
          tokens or goto nonterminals from a given state, during execution


The first modification allows you to debug your grammar. It provides
much more information than the normal "yydebug=1" features because it
describes states as item sets, as shown in the grammar description
produced by YACC. The second modification allows your compiler to
produce the sorts of useful error messages requested by the
correspondent, under your control. (In order to produce a message you
only need to know a state number; the YACC-generated parser calls
yyerror while it is in the state at which the error was seen, so if
you modify the call to yyerror to pass in yystate your yyerror function
can store the state for later use during your recovery action).


The modifications involved changing youtpt (the routine which
writes out the grammar description) to add arrays of strings
to your parser source file giving the names of terminals and
nonterminals, and giving the lookahead and goto sets encoded
as shorts to index into those string arrays.


Please note: I am *not* offering to distribute the source code to
these changes, unless someone can suggest an extremely easy way
for this to happen (e.g. someone else distributes it). But I would
be happy to post more information about how the modifications were
made if people are interested.


-------------------------
Alan Heirich Comp. Sci. & Eng., Cognitive Science
C-014 University of California, San Diego 92093


heirich@cs.ucsd.edu aheirich@ucsd.bitnet





Post a followup to this message

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