[gnu.utils.bug] Bison suggestion

imdave@att.att.com (01/05/89)

Hi,

If this isn't the place to mail suggestions for bison, could you
let me know where? ..or forward it?  Thanks.

I have a suggestion for bison.  A few years ago I was working as a
consultant for a software vendor, and I wrote a COBOL parser using
yacc.  One undocumented (but supported) feature of yacc is the
YYBACKUP() macro.  This allows one to backup in the context of
a single token production.  An example is easier than an explanation.
I figured out how to use YYBACKUP by looking at the yacc-generated
parser.

With COBOL data definitions, one has normal data definitions
preceeded by a level number, and in addition, special definitions
distinguished by the *value* of the level number: 77 and 88.  My
grammar included:

	stmt: level NAME ...
	    | L77   NAME ...
	    | L88   NAME ...
		;

	level: NUMBER
		{
		if ( $1 == 77 ) YYBACKUP(L77,$1);
		else if ( $1 == 88 ) YYBACKUP(L88,$1);
		else $$ = $1;
		}

As I'm working from memory, I don't remember if the L77 or L88 productions
both had NAME following the level number.  In any event, the syntax
for each of 'level', L77 and L88 were different enough that it made
much sense to split them into individual productions rather than 
attempting to handle them all in the single "level NAME ..." production.

Yacc's parser would handle this by reducing the "level: NUMBER"
production in all cases.  The action for this production allowed
one to backup -- to push the token (L77 or L88) and its value back
onto the stack replacing the NUMBER, and continue as though
"level:NUMBER" had never been reduced.
Yacc would at this point continue stacking tokens until the L77 or
L88 production could be reduced.

Anyway, this was a handy feature in this case.  You might want to
consider adding an equivalent feature to bison.


Dave Bodenstab
AT&T Bell Labs
...att!iwsl8!imdave