Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: yacc stack overflow Message-ID: <1991Mar14.042103.26095@jpl-devvax.jpl.nasa.gov> Date: 14 Mar 91 04:21:03 GMT References: <1991Mar13.012932.1710@NCoast.ORG> <1991Mar13.234823.12036@NCoast.ORG> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 100 In article <1991Mar13.234823.12036@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes: : As quoted from <1991Mar13.012932.1710@NCoast.ORG> by allbery@NCoast.ORG (Brandon S. Allbery KB8JRR): : +--------------- : | /usr/lib/yaccpar and I produce a modified version that dynamically allocates : | yacc stack space, can I post the diffs without getting AT&T on my case? : +--------------- : : Actually, the answer *may* be "yes" --- AT&T has already permitted generated : y.tab.c's to be distributed. : : In any case, I got two main suggestions: byacc (which is freely hackable) and : bison (which automatically grows the stack). In my case, bison is out: I : had the same problem with some home-grown parsers... which must be linked with : proprietary libraries. And I've explained to a brick wall (read: rms) why : that can't change. : : I *have* byacc, so that's an idea. But many people don't have it, and do have : Perl, and therefore have a problem. Suggestions? Find the line in your Makefile that says "mv y.tab.c ..." and change the mv to perly.fixer. Install the following script as perly.fixer. See if it helps. :-) I note that Sun's yaccpar already does dynamic stack allocation. This script is built to fix 4.3BSD's yaccpar--lemme know if yours differs. I don't like arbitrary limits either... Larry #!/bin/sh : make a subdirectory, cd to it, and run this through sh. echo 'If this kit is complete, "End of kit" will echo at the end' echo Extracting perly.fixer sed >perly.fixer <<'!STUFFY!FUNK!' -e 's/X//' X#!/bin/sh X Xinput=$1 Xoutput=$2 Xtmp=/tmp/f$$ X Xegrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; Xshort[ ]*yys\[ *YYMAXDEPTH *\] *; Xyyps *= *&yys\[ *-1 *\]; Xyypv *= *&yyv\[ *-1 *\]; Xif *\( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp Xset `wc -l $tmp` X Xcase "$1" in X5) echo "Patching perly.c to allow dynamic yacc stack allocation";; X*) mv $input $output; rm -f $tmp; exit;; Xesac X Xcat >$tmp <<'END' X/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ Xint yymaxdepth = YYMAXDEPTH;\ XYYSTYPE *yyv; /* where the values are stored */\ Xshort *yys;\ Xshort *maxyyps; X X/short[ ]*yys\[ *YYMAXDEPTH *\] *;/d X X/yyps *= *&yys\[ *-1 *\];/d X X/yypv *= *&yyv\[ *-1 *\];/c\ X\ if (!yyv) {\ X\ yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\ X\ yys = (short*) malloc(yymaxdepth * sizeof(short));\ X\ maxyyps = &yys[yymaxdepth];\ X\ }\ X\ yyps = &yys[-1];\ X\ yypv = &yyv[-1]; X X X/if *( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *)/c\ X\ if( ++yyps >= maxyyps ) {\ X\ int tv = yypv - yyv;\ X\ int ts = yyps - yys;\ X\ X\ yymaxdepth *= 2;\ X\ yyv = (YYSTYPE*)realloc((char*)yyv,\ X\ yymaxdepth*sizeof(YYSTYPE));\ X\ yys = (short*)realloc((char*)yys,\ X\ yymaxdepth*sizeof(short));\ X\ yyps = yys + ts;\ X\ yypv = yyv + tv;\ X\ maxyyps = &yys[yymaxdepth];\ X\ } X X/yacc stack overflow.*}/d X/yacc stack overflow/,/}/d XEND X Xsed -f $tmp <$input >$output Xrm -rf $tmp $input !STUFFY!FUNK! echo "" echo "End of kit" : I do not append .signature, but someone might mail this. exit