jnh@ecemwl.ncsu.edu (Joseph N. Hall) (09/19/89)
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). I have done so, but it is not generating correct output. I have compiled zoo using both VMS and Ultrix (pcc) C. Both compilations were successful. Both versions generate similar output. I have found two problems: 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 DO NOT read comp.lang.c any more, so your magnanimous efforts will be wasted if you post here instead of emailing to me ... Thanks, and now you can go back to arguing about const and volatile ... v v sssss|| joseph hall || 4116 Brewster Drive v v s s || jnh@ecemwl.ncsu.edu (Internet) || Raleigh, NC 27606 v sss || SP Software/CAD Tool Developer, Mac Hacker and Keyboardist -----------|| Disclaimer: NCSU may not share my views, but is welcome to.
jeffc@soba.osf.org (Jeff Carter) (09/19/89)
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