Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!husc6!paperboy!soba!jeffc From: jeffc@soba.osf.org (Jeff Carter) Newsgroups: comp.lang.c Subject: Re: PD yacc clone named 'ZOO' ... Message-ID: <919@paperboy.OSF.ORG> Date: 19 Sep 89 14:34:29 GMT References: <3979@ncsuvx.ncsu.edu> Sender: news@OSF.ORG Reply-To: jeffc@soba.osf.org (Jeff Carter) Organization: Open Software Foundation Lines: 70 In article <3979@ncsuvx.ncsu.edu> jnh@ecemwl.UUCP (Joseph N. Hall) writes: >I'm trying to find someone who has compiled and run the yacc clone 'zoo' >which is available via anon ftp from some site at Berkeley (I forget where). > >1) y.tab.c does not contain the #defines for tokens, although they are > included in y.tab.h > >2) the parser dies with a syntax error on the first line of input. > >These are identical to the problems another person reported to me (who also >tried unix and VMS C). Apparently this program is supposed to work, but >the version I have does not. I would greatly appreciate any help one of >you could provide. I was able to fix this, after a couple of days hacking. Ya know, a comment in the code would of been nice, since LR(1) parser generators aren't my forte, otherwise I wouldn't have wanted this one :-). The fix for (1) involves the following: - changer reader() so that define_symbols() is always called, rather than only if dflag is set. - in define_symbols(), change fprintf(temp_file, ... ) to fprintf(output_file, ... ) in the for() loop, and right after the close of the for() loop. Then, add conditional output to temp_file. The diff below takes care of reader.c: ------- reader.c ------- 1144,1149c1144,1145 < if (bp->value > 0 && is_C_identifier(bp->key, bp->length)) < { < fprintf(output_file, "\n#define\t%s\t%d", bp->key, bp->value); < if(dflag) < fprintf(temp_file, "\n#define\t%s\t%d", bp->key, bp->value); < } --- > if (bp->value > 0 && is_C_identifier(bp->key, bp->length)) > fprintf(temp_file, "\n#define\t%s\t%d", bp->key, bp->value); 1152,1154c1148 < fprintf(output_file, "\n#define\tYYMAXTOK\t%d\n", max); < if(dflag)fprintf(temp_file, "\n#define\tYYMAXTOK\t%d\n", max); < else return; --- > fprintf(temp_file, "\n#define\tYYMAXTOK\t%d\n", max); 1305c1299 < define_symbols(); --- > if (dflag) define_symbols(); The fix for (2) was difficult to find, because it actually involved figuring out how the program worked :-). Basically, it builds the parser correctly, then blows it while outputting the tables into the generated C code. In output.c, pack_vector() does not keep track of the highest location used in the table, because a test is done at the wrong place. The following patch moves 2 lines inside a loop, and Voila! the parser I was working on began working. ------- output.c ------- 521a522,523 > if (loc > high) > high = loc; 527,529d528 < if (loc > high) < high = loc; < These patches, are of course, unofficial, but they work for me. Your mileage may vary. jeff carter