why does yacc use array[-n]?
Eric S. Raymond
eric at snark.UUCP
Thu Sep 29 09:25:48 AEST 1988
In article <227 at olive.athertn.atherton.com>, joshua at atherton.com (Sleaze Hack) writes:
> >case 28:
> ># line 160 "gram.y"
> >{ Mpc_insert_with_searchdir(yypvt[-3],yypvt[-1]);
> > yyval = tree(N_INSERT_DECL3);} break;
>
> My question is: why does YACC do this? [incorrect hypothesis follows].
The answer: YACC isn't doing what you thought it was doing. It turns out (as
you'd know if you'd looked at /usr/lib/yaccpar) that yypvt is a *pointer*,
a register pointer in fact, into the parser stack.
In fact, it seems to define the 'frame' of syntax values available for
$[0-9]-substitution in the current action. The negative indexing looks a
little weird but is perfectly legal and even portable.
--
Eric S. Raymond (the mad mastermind of TMN-Netnews)
UUCP: ...!{uunet,att,rutgers}!snark!eric = eric at snark.UUCP
Post: 22 S. Warren Avenue, Malvern, PA 19355 Phone: (215)-296-5718
More information about the Comp.lang.c
mailing list