[net.lang.ada] Hello out there...

duke@drutx.UUCP (07/06/84)

Is there anyone out there who is working with yacc/lex to develop ada
parser, etc?  Oh really?  Well, so am I.  Everything was going fine,
until I tried to handle incorrect programs.  The yacc I was using was
pretty ancient (v 6), and I undertand newer versions are more 
forgiving. I'd appreciate hearing from anyone with experience in this
area. 

duke smith aka drutx!duke,
DR 22-1P10, 2855

colbert@trwspp.UUCP (07/13/84)

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