PD yacc clone named 'ZOO' ...
Jeff Carter
jeffc at soba.osf.org
Wed Sep 20 00:34:29 AEST 1989
In article <3979 at ncsuvx.ncsu.edu> jnh at 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
More information about the Comp.lang.c
mailing list