From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_05,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site trwspp.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!sdcrdcf!trwrb!trwspp!colbert From: colbert@trwspp.UUCP Newsgroups: net.lang.ada Subject: Re: Hello out there... Message-ID: <503@trwspp.UUCP> Date: Fri, 13-Jul-84 13:54:06 EDT Article-I.D.: trwspp.503 Posted: Fri Jul 13 13:54:06 1984 Date-Received: Wed, 18-Jul-84 02:27:07 EDT References: <572@drutx.UUCP> Organization: T R W, Redondo Beach, CA List-Id: I've been using YACC (bsd4.1) to develop our Ada Pdl parser for the last few years and I have also encountered the problems with YACCS error handling. Although some of the problems stem from the way I modified the YACC driver to give better error messages without having to embed error messages in the grammar. Most of the problems with error handling in YACC result from the state optimization performed by YACC. The problem is that YACC will combine states that in the "most" local context are the same and use what comes next as the sole means of distiquishing where to go. However, sometimes there is information already seen which could have been used to eliminate some possible inputs as illegal. I don't have a good example of this at the moment, but if people want them, I'll search through old versions of our processor grammar & extract a few. I'd like to suggest the following guidelines which helped me get better error recovery: (1) Avoid null productions. While they help reduce the number of states that YACC needs to create & often reduces the size of the stack that you will need, the null production becomes the default action of a state (i.e. a reduction). The problem is that when something illegal is encountered, the reduction is taken, resulting in a new state. This may lead to more reductions until YACC finally reaches a state where the default action is 'error' (look at the state map produced by the '-v' option). By the time this state is reached, information on what was expected when the input was originally encountered is lost. (2) Right recursion can be useful. By using Left recursion YACC needs less stack space than when Right recursion is used, however, Right recursion can delay a decision on what reductions to take until more input is seen (this assumes that you have 2 simular recursive productions). (3) Don't rush to make a production out of a sequence of terminals/non-terminals that are common to 2 or more productions. Often you end up getting rid of the productions latter reversing the decsion when you go to insert error productions. good luck, Ed Colbert