Path: utzoo!attcan!uunet!cbmvax!snark!eric From: eric@snark.UUCP (Eric S. Raymond) Newsgroups: comp.lang.c Subject: Re: why does yacc use array[-n]? Summary: yypvt is a pointer, not an array Message-ID: Date: 28 Sep 88 23:25:48 GMT References: <1237@imagine.pawl.rpi.edu> <816@goofy.megatest.uucp> <227@olive.athertn.atherton.com> Organization: Wild-Eyed Extremists for Freedom, Inc. Lines: 19 Back-References: <2712@ima.ima.isc.com> In article <227@olive.athertn.atherton.com>, joshua@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@snark.UUCP Post: 22 S. Warren Avenue, Malvern, PA 19355 Phone: (215)-296-5718