? lib/hash.h ? lib/hash.c ? src/macrotab.h ? src/macrotab.c Index: ChangeLog =================================================================== RCS file: /cvsroot/bison/bison/ChangeLog,v retrieving revision 1.173 diff -u -r1.173 ChangeLog --- ChangeLog 2001/08/15 08:44:16 1.173 +++ ChangeLog 2001/08/21 18:14:04 @@ -1,8 +1,114 @@ +2001-08-20 Robert Anisko + + * src/output.c (prepare): Add prefixed names. + (output_parser): Output semantic actions. + (output_parser): Fix bug on '%%line' directives. + +2001-08-19 Robert Anisko + + * src/output.c (output_rule_data): Do not output tables to + the table obstack. + + * src/reader.c (reader): Remove calls to 'output_headers' and + 'output_trailers'. Remove some C output. + (readgram): Disable a piece of code that was writing a default + definition for 'YYSTYPE'. + (reader_output_yylsp): Remove. + (packsymbols): Output token defintions to a macro. + (copy_definition): Disable C output. + + * src/output.c (output_headers): Remove. The C code printed by this + function should now be in the skeletons. + (output_trailers): Remove. + (output): Disable call to 'reader_output_yylsp'. + +2001-08-18 Robert Anisko + + * src/output.c: Remove some C dedicated output. + +2001-08-18 Robert Anisko + + * src/output.c (output_defines): Remove. + +2001-08-18 Robert Anisko + + * src/output.c: Improve the use of macro and output obstacks. + +2001-08-18 Robert Anisko + + * src/output.c (output_token_translations): Associate 'translate' table + with a macro. No output to the table obstack. + (output_gram): Same for 'rhs' and 'prhs'. + (output_stos): Same for 'stos'. + (output_rule_data): Same for 'r1' and 'r2'. + (token_actions): Same for 'defact'. + (goto_actions): Same for 'defgoto'. + (output_base): Same for 'pact' and 'pgoto'. + (output_table): Same for 'table'. + (output_check): Same for 'check'. + +2001-08-18 Robert Anisko + + * src/output.c (output_table_data): New function. + (output_short_table): Remove. + (output_short_or_char_table): Remove. + +2001-08-17 Robert Anisko + + * src/main.c (main): Initialize the macro table. + +2001-08-17 Robert Anisko + + * src/output.c (output_parser): Use the macro table. + * src/macrotab.c: New file. + * src/macrotab.h: New file. + +2001-08-17 Robert Anisko + + * lib/xalloc.h (CALLOC, MALLOC, REALLOC): New macros. + +2001-08-17 Robert Anisko + + * lib/hash.c: New file. + * lib/hash.h: New file. + +2001-08-16 Robert Anisko + + * src/reader.c (parse_macro_decl): Read macro identifiers using + copy_identifier rather than lex. + +2001-08-16 Robert Anisko + + * src/reader.c (copy_identifier): New. + +2001-08-16 Robert Anisko + + * src/reader.c (read_declarations): Add case for macro definition. + * src/lex.c (percent_table): Add tok_define. + * src/lex.h: Add tok_define. + +2001-08-16 Robert Anisko + + * src/reader.c (parse_macro_decl): New function used to parse macro + declarations. + (copy_string2): Put the body of copy_string into this new function. + Add a parameter to let the caller choose whether he wants to copy the + string delimiters or not. + (copy_string): Be a simple call to copy_string2 with the last argument + bound to true. + +2001-08-15 Robert Anisko + + * src/output.c (output_parser): Replace most of the skeleton copy code + with something new. Skeletons are now processed character by character + rather than line by line, and Bison looks for '%%' macros. This is the + first step in making Bison's output process (a lot) more flexible. + 2001-08-15 Akim Demaille Version 1.28c. -2001-08-15 Marc Autret +2001-08-15 Marc Autret * src/reader.c (readgram): Indent output macro YYSTYPE. (packsymbols): Likewise. Index: lib/Makefile.am =================================================================== RCS file: /cvsroot/bison/bison/lib/Makefile.am,v retrieving revision 1.8 diff -u -r1.8 Makefile.am --- lib/Makefile.am 2001/08/13 14:54:50 1.8 +++ lib/Makefile.am 2001/08/21 18:14:17 @@ -4,7 +4,7 @@ noinst_LIBRARIES = libbison.a -INCLUDES = -I.. -I$(srcdir) -I../intl +INCLUDES = -I.. -I$(srcdir) -I../intl -I$(top_srcdir)/src # Heck, we are still using an old version of Automake which does not # understand LIBOBJ additions using $objext... @@ -14,6 +14,7 @@ libbison_a_SOURCES = \ error.c error.h \ getopt.h getopt.c getopt1.c \ + hash.h hash.c \ obstack.h obstack.c \ quote.h quote.c quotearg.h quotearg.c \ xalloc.h xmalloc.c xstrdup.c Index: lib/Makefile.in =================================================================== RCS file: /cvsroot/bison/bison/lib/Makefile.in,v retrieving revision 1.5 diff -u -r1.5 Makefile.in --- lib/Makefile.in 2001/08/13 14:54:50 1.5 +++ lib/Makefile.in 2001/08/21 18:14:17 @@ -98,14 +98,14 @@ noinst_LIBRARIES = libbison.a -INCLUDES = -I.. -I$(srcdir) -I../intl +INCLUDES = -I.. -I$(srcdir) -I../intl -I$(top_srcdir)/src # Heck, we are still using an old version of Automake which does not # understand LIBOBJ additions using $objext... EXTRA_DIST = malloc.c realloc.c -libbison_a_SOURCES = error.c error.h getopt.h getopt.c getopt1.c obstack.h obstack.c quote.h quote.c quotearg.h quotearg.c xalloc.h xmalloc.c xstrdup.c +libbison_a_SOURCES = error.c error.h getopt.h getopt.c getopt1.c hash.h hash.c obstack.h obstack.c quote.h quote.c quotearg.h quotearg.c xalloc.h xmalloc.c xstrdup.c libbison_a_LIBADD = @LIBOBJS@ @@ -121,8 +121,8 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ ANSI2KNR = @ANSI2KNR@ -libbison_a_OBJECTS = error$U.o getopt$U.o getopt1$U.o obstack$U.o \ -quote$U.o quotearg$U.o xmalloc$U.o xstrdup$U.o +libbison_a_OBJECTS = error$U.o getopt$U.o getopt1$U.o hash$U.o \ +obstack$U.o quote$U.o quotearg$U.o xmalloc$U.o xstrdup$U.o AR = ar CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -136,10 +136,10 @@ TAR = tar GZIP_ENV = --best -DEP_FILES = .deps/error.P .deps/getopt.P .deps/getopt1.P .deps/memchr.P \ -.deps/obstack.P .deps/quote.P .deps/quotearg.P .deps/stpcpy.P \ -.deps/strndup.P .deps/strnlen.P .deps/strspn.P .deps/xmalloc.P \ -.deps/xstrdup.P +DEP_FILES = .deps/error.P .deps/getopt.P .deps/getopt1.P .deps/hash.P \ +.deps/memchr.P .deps/obstack.P .deps/quote.P .deps/quotearg.P \ +.deps/stpcpy.P .deps/strndup.P .deps/strnlen.P .deps/strspn.P \ +.deps/xmalloc.P .deps/xstrdup.P SOURCES = $(libbison_a_SOURCES) OBJECTS = $(libbison_a_OBJECTS) @@ -213,6 +213,8 @@ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/getopt.c; then echo $(srcdir)/getopt.c; else echo getopt.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > getopt_.c getopt1_.c: getopt1.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/getopt1.c; then echo $(srcdir)/getopt1.c; else echo getopt1.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > getopt1_.c +hash_.c: hash.c $(ANSI2KNR) + $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/hash.c; then echo $(srcdir)/hash.c; else echo hash.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > hash_.c memchr_.c: memchr.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/memchr.c; then echo $(srcdir)/memchr.c; else echo memchr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > memchr_.c obstack_.c: obstack.c $(ANSI2KNR) @@ -233,9 +235,9 @@ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xmalloc.c; then echo $(srcdir)/xmalloc.c; else echo xmalloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xmalloc_.c xstrdup_.c: xstrdup.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xstrdup.c; then echo $(srcdir)/xstrdup.c; else echo xstrdup.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xstrdup_.c -alloca_.o error_.o getopt_.o getopt1_.o memchr_.o obstack_.o quote_.o \ -quotearg_.o stpcpy_.o strndup_.o strnlen_.o strspn_.o xmalloc_.o \ -xstrdup_.o : $(ANSI2KNR) +alloca_.o error_.o getopt_.o getopt1_.o hash_.o memchr_.o obstack_.o \ +quote_.o quotearg_.o stpcpy_.o strndup_.o strnlen_.o strspn_.o \ +xmalloc_.o xstrdup_.o : $(ANSI2KNR) tags: TAGS Index: lib/xalloc.h =================================================================== RCS file: /cvsroot/bison/bison/lib/xalloc.h,v retrieving revision 1.2 diff -u -r1.2 xalloc.h --- lib/xalloc.h 2001/02/02 14:56:44 1.2 +++ lib/xalloc.h 2001/08/21 18:14:18 @@ -83,5 +83,9 @@ /* Return a malloc'ed copy of SRC. */ # define CLONE(Src) CCLONE (Src, 1) +/* Wrappers for standard functions. */ +#define CALLOC(t, n) ((t *) calloc (sizeof (t), (n))) +#define MALLOC(t, n) ((t *) xmalloc (sizeof (t) * (n))) +#define REALLOC(o, t, n) ((t *) xrealloc ((o), sizeof (t) * (n))) #endif /* !XALLOC_H_ */ Index: src/Makefile.am =================================================================== RCS file: /cvsroot/bison/bison/src/Makefile.am,v retrieving revision 1.25 diff -u -r1.25 Makefile.am --- src/Makefile.am 2001/08/06 09:22:33 1.25 +++ src/Makefile.am 2001/08/21 18:14:18 @@ -12,7 +12,7 @@ bison_SOURCES = LR0.c closure.c complain.c conflicts.c \ derives.c \ - files.c getargs.c gram.c lalr.c lex.c main.c nullable.c \ + files.c getargs.c gram.c lalr.c lex.c main.c macrotab.c nullable.c \ output.c \ print.c reader.c reduce.c symtab.c warshall.c vcg.c print_graph.c @@ -20,7 +20,7 @@ noinst_HEADERS = LR0.h closure.h complain.h conflicts.h \ derives.h \ - files.h getargs.h gram.h lalr.h lex.h nullable.h \ + files.h getargs.h gram.h lalr.h lex.h macrotab.h nullable.h \ output.h state.h \ print.h reader.h reduce.h symtab.h warshall.h system.h types.h \ vcg.h vcg_defaults.h print_graph.h Index: src/Makefile.in =================================================================== RCS file: /cvsroot/bison/bison/src/Makefile.in,v retrieving revision 1.4 diff -u -r1.4 Makefile.in --- src/Makefile.in 2001/08/06 09:22:33 1.4 +++ src/Makefile.in 2001/08/21 18:14:18 @@ -103,12 +103,12 @@ bin_PROGRAMS = bison -bison_SOURCES = LR0.c closure.c complain.c conflicts.c derives.c files.c getargs.c gram.c lalr.c lex.c main.c nullable.c output.c print.c reader.c reduce.c symtab.c warshall.c vcg.c print_graph.c +bison_SOURCES = LR0.c closure.c complain.c conflicts.c derives.c files.c getargs.c gram.c lalr.c lex.c main.c macrotab.c nullable.c output.c print.c reader.c reduce.c symtab.c warshall.c vcg.c print_graph.c EXTRA_bison_SOURCES = vmsgetargs.c -noinst_HEADERS = LR0.h closure.h complain.h conflicts.h derives.h files.h getargs.h gram.h lalr.h lex.h nullable.h output.h state.h print.h reader.h reduce.h symtab.h warshall.h system.h types.h vcg.h vcg_defaults.h print_graph.h +noinst_HEADERS = LR0.h closure.h complain.h conflicts.h derives.h files.h getargs.h gram.h lalr.h lex.h macrotab.h nullable.h output.h state.h print.h reader.h reduce.h symtab.h warshall.h system.h types.h vcg.h vcg_defaults.h print_graph.h pkgdata_DATA = bison.simple bison.hairy @@ -125,8 +125,8 @@ ANSI2KNR = ../lib/ansi2knr bison_OBJECTS = LR0$U.o closure$U.o complain$U.o conflicts$U.o \ derives$U.o files$U.o getargs$U.o gram$U.o lalr$U.o lex$U.o main$U.o \ -nullable$U.o output$U.o print$U.o reader$U.o reduce$U.o symtab$U.o \ -warshall$U.o vcg$U.o print_graph$U.o +macrotab$U.o nullable$U.o output$U.o print$U.o reader$U.o reduce$U.o \ +symtab$U.o warshall$U.o vcg$U.o print_graph$U.o bison_LDADD = $(LDADD) bison_DEPENDENCIES = ../lib/libbison.a bison_LDFLAGS = @@ -147,10 +147,10 @@ GZIP_ENV = --best DEP_FILES = .deps/LR0.P .deps/closure.P .deps/complain.P \ .deps/conflicts.P .deps/derives.P .deps/files.P .deps/getargs.P \ -.deps/gram.P .deps/lalr.P .deps/lex.P .deps/main.P .deps/nullable.P \ -.deps/output.P .deps/print.P .deps/print_graph.P .deps/reader.P \ -.deps/reduce.P .deps/symtab.P .deps/vcg.P .deps/vmsgetargs.P \ -.deps/warshall.P +.deps/gram.P .deps/lalr.P .deps/lex.P .deps/macrotab.P .deps/main.P \ +.deps/nullable.P .deps/output.P .deps/print.P .deps/print_graph.P \ +.deps/reader.P .deps/reduce.P .deps/symtab.P .deps/vcg.P \ +.deps/vmsgetargs.P .deps/warshall.P SOURCES = $(bison_SOURCES) $(EXTRA_bison_SOURCES) OBJECTS = $(bison_OBJECTS) @@ -226,8 +226,6 @@ $(LINK) $(bison_LDFLAGS) $(bison_OBJECTS) $(bison_LDADD) $(LIBS) LR0_.c: LR0.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/LR0.c; then echo $(srcdir)/LR0.c; else echo LR0.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > LR0_.c -alloca_.c: alloca.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/alloca.c; then echo $(srcdir)/alloca.c; else echo alloca.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > alloca_.c closure_.c: closure.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/closure.c; then echo $(srcdir)/closure.c; else echo closure.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > closure_.c complain_.c: complain.c $(ANSI2KNR) @@ -246,10 +244,10 @@ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/lalr.c; then echo $(srcdir)/lalr.c; else echo lalr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > lalr_.c lex_.c: lex.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/lex.c; then echo $(srcdir)/lex.c; else echo lex.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > lex_.c +macrotab_.c: macrotab.c $(ANSI2KNR) + $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/macrotab.c; then echo $(srcdir)/macrotab.c; else echo macrotab.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > macrotab_.c main_.c: main.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/main.c; then echo $(srcdir)/main.c; else echo main.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > main_.c -memchr_.c: memchr.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/memchr.c; then echo $(srcdir)/memchr.c; else echo memchr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > memchr_.c nullable_.c: nullable.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/nullable.c; then echo $(srcdir)/nullable.c; else echo nullable.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > nullable_.c output_.c: output.c $(ANSI2KNR) @@ -262,14 +260,6 @@ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/reader.c; then echo $(srcdir)/reader.c; else echo reader.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > reader_.c reduce_.c: reduce.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/reduce.c; then echo $(srcdir)/reduce.c; else echo reduce.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > reduce_.c -stpcpy_.c: stpcpy.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/stpcpy.c; then echo $(srcdir)/stpcpy.c; else echo stpcpy.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > stpcpy_.c -strndup_.c: strndup.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strndup.c; then echo $(srcdir)/strndup.c; else echo strndup.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strndup_.c -strnlen_.c: strnlen.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strnlen.c; then echo $(srcdir)/strnlen.c; else echo strnlen.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strnlen_.c -strspn_.c: strspn.c $(ANSI2KNR) - $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strspn.c; then echo $(srcdir)/strspn.c; else echo strspn.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strspn_.c symtab_.c: symtab.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/symtab.c; then echo $(srcdir)/symtab.c; else echo symtab.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > symtab_.c vcg_.c: vcg.c $(ANSI2KNR) @@ -278,10 +268,9 @@ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/vmsgetargs.c; then echo $(srcdir)/vmsgetargs.c; else echo vmsgetargs.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > vmsgetargs_.c warshall_.c: warshall.c $(ANSI2KNR) $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/warshall.c; then echo $(srcdir)/warshall.c; else echo warshall.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > warshall_.c -LR0_.o alloca_.o closure_.o complain_.o conflicts_.o derives_.o \ -files_.o getargs_.o gram_.o lalr_.o lex_.o main_.o memchr_.o \ -nullable_.o output_.o print_.o print_graph_.o reader_.o reduce_.o \ -stpcpy_.o strndup_.o strnlen_.o strspn_.o symtab_.o vcg_.o \ +LR0_.o closure_.o complain_.o conflicts_.o derives_.o files_.o \ +getargs_.o gram_.o lalr_.o lex_.o macrotab_.o main_.o nullable_.o \ +output_.o print_.o print_graph_.o reader_.o reduce_.o symtab_.o vcg_.o \ vmsgetargs_.o warshall_.o : $(ANSI2KNR) install-pkgdataDATA: $(pkgdata_DATA) Index: src/bison.simple =================================================================== RCS file: /cvsroot/bison/bison/src/bison.simple,v retrieving revision 1.53 diff -u -r1.53 bison.simple --- src/bison.simple 2001/08/13 21:37:22 1.53 +++ src/bison.simple 2001/08/21 18:14:18 @@ -1,5 +1,8 @@ -/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ -#line +/* -*- C -*- */ + +/* A Bison parser, made from %%filename + by GNU bison %%version. */ + /* Skeleton output parser for bison, Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc. @@ -28,6 +31,14 @@ It was written by Richard Stallman by simplifying the hairy parser used when %semantic_parser is specified. */ +#include + +#ifndef __cplusplus +# ifndef __STDC__ +# define const +# endif +#endif + #ifndef YYSTACK_USE_ALLOCA # ifdef alloca # define YYSTACK_USE_ALLOCA 1 @@ -54,7 +65,7 @@ /* I don't know what this was needed for, but it pollutes the namespace. So I turned it off. rms, 2 May 1997. */ /* #include */ - #pragma alloca +# pragma alloca # define YYSTACK_USE_ALLOCA 1 # else /* not MSDOS, or __TURBOC__, or _AIX */ # if 0 @@ -78,31 +89,162 @@ # define YYSTACK_ALLOC malloc #endif +#define YYBISON 1 /* Identify Bison output. */ +#define YYPURE %%pure /* Identify pure parsers. */ + +#ifndef YYDEBUG +# define YYDEBUG %%debug +#endif + +#ifndef YYSTYPE +# define YYSTYPE %%stype +#endif + +#ifndef YYLTYPE +typedef struct yyltype +{ + int first_line; + int first_column; + int last_line; + int last_column; +} yyltype; +# define YYLTYPE %%ltype +#endif + +#ifndef YYERROR_VERBOSE +# define YYERROR_VERBOSE %%verbose +#endif + +/* Tokens. */ +%%tokendef + +#define YYFINAL %%final +#define YYFLAG %%flag +#define YYNTBASE %%ntbase +#define YYLAST %%last + +#define YYNTOKENS %%ntokens +#define YYNNTS %%nnts +#define YYNRULES %%nrules +#define YYNSTATES %%nstates +#define YYMAXUTOK %%maxtok + +/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ +#define YYTRANSLATE(x) ((unsigned)(x) <= %%maxtok ? yytranslate[x] : %%nsym) + +/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ +static const char yytranslate[] = +{ + %%translate +}; + +#if YYDEBUG +static const short yyprhs[] = +{ + %%prhs +}; + +static const short yyrhs[] = +{ + %%rhs +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const short yyrline[] = +{ + %%rline +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE +/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */ +static const char* const yytname[] = +{ + %%tname +}; +#endif + +/* YYTOKNUM[YYN] -- Index in YYTNAME corresponding to YYLEX. */ +static const short yytoknum[] = +{ + %%toknum +}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const short yyr1[] = +{ + %%r1 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const short yyr2[] = +{ + %%r2 +}; + +/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE + doesn't specify something else to do. Zero means the default is an + error. */ +static const short yydefact[] = +{ + %%defact +}; + +static const short yydefgoto[] = +{ + %%defgoto +}; + +static const short yypact[] = +{ + %%pact +}; + +static const short yypgoto[] = +{ + %%pgoto +}; + +static const short yytable[] = +{ + %%table +}; + +static const short yycheck[] = +{ + %%check +}; + #define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) +#define yyclearin (%%yychar = YYEMPTY) #define YYEMPTY -2 #define YYEOF 0 + #define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab +#define YYABORT goto yyabortlab #define YYERROR goto yyerrlab1 + /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ + #define YYFAIL goto yyerrlab + #define YYRECOVERING() (!!yyerrstatus) + #define YYBACKUP(Token, Value) \ do \ - if (yychar == YYEMPTY && yylen == 1) \ + if (%%yychar == YYEMPTY && yylen == 1) \ { \ - yychar = (Token); \ - yylval = (Value); \ - yychar1 = YYTRANSLATE (yychar); \ + %%yychar = (Token); \ + %%yylval = (Value); \ + yychar1 = YYTRANSLATE (%%yychar); \ YYPOPSTACK; \ goto yybackup; \ } \ else \ { \ - yyerror ("syntax error: cannot back up"); \ + %%yyerror ("syntax error: cannot back up"); \ YYERROR; \ } \ while (0) @@ -110,7 +252,6 @@ #define YYTERROR 1 #define YYERRCODE 256 - /* YYLLOC_DEFAULT -- Compute the default location (before the actions are run). @@ -124,47 +265,45 @@ Current.last_column = Rhs[N].last_column; #endif - /* YYLEX -- calling `yylex' with the right arguments. */ #if YYPURE # if YYLSP_NEEDED # ifdef YYLEX_PARAM -# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +# define YYLEX %%yylex (&%%yylval, &yylloc, YYLEX_PARAM) # else -# define YYLEX yylex (&yylval, &yylloc) +# define YYLEX %%yylex (&%%yylval, &yylloc) # endif # else /* !YYLSP_NEEDED */ # ifdef YYLEX_PARAM -# define YYLEX yylex (&yylval, YYLEX_PARAM) +# define YYLEX %%yylex (&%%yylval, YYLEX_PARAM) # else -# define YYLEX yylex (&yylval) +# define YYLEX %%yylex (&%%yylval) # endif # endif /* !YYLSP_NEEDED */ #else /* !YYPURE */ -# define YYLEX yylex () +# define YYLEX %%yylex () #endif /* !YYPURE */ - /* Enable debugging if requested. */ #if YYDEBUG # define YYDPRINTF(Args) \ do { \ - if (yydebug) \ + if (%%yydebug) \ fprintf Args; \ } while (0) /* Nonzero means print parse trace. [The following comment makes no sense to me. Could someone clarify it? --akim] Since this is uninitialized, it does not stop multiple parsers from coexisting. */ -int yydebug; +int %%yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +# define YYINITDEPTH %%initdepth #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -174,9 +313,11 @@ #endif #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +# define YYMAXDEPTH %%maxdepth #endif + + /* Define __yy_memcpy. Note that the size argument should be passed with type unsigned int, because that is what the non-GCC definitions require. With GCC, __builtin_memcpy takes an arg @@ -205,11 +346,12 @@ while (i-- > 0) *t++ = *f++; } - #endif + -#line +#line %%line "%%filename" + /* The user can define YYPARSE_PARAM as the name of an argument to be passed into yyparse. The argument should have type void *. It should actually point to an object. @@ -232,9 +374,9 @@ /* Prevent warning if -Wstrict-prototypes. */ #ifdef __GNUC__ # ifdef YYPARSE_PARAM -int yyparse (void *); +int %%yyparse (void *); # else -int yyparse (void); +int %%yyparse (void); # endif #endif @@ -243,13 +385,13 @@ #define _YY_DECL_VARIABLES \ /* The lookahead symbol. */ \ -int yychar; \ +int %%yychar; \ \ /* The semantic value of the lookahead symbol. */ \ -YYSTYPE yylval; \ +YYSTYPE %%yylval; \ \ /* Number of parse errors so far. */ \ -int yynerrs; +int %%yynerrs; #if YYLSP_NEEDED # define YY_DECL_VARIABLES \ @@ -262,7 +404,6 @@ _YY_DECL_VARIABLES #endif - /* If nonreentrant, generate the variables here. */ #if !YYPURE @@ -270,7 +411,7 @@ #endif /* !YYPURE */ int -yyparse (YYPARSE_PARAM_ARG) +%%yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL { /* If reentrant, generate the variables here. */ @@ -319,7 +460,6 @@ int yystacksize = YYINITDEPTH; int yyfree_stacks = 0; - /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -335,8 +475,8 @@ yystate = 0; yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ + %%yynerrs = 0; + %%yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack @@ -349,7 +489,6 @@ yylsp = yyls; #endif - /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ @@ -399,7 +538,7 @@ /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) { - yyerror ("parser stack overflow"); + %%yyerror ("parser stack overflow"); if (yyfree_stacks) { free (yyss); @@ -413,7 +552,7 @@ yystacksize *= 2; if (yystacksize > YYMAXDEPTH) yystacksize = YYMAXDEPTH; -# ifndef YYSTACK_USE_ALLOCA +# if !YYSTACK_USE_ALLOCA yyfree_stacks = 1; # endif yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); @@ -445,7 +584,6 @@ goto yybackup; - /*-----------. | yybackup. | `-----------*/ @@ -466,35 +604,35 @@ /* yychar is either YYEMPTY or YYEOF or a valid token in external form. */ - if (yychar == YYEMPTY) + if (%%yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + %%yychar = YYLEX; } /* Convert token to internal form (in yychar1) for indexing tables with */ - if (yychar <= 0) /* This means end of input. */ + if (%%yychar <= 0) /* This means end of input. */ { yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ + %%yychar = YYEOF; /* Don't call YYLEX any more */ YYDPRINTF ((stderr, "Now at end of input.\n")); } else { - yychar1 = YYTRANSLATE (yychar); + yychar1 = YYTRANSLATE (%%yychar); #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ - if (yydebug) + if (%%yydebug) { - fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + fprintf (stderr, "Next token is %d (%s", %%yychar, yytname[yychar1]); /* Give the individual parser a way to print the precise meaning of a token, for further debugging info. */ # ifdef YYPRINT - YYPRINT (stderr, yychar, yylval); + YYPRINT (stderr, %%yychar, %%yylval); # endif fprintf (stderr, ")\n"); } @@ -528,13 +666,13 @@ YYACCEPT; /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1])); + YYDPRINTF ((stderr, "Shifting token %d (%s), ", %%yychar, yytname[yychar1])); /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; + if (%%yychar != YYEOF) + %%yychar = YYEMPTY; - *++yyvsp = yylval; + *++yyvsp = %%yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif @@ -585,7 +723,7 @@ #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ - if (yydebug) + if (%%yydebug) { int i; @@ -598,8 +736,11 @@ fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); } #endif -%% actions /* The action file replaces this line. */ -#line + switch (yyn) + { + %%action /* The action file replaces this line. */ + } +#line %%line "%%filename" yyvsp -= yylen; yyssp -= yylen; @@ -608,7 +749,7 @@ #endif #if YYDEBUG - if (yydebug) + if (%%yydebug) { short *ssp1 = yyss - 1; fprintf (stderr, "state stack now"); @@ -645,9 +786,9 @@ /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { - ++yynerrs; + ++%%yynerrs; -#ifdef YYERROR_VERBOSE +#if YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) @@ -663,36 +804,36 @@ if (yycheck[x + yyn] == x) size += strlen (yytname[x]) + 15, count++; size += strlen ("parse error, unexpected `") + 1; - size += strlen (yytname[YYTRANSLATE (yychar)]); + size += strlen (yytname[YYTRANSLATE (%%yychar)]); msg = (char *) malloc (size); if (msg != 0) { strcpy (msg, "parse error, unexpected `"); - strcat (msg, yytname[YYTRANSLATE (yychar)]); + strcat (msg, yytname[YYTRANSLATE (%%yychar)]); strcat (msg, "'"); if (count < 5) { count = 0; for (x = (yyn < 0 ? -yyn : 0); - x < (int) (sizeof (yytname) / sizeof (char *)); x++) + x < (int) (sizeof (yytname) / sizeof (char *)); x++) if (yycheck[x + yyn] == x) { - strcat (msg, count == 0 ? ", expecting `" : " or `"); - strcat (msg, yytname[x]); + strcat (msg, count == 0 ? ", expecting `" : " or `"); + strcat (msg, yytname[x]); strcat (msg, "'"); count++; } } - yyerror (msg); + %%yyerror (msg); free (msg); } - else - yyerror ("parse error; also virtual memory exceeded"); - } + else + %%yyerror ("parse error; also virtual memory exceeded"); + } else #endif /* YYERROR_VERBOSE */ - yyerror ("parse error"); + %%yyerror ("parse error"); } goto yyerrlab1; @@ -707,11 +848,11 @@ error, discard it. */ /* return failure if at end of input */ - if (yychar == YYEOF) + if (%%yychar == YYEOF) YYABORT; YYDPRINTF ((stderr, "Discarding token %d (%s).\n", - yychar, yytname[yychar1])); - yychar = YYEMPTY; + %%yychar, yytname[yychar1])); + %%yychar = YYEMPTY; } /* Else will try to reuse lookahead token after shifting the error @@ -752,7 +893,7 @@ #endif #if YYDEBUG - if (yydebug) + if (%%yydebug) { short *ssp1 = yyss - 1; fprintf (stderr, "Error: state stack now"); @@ -790,7 +931,7 @@ YYDPRINTF ((stderr, "Shifting error token, ")); - *++yyvsp = yylval; + *++yyvsp = %%yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif Index: src/lex.c =================================================================== RCS file: /cvsroot/bison/bison/src/lex.c,v retrieving revision 1.33 diff -u -r1.33 lex.c --- src/lex.c 2001/08/14 11:28:48 1.33 +++ src/lex.c 2001/08/21 18:14:19 @@ -552,8 +552,9 @@ { "file_prefix", &spec_file_prefix, tok_setopt }, /* -b */ { "name_prefix", &spec_name_prefix, tok_setopt }, /* -p */ #endif - { "header_extension", NULL, tok_hdrext}, - { "source_extension", NULL, tok_srcext}, + { "header_extension", NULL, tok_hdrext }, + { "source_extension", NULL, tok_srcext }, + { "define", NULL, tok_define }, { "verbose", &verbose_flag, tok_noop }, /* -v */ { "debug", &debug_flag, tok_noop }, /* -t */ { "semantic_parser", &semantic_parser, tok_noop }, Index: src/lex.h =================================================================== RCS file: /cvsroot/bison/bison/src/lex.h,v retrieving revision 1.13 diff -u -r1.13 lex.h --- src/lex.h 2001/08/06 08:51:41 1.13 +++ src/lex.h 2001/08/21 18:14:19 @@ -49,6 +49,7 @@ tok_thong, tok_hdrext, tok_srcext, + tok_define, tok_noop, tok_setopt, tok_illegal, Index: src/main.c =================================================================== RCS file: /cvsroot/bison/bison/src/main.c,v retrieving revision 1.30 diff -u -r1.30 main.c --- src/main.c 2001/08/07 07:58:43 1.30 +++ src/main.c 2001/08/21 18:14:19 @@ -51,6 +51,7 @@ lineno = 0; getargs (argc, argv); + macro_init (); open_files (); /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE Index: src/output.c =================================================================== RCS file: /cvsroot/bison/bison/src/output.c,v retrieving revision 1.39 diff -u -r1.39 output.c --- src/output.c 2001/08/13 14:51:15 1.39 +++ src/output.c 2001/08/21 18:14:19 @@ -103,11 +103,10 @@ #include "lalr.h" #include "reader.h" #include "conflicts.h" +#include "macrotab.h" extern void berror PARAMS((const char *)); - - static int nvectors; static int nentries; static short **froms; @@ -124,211 +123,54 @@ static int lowzero; static int high; +struct obstack macro_obstack; +struct obstack output_obstack; +/* FIXME. */ static inline void -output_short_or_char_table (struct obstack *oout, - const char *comment, - const char *type, - const char *table_name, - short *short_table, - short first_value, - short begin, short end) -{ - int i, j; - - if (comment) - obstack_fgrow1 (oout, "/* %s. */\n", comment); - - obstack_fgrow3 (oout, "static const %s %s[] =\n{\n %6d", - type, table_name, first_value); - - j = 1; - for (i = begin; i < end; i++) +output_table_data (struct obstack* oout, + short* table, + short first, + short begin, + short end) +{ + int i; + int j = 1; + + obstack_fgrow1 (oout, "%6d", first); + for (i = begin; i < end; ++i) { obstack_1grow (oout, ','); - if (j >= 10) { obstack_sgrow (oout, "\n "); j = 1; } else - { - j++; - } - - obstack_fgrow1 (oout, "%6d", short_table[i]); + ++j; + obstack_fgrow1 (oout, "%6d", table[i]); } - - obstack_sgrow (oout, "\n};\n"); -} - - -static inline void -output_short_table (struct obstack *oout, - const char *comment, - const char *table_name, - short *short_table, - short first_value, - short begin, short end) -{ - output_short_or_char_table (oout, comment, "short", table_name, short_table, - first_value, begin, end); + obstack_1grow (oout, 0); } -/*--------------------------------------------------------------. -| output_headers -- Output constant strings to the beginning of | -| certain files. | -`--------------------------------------------------------------*/ - -/* Don't put the `%s' insides quotes, since it quotearg puts them. */ - -#define GUARDSTR \ -"\n\ -#include %s\n\ -extern int yyerror;\n\ -extern int yycost;\n\ -extern char * yymsg;\n\ -extern YYSTYPE yyval;\n\ -\n\ -yyguard(n, yyvsp, yylsp)\n\ -register int n;\n\ -register YYSTYPE *yyvsp;\n\ -register YYLTYPE *yylsp;\n\ -{\n\ - yyerror = 0;\n\ - yycost = 0;\n\ - yymsg = 0;\n\ - switch (n)\n\ - {" - -#define ACTSTR \ -"\n\ -#include %s\n\ -extern YYSTYPE yyval;\n\ -extern int yychar;\n\ -\n\ -yyaction(n, yyvsp, yylsp)\n\ -register int n;\n\ -register YYSTYPE *yyvsp;\n\ -register YYLTYPE *yylsp;\n\ -{\n\ - switch (n)\n\ - {" - -#define ACTSTR_SIMPLE "\n switch (yyn) {\n" - -void -output_headers (void) -{ - char *attrsfile_quoted = 0; - - if (semantic_parser) - { - /* FIXME: This is *buggy*. ATTRSFILE is not computed yet, since - we are waiting for the full input file to have been read to - be sure of the output file name. So basically, here, a SEGV - is guaranteed. OTOH, currently semantic parsers are not - supported. */ - attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile); - obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted); - } - - if (no_parser_flag) - return; - - if (semantic_parser) - obstack_fgrow1 (&action_obstack, ACTSTR, attrsfile_quoted); - else - obstack_sgrow (&action_obstack, ACTSTR_SIMPLE); - - /* Rename certain symbols if -p was specified. */ - if (spec_name_prefix) - { - obstack_fgrow1 (&table_obstack, - "#define yyparse %sparse\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yylex %slex\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yyerror %serror\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yylval %slval\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yychar %schar\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yydebug %sdebug\n", spec_name_prefix); - obstack_fgrow1 (&table_obstack, - "#define yynerrs %snerrs\n", spec_name_prefix); - } -} - - -/*-------------------------------------------------------. -| Output constant strings to the ends of certain files. | -`-------------------------------------------------------*/ - -void -output_trailers (void) -{ - if (semantic_parser) - obstack_sgrow (&guard_obstack, "\n }\n}\n"); - - obstack_1grow (&action_obstack, '\n'); - - if (no_parser_flag) - return; - - if (semantic_parser) - obstack_sgrow (&action_obstack, " }\n"); - - obstack_sgrow (&action_obstack, "}\n"); -} - - - static void output_token_translations (void) { - obstack_sgrow (&table_obstack, "\ -\n\ -/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n"); - - if (translations) - { - obstack_fgrow2 (&table_obstack, - "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\ -\n\ -\n", - max_user_token_number, nsyms); - - output_short_or_char_table (&table_obstack, - "YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX", - ntokens < 127 ? "char" : "short", - "yytranslate", token_translations, - 0, 1, max_user_token_number + 1); - } - else - { - obstack_sgrow (&table_obstack, - "\n#define YYTRANSLATE(x) (x)\n"); - } + output_table_data (&output_obstack, token_translations, + 0, 1, max_user_token_number + 1); + macro_insert ("translate", obstack_finish (&output_obstack)); } static void output_gram (void) { - /* With the ordinary parser, - yyprhs and yyrhs are needed only for yydebug. */ - /* With the no_parser option, all tables are generated */ - if (!semantic_parser && !no_parser_flag) - obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n"); - - output_short_table (&table_obstack, NULL, "yyprhs", rrhs, - 0, 1, nrules + 1); - + output_table_data (&output_obstack, rrhs, + 0, 1, nrules + 1); + macro_insert ("prhs", obstack_finish (&output_obstack)); + { size_t yyrhs_size = 1; short *yyrhs, *sp; @@ -341,21 +183,24 @@ for (sp = ritem + 1, i = 1; *sp; ++sp, ++i) yyrhs[i] = *sp > 0 ? *sp : 0; - output_short_table (&table_obstack, NULL, "yyrhs", yyrhs, - ritem[0], 1, yyrhs_size); + output_table_data (&output_obstack, yyrhs, + ritem[0], 1, yyrhs_size); + macro_insert ("rhs", obstack_finish (&output_obstack)); + XFREE (yyrhs); } - if (!semantic_parser && !no_parser_flag) - obstack_sgrow (&table_obstack, "\n#endif\n"); + /* if (!semantic_parser && !no_parser_flag) + obstack_sgrow (&table_obstack, "\n#endif\n"); */ } static void output_stos (void) { - output_short_table (&table_obstack, NULL, "yystos", accessing_symbol, - 0, 1, nstates); + output_table_data (&output_obstack, accessing_symbol, + 0, 1, nstates); + macro_insert ("stos", obstack_finish (&output_obstack)); } @@ -365,35 +210,10 @@ int i; int j; short *short_tab = NULL; - - obstack_sgrow (&table_obstack, "\n\ -#if YYDEBUG != 0\n"); - output_short_table (&table_obstack, - "YYRLINE[YYN] -- source line where rule number YYN was defined", - "yyrline", rline, - 0, 1, nrules + 1); - - obstack_sgrow (&table_obstack, "#endif\n\n"); - - if (token_table_flag || no_parser_flag) - { - obstack_fgrow1 (&table_obstack, "#define YYNTOKENS %d\n", ntokens); - obstack_fgrow1 (&table_obstack, "#define YYNNTS %d\n", nvars); - obstack_fgrow1 (&table_obstack, "#define YYNRULES %d\n", nrules); - obstack_fgrow1 (&table_obstack, "#define YYNSTATES %d\n", nstates); - obstack_fgrow1 (&table_obstack, "#define YYMAXUTOK %d\n\n", - max_user_token_number); - } - - /* Output the table of symbol names. */ - if (!token_table_flag && !no_parser_flag) - obstack_sgrow (&table_obstack, - "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n"); - obstack_sgrow (&table_obstack, "\ -/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n"); - obstack_sgrow (&table_obstack, - "static const char *const yytname[] =\n{\n "); + output_table_data (&output_obstack, rline, + 0, 1, nrules + 1); + macro_insert ("rline", obstack_finish (&output_obstack)); j = 0; for (i = 0; i < nsyms; i++) @@ -416,80 +236,61 @@ if (j + strsize > 75) { - obstack_sgrow (&table_obstack, "\n "); + obstack_sgrow (&output_obstack, "\n "); j = 2; } - obstack_1grow (&table_obstack, '\"'); + obstack_1grow (&output_obstack, '\"'); for (p = tags[i]; p && *p; p++) { if (*p == '"' || *p == '\\') - obstack_fgrow1 (&table_obstack, "\\%c", *p); + obstack_fgrow1 (&output_obstack, "\\%c", *p); else if (*p == '\n') - obstack_sgrow (&table_obstack, "\\n"); + obstack_sgrow (&output_obstack, "\\n"); else if (*p == '\t') - obstack_sgrow (&table_obstack, "\\t"); + obstack_sgrow (&output_obstack, "\\t"); else if (*p == '\b') - obstack_sgrow (&table_obstack, "\\b"); + obstack_sgrow (&output_obstack, "\\b"); else if (*p < 040 || *p >= 0177) - obstack_fgrow1 (&table_obstack, "\\%03o", *p); + obstack_fgrow1 (&output_obstack, "\\%03o", *p); else - obstack_1grow (&table_obstack, *p); + obstack_1grow (&output_obstack, *p); } - obstack_sgrow (&table_obstack, "\", "); + obstack_sgrow (&output_obstack, "\", "); j += strsize; } /* add a NULL entry to list of tokens */ - obstack_sgrow (&table_obstack, "NULL\n};\n"); + obstack_sgrow (&output_obstack, "NULL"); - if (!token_table_flag && !no_parser_flag) - obstack_sgrow (&table_obstack, "#endif\n\n"); + /* Finish table and store. */ + obstack_1grow (&output_obstack, 0); + macro_insert ("tname", obstack_finish (&output_obstack)); /* Output YYTOKNUM. */ - if (token_table_flag) - { - output_short_table (&table_obstack, - "YYTOKNUM[YYLEX] -- Index in YYTNAME corresponding to YYLEX", - "yytoknum", user_toknums, - 0, 1, ntokens + 1); - } + output_table_data (&output_obstack, user_toknums, + 0, 1, ntokens + 1); + macro_insert ("toknum", obstack_finish (&output_obstack)); /* Output YYR1. */ - output_short_table (&table_obstack, - "YYR1[YYN] -- Symbol number of symbol that rule YYN derives", - "yyr1", rlhs, - 0, 1, nrules + 1); + output_table_data (&output_obstack, rlhs, + 0, 1, nrules + 1); + macro_insert ("r1", obstack_finish (&output_obstack)); XFREE (rlhs + 1); - obstack_1grow (&table_obstack, '\n'); - /* Output YYR2. */ short_tab = XMALLOC (short, nrules + 1); for (i = 1; i < nrules; i++) short_tab[i] = rrhs[i + 1] - rrhs[i] - 1; short_tab[nrules] = nitems - rrhs[nrules] - 1; - output_short_table (&table_obstack, - "YYR2[YYN] -- Number of symbols composing right hand side of rule YYN", - "yyr2", short_tab, - 0, 1, nrules + 1); - obstack_1grow (&table_obstack, '\n'); - + output_table_data (&output_obstack, short_tab, + 0, 1, nrules + 1); + macro_insert ("r2", obstack_finish (&output_obstack)); XFREE (short_tab); XFREE (rrhs + 1); } - -static void -output_defines (void) -{ - obstack_fgrow1 (&table_obstack, "\n\n#define\tYYFINAL\t\t%d\n", final_state); - obstack_fgrow1 (&table_obstack, "#define\tYYFLAG\t\t%d\n", MINSHORT); - obstack_fgrow1 (&table_obstack, "#define\tYYNTBASE\t%d\n", ntokens); -} - - /*------------------------------------------------------------------. | Decide what to do for each type of token if seen as the lookahead | | token in specified state. The value returned is used as the | @@ -730,15 +531,12 @@ yydefact[i] = action_row (i); save_row (i); } - XFREE (actrow); - output_short_table (&table_obstack, - "YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE\n\ - doesn't specify something else to do. Zero means the default is an\n\ - error", - "yydefact", yydefact, - yydefact[0], 1, nstates); - obstack_1grow (&table_obstack, '\n'); + output_table_data (&output_obstack, yydefact, + yydefact[0], 1, nstates); + macro_insert ("defact", obstack_finish (&output_obstack)); + + XFREE (actrow); XFREE (yydefact); } @@ -865,10 +663,9 @@ goto_actions (void) { int i; - short *yydefgoto = XMALLOC (short, nsyms - ntokens); - state_count = XCALLOC (short, nstates); + state_count = XCALLOC (short, nstates); for (i = ntokens; i < nsyms; ++i) { int default_state = default_goto (i); @@ -876,8 +673,9 @@ yydefgoto[i - ntokens] = default_state; } - output_short_table (&table_obstack, NULL, "yydefgoto", yydefgoto, - yydefgoto[0], 1, nsyms - ntokens); + output_table_data (&output_obstack, yydefgoto, + yydefgoto[0], 1, nsyms - ntokens); + macro_insert ("defgoto", obstack_finish (&output_obstack)); XFREE (state_count); XFREE (yydefgoto); @@ -1079,14 +877,16 @@ static void output_base (void) { - output_short_table (&table_obstack, NULL, "yypact", base, - base[0], 1, nstates); - - obstack_1grow (&table_obstack, '\n'); + /* Output pact. */ + output_table_data (&output_obstack, base, + base[0], 1, nstates); + macro_insert ("pact", obstack_finish (&output_obstack)); + + /* Output pgoto. */ + output_table_data (&output_obstack, base, + base[nstates], nstates + 1, nvectors); + macro_insert ("pgoto", obstack_finish (&output_obstack)); - output_short_table (&table_obstack, NULL, "yypgoto", base, - base[nstates], nstates + 1, nvectors); - XFREE (base); } @@ -1094,9 +894,9 @@ static void output_table (void) { - obstack_fgrow1 (&table_obstack, "\n\n#define\tYYLAST\t\t%d\n\n\n", high); - output_short_table (&table_obstack, NULL, "yytable", table, - table[0], 1, high + 1); + output_table_data (&output_obstack, table, + table[0], 1, high + 1); + macro_insert ("table", obstack_finish (&output_obstack)); XFREE (table); } @@ -1104,8 +904,9 @@ static void output_check (void) { - output_short_table (&table_obstack, NULL, "yycheck", check, - check[0], 1, high + 1); + output_table_data (&output_obstack, check, + check[0], 1, high + 1); + macro_insert ("check", obstack_finish (&output_obstack)); XFREE (check); } @@ -1137,10 +938,12 @@ sort_actions (); pack_table (); - obstack_1grow (&table_obstack, '\n'); + /* FIXME: See if this is useful. */ + /* obstack_1grow (&table_obstack, '\n'); */ output_base (); output_table (); - obstack_1grow (&table_obstack, '\n'); + /* FIXME: See if this is useful. */ + /* obstack_1grow (&table_obstack, '\n'); */ output_check (); } @@ -1156,9 +959,6 @@ size_t line; int actions_dumped = 0; - if (pure_parser) - obstack_sgrow (&table_obstack, "#define YYPURE 1\n\n"); - /* Loop over lines in the standard parser file. */ if (!skeleton) { @@ -1168,115 +968,50 @@ skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE); } fskel = xfopen (skeleton, "r"); - - /* Set LINE to 2, not 1: `#line LINENUM' -- Here LINENUM is a - decimal integer constant. This specifies that the line number of - the *following* line of input, in its original source file, was - LINENUM. */ - line = 2; - while (1) + /* New output code. */ + line = 1; + c = getc (fskel); + while (c != EOF) { - enum line_type_e + if (c != '%') { - regular_line, - sync_line, /* #line. */ - actions_line /* %% actions. */ - }; - enum line_type_e line_type = regular_line; - - c = getc (fskel); - - /* Is this line special? */ - if (c == '#') - { - /* See if it's a `#line' line. */ - if ((c = getc (fskel)) == 'l') - if ((c = getc (fskel)) == 'i') - if ((c = getc (fskel)) == 'n') - if ((c = getc (fskel)) == 'e') - line_type = sync_line; - else - obstack_sgrow (&table_obstack, "#lin"); - else - obstack_sgrow (&table_obstack, "#li"); - else - obstack_sgrow (&table_obstack, "#l"); - else - obstack_sgrow (&table_obstack, "#"); + if (c == '\n') + ++line; + obstack_1grow (&table_obstack, c); + c = getc (fskel); } - else if (c == '%') + else if ((c = getc (fskel)) == '%') { - /* See if it's a `%% actions' line. */ - if ((c = getc (fskel)) == '%') - if ((c = getc (fskel)) == ' ') - if ((c = getc (fskel)) == 'a') - if ((c = getc (fskel)) == 'c') - if ((c = getc (fskel)) == 't') - if ((c = getc (fskel)) == 'i') - if ((c = getc (fskel)) == 'o') - if ((c = getc (fskel)) == 'n') - if ((c = getc (fskel)) == 's') - line_type = actions_line; - else - obstack_sgrow (&table_obstack, "%% action"); - else - obstack_sgrow (&table_obstack, "%% actio"); - else - obstack_sgrow (&table_obstack, "%% acti"); - else - obstack_sgrow (&table_obstack, "%% act"); - else - obstack_sgrow (&table_obstack, "%% ac"); - else - obstack_sgrow (&table_obstack, "%% a"); - else - obstack_sgrow (&table_obstack, "%% "); - else - obstack_sgrow (&table_obstack, "%%"); + /* Read the macro. */ + char* macro_key = 0; + char* macro_value = 0; + while (isalnum (c = getc (fskel)) || c == '_') + obstack_1grow (¯o_obstack, c); + obstack_1grow (¯o_obstack, 0); + + /* Output the right value, or see if it's something special. */ + macro_key = obstack_finish (¯o_obstack); + macro_value = macro_find (macro_key); + if (macro_value) + obstack_sgrow (&table_obstack, macro_value); + else if (!strcmp (macro_key, "line")) + obstack_fgrow1 (&table_obstack, "%d", line + 1); + else if (!strcmp (macro_key, "action")) + { + size_t size = obstack_object_size (&action_obstack); + obstack_grow (&table_obstack, + obstack_finish (&action_obstack), size); + } else - obstack_sgrow (&table_obstack, "%"); - } - - switch (line_type) - { - case sync_line: - if (!no_lines_flag) - obstack_fgrow2 (&table_obstack, "#line %d %s\n", - line, quotearg_style (c_quoting_style, skeleton)); - - /* Skip the end of line. */ - for (; c != '\n' && c != EOF; c = getc (fskel)) - /* nothing */; - break; - - case actions_line: - { - size_t size = obstack_object_size (&action_obstack); - - actions_dumped++; - assert (actions_dumped == 1); - obstack_grow (&table_obstack, - obstack_finish (&action_obstack), - size); - } - - /* Skip the end of line. */ - for (; c != '\n' && c != EOF; c = getc (fskel)) - /* nothing */; - break; - - case regular_line: - for (; c != '\n' && c != EOF; c = getc (fskel)) - obstack_1grow (&table_obstack, c); + { + obstack_sgrow (&table_obstack, "%%"); + obstack_sgrow (&table_obstack, macro_key); + } } - - if (c == EOF) - break; - obstack_1grow (&table_obstack, c); - line++; } - assert (actions_dumped == 1); + + /* End. */ xfclose (fskel); } @@ -1285,10 +1020,6 @@ { int c; - if (!no_lines_flag) - obstack_fgrow2 (&table_obstack, "#line %d %s\n", - lineno, quotearg_style (c_quoting_style, infile)); - while ((c = getc (finput)) != EOF) obstack_1grow (&table_obstack, c); } @@ -1308,7 +1039,61 @@ } } +/* FIXME. */ + +#define MACRO_INSERT_INT(Key, Value) \ +{ \ + obstack_fgrow1 (¯o_obstack, "%d", Value); \ + obstack_1grow (¯o_obstack, 0); \ + macro_insert (Key, obstack_finish (¯o_obstack)); \ +} + +#define MACRO_INSERT_STRING(Key, Value) \ +{ \ + obstack_sgrow (¯o_obstack, Value); \ + obstack_1grow (¯o_obstack, 0); \ + macro_insert (Key, obstack_finish (¯o_obstack)); \ +} + +#define MACRO_INSERT_PREFIX(Key, Value) \ +{ \ + obstack_fgrow2 (¯o_obstack, "%s%s", spec_name_prefix, Value); \ + obstack_1grow (¯o_obstack, 0); \ + macro_insert (Key, obstack_finish (¯o_obstack)); \ +} + +static void +prepare (void) +{ + MACRO_INSERT_INT ("last", high); + MACRO_INSERT_INT ("flag", MINSHORT); + MACRO_INSERT_INT ("pure", pure_parser); + MACRO_INSERT_INT ("nsym", nsyms); + MACRO_INSERT_INT ("debug", debug_flag); + MACRO_INSERT_INT ("final", final_state); + MACRO_INSERT_INT ("maxtok", max_user_token_number); + MACRO_INSERT_INT ("ntbase", ntokens); + MACRO_INSERT_INT ("verbose", 0); + + MACRO_INSERT_STRING ("filename", infile); + + MACRO_INSERT_INT ("nnts", nvars); + MACRO_INSERT_INT ("nrules", nrules); + MACRO_INSERT_INT ("nstates", nstates); + MACRO_INSERT_INT ("ntokens", ntokens); + if (spec_name_prefix) + { + MACRO_INSERT_PREFIX ("yylex", "lex"); + MACRO_INSERT_PREFIX ("yychar", "char"); + MACRO_INSERT_PREFIX ("yylval", "lval"); + MACRO_INSERT_PREFIX ("yydebug", "debug"); + MACRO_INSERT_PREFIX ("yyerror", "error"); + MACRO_INSERT_PREFIX ("yynerrs", "nerrs"); + MACRO_INSERT_PREFIX ("yyparse", "parse"); + } +} + /*----------------------------------------------------------. | Output the parsing tables and the parser code to ftable. | `----------------------------------------------------------*/ @@ -1316,8 +1101,10 @@ void output (void) { - /* output_token_defines(ftable); / * JF put out token defines FIRST */ + obstack_init (¯o_obstack); + obstack_init (&output_obstack); +#if 0 /* If using a simple parser the definition of YYSTYPE are put into TABLE_OBSTACK. */ if (!semantic_parser) @@ -1325,42 +1112,25 @@ size_t size = obstack_object_size (&attrs_obstack); obstack_grow (&table_obstack, obstack_finish (&attrs_obstack), size); } - reader_output_yylsp (&table_obstack); - if (debug_flag) - obstack_sgrow (&table_obstack, "\ -#ifndef YYDEBUG\n\ -# define YYDEBUG 1\n\ -#endif\n\ -\n"); - - if (semantic_parser) - obstack_fgrow1 (&table_obstack, "#include %s\n", - quotearg_style (c_quoting_style, attrsfile)); +#endif - if (!no_parser_flag) - obstack_sgrow (&table_obstack, "#include \n\n"); - - /* Make "const" do nothing if not in ANSI C. */ - obstack_sgrow (&table_obstack, "\ -#ifndef __cplusplus\n\ -# ifndef __STDC__\n\ -# define const\n\ -# endif\n\ -#endif\n\ -\n"); - + /* reader_output_yylsp (&table_obstack); */ free_itemsets (); - output_defines (); + output_token_translations (); -/* if (semantic_parser) */ - /* This is now unconditional because debugging printouts can use it. */ output_gram (); + XFREE (ritem); if (semantic_parser) output_stos (); output_rule_data (); output_actions (); - if (!no_parser_flag) - output_parser (); + + /* if (!no_parser_flag) */ + prepare (); + output_parser (); output_program (); + + obstack_free (¯o_obstack, 0); + obstack_free (&output_obstack, 0); } Index: src/reader.c =================================================================== RCS file: /cvsroot/bison/bison/src/reader.c,v retrieving revision 1.72 diff -u -r1.72 reader.c --- src/reader.c 2001/08/15 08:40:19 1.72 +++ src/reader.c 2001/08/21 18:14:19 @@ -34,6 +34,7 @@ #include "output.h" #include "reader.h" #include "conflicts.h" +#include "macrotab.h" /* Number of slots allocated (but not necessarily used yet) in `rline' */ static int rline_allocated; @@ -156,11 +157,12 @@ `------------------------------------------------------------*/ static inline void -copy_string (FILE *fin, struct obstack *oout, int match) +copy_string2 (FILE *fin, struct obstack *oout, int match, int store) { int c; - obstack_1grow (oout, match); + if (store) + obstack_1grow (oout, match); c = getc (fin); @@ -191,10 +193,31 @@ c = getc (fin); } + + if (store) + obstack_1grow (oout, c); +} + +/* FIXME. */ - obstack_1grow (oout, c); +static inline void +copy_string (FILE *fin, struct obstack *oout, int match) +{ + copy_string2 (fin, oout, match, 1); } +/* FIXME. */ + +static inline void +copy_identifier (FILE *fin, struct obstack *oout) +{ + int c; + + while (isalnum (c = getc (fin)) || c == '_') + obstack_1grow (oout, c); + + ungetc (c, fin); +} /*-----------------------------------------------------------------. | Dump the wannabee comment from IN to OUT1 and OUT2 (which can be | @@ -403,9 +426,11 @@ /* -1 while reading a character if prev char was %. */ int after_percent; +#if 0 if (!no_lines_flag) obstack_fgrow2 (&attrs_obstack, "#line %d %s\n", lineno, quotearg_style (c_quoting_style, infile)); +#endif after_percent = 0; @@ -874,6 +899,51 @@ nsyms--; } +/* FIXME. */ + +static void +parse_macro_decl (void) +{ + int ch = ungetc (skip_white_space (), finput); + char* macro_key; + char* macro_value; + struct obstack macro_obstack; + + obstack_init (¯o_obstack); + + /* Read key. */ + if (!isalpha (ch) && ch != '_') + { + complain (_("invalid %s declaration"), "%define"); + skip_to_char ('%'); + return; + } + copy_identifier (finput, ¯o_obstack); + macro_key = obstack_finish (¯o_obstack); + + /* Read value. */ + ch = skip_white_space (); + if (ch != '"') + { + ungetc (ch, finput); + if (ch != EOF) + { + complain (_("invalid %s declaration"), "%define"); + skip_to_char ('%'); + return; + } + else + fatal (_("Premature EOF after %s"), "\""); + } + copy_string (finput, ¯o_obstack, '"'); + macro_value = obstack_finish (¯o_obstack); + + obstack_free (¯o_obstack, 0); + + /* Store the (key, value) pair in the environment. */ + macro_insert (macro_key, macro_value); +} + /*------------------------------------------. | Parse what comes after %header_extension. | `------------------------------------------*/ @@ -981,6 +1051,10 @@ parse_source_extension_decl (); break; + case tok_define: + parse_macro_decl (); + break; + case tok_noop: break; @@ -1564,6 +1638,7 @@ if (nrules == 0) fatal (_("no rules in the input grammar")); +#if 0 /* This code is in the skeleton now. */ /* JF put out same default YYSTYPE as YACC does */ if (typed == 0 && !value_components_used) @@ -1579,6 +1654,7 @@ # define YYSTYPE int\n\ # endif\n"); } +#endif /* Report any undefined symbols and consider them nonterminals. */ @@ -1641,7 +1717,7 @@ obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); } - obstack_1grow (oout, '\n'); + /* obstack_1grow (oout, '\n'); */ } @@ -1763,9 +1839,13 @@ error_token_number = errtoken->value; - if (!no_parser_flag) - output_token_defines (&table_obstack); + output_token_defines (&output_obstack); + obstack_1grow (&output_obstack, 0); + macro_insert ("tokendef", obstack_finish (&output_obstack)); + /* if (!no_parser_flag) + output_token_defines (&table_obstack); */ + if (startval->class == unknown_sym) fatal (_("the start symbol %s is undefined"), startval->tag); else if (startval->class == token_sym) @@ -1913,10 +1993,12 @@ /* Initialize the symbol table. */ tabinit (); + /* Construct the error token */ errtoken = getsym ("error"); errtoken->class = token_sym; errtoken->user_token_number = 256; /* Value specified by POSIX. */ + /* Construct a token that represents all undefined literal tokens. It is always token number 2. */ undeftoken = getsym ("$undefined."); @@ -1926,30 +2008,22 @@ /* Read the declaration section. Copy %{ ... %} groups to TABLE_OBSTACK and FDEFINES file. Also notice any %token, %left, etc. found there. */ - obstack_1grow (&table_obstack, '\n'); - obstack_fgrow3 (&table_obstack, "\ -/* %s, made from %s\n\ - by GNU bison %s. */\n\ -\n", - no_parser_flag ? "Bison-generated parse tables" : "A Bison parser", - infile, VERSION); + /* obstack_1grow (&table_obstack, '\n'); */ - obstack_sgrow (&table_obstack, - "#define YYBISON 1 /* Identify Bison output. */\n\n"); read_declarations (); /* Start writing the guard and action files, if they are needed. */ - output_headers (); + /* output_headers (); */ /* Read in the grammar, build grammar in list form. Write out guards and actions. */ readgram (); /* Now we know whether we need the line-number stack. If we do, write its type into the .tab.h file. */ - if (defines_flag) - reader_output_yylsp (&defines_obstack); + /* if (defines_flag) + reader_output_yylsp (&defines_obstack); */ /* Write closing delimiters for actions and guards. */ - output_trailers (); - if (locations_flag) - obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n"); + /* output_trailers (); */ + /* if (locations_flag) + obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n"); */ /* Assign the symbols their symbol numbers. Write #defines for the token symbols into FDEFINES if requested. */ packsymbols (); @@ -1958,31 +2032,4 @@ /* Free the symbol table data structure since symbols are now all referred to by symbol number. */ free_symtab (); -} - - -/*------------------------------------------------------------------. -| Define YYLTYPE. Cannot be in the skeleton since we might have to | -| output it in the headers if --defines is used. | -`------------------------------------------------------------------*/ - -void -reader_output_yylsp (struct obstack *oout) -{ - if (locations_flag) - obstack_sgrow (oout, "\ -\n\ -#ifndef YYLTYPE\n\ -typedef struct yyltype\n\ -{\n\ - int first_line;\n\ - int first_column;\n\ -\n\ - int last_line;\n\ - int last_column;\n\ -} yyltype;\n\ -\n\ -# define YYLTYPE yyltype\n\ -#endif\n\ -\n"); }