From: Robert Anisko Date: Sat, 25 Aug 2001 13:13:14 +0000 (+0000) Subject: Revert to 1.28c X-Git-Tag: pre-merge-of-1-29-branch~67 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/bbb5bcc6f85b9ae3f951ab062455767318b827ad?ds=sidebyside;hp=667a550e7be731c1a602d61d284f4a1c30e459a1 Revert to 1.28c --- diff --git a/.cvsignore b/.cvsignore index 22064aa2..e1a48168 100644 --- a/.cvsignore +++ b/.cvsignore @@ -9,4 +9,3 @@ patches *.patch *.log log patches applied *.prj releases -*.flc diff --git a/ChangeLog b/ChangeLog index dd54dca4..49cb99e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,114 +1,8 @@ -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. diff --git a/config/.cvsignore b/config/.cvsignore index c3c4413f..cd773968 100644 --- a/config/.cvsignore +++ b/config/.cvsignore @@ -1,3 +1,2 @@ Makefile *.t -*.flc diff --git a/doc/.cvsignore b/doc/.cvsignore index a9ca9a4a..5449ec43 100644 --- a/doc/.cvsignore +++ b/doc/.cvsignore @@ -14,4 +14,3 @@ bison.vr refcard.dvi refcard.log refcard.ps -*.flc \ No newline at end of file diff --git a/etc/clcommit b/etc/clcommit index cc5585a6..77972188 100755 --- a/etc/clcommit +++ b/etc/clcommit @@ -49,7 +49,7 @@ # -h,-? --help print short or long help message name=clcommit -: ${CVS="cvs"} +: ${CVS=cvs} cvsopt= updateopt= commitopt= diff --git a/intl/.cvsignore b/intl/.cvsignore index 8d84ee7b..f3c7a7c5 100644 --- a/intl/.cvsignore +++ b/intl/.cvsignore @@ -1,2 +1 @@ Makefile -*.flc \ No newline at end of file diff --git a/lib/.cvsignore b/lib/.cvsignore index 7deb8cec..8dc74bcd 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -2,4 +2,3 @@ .deps Makefile ansi2knr -*.flc \ No newline at end of file diff --git a/lib/Makefile.am b/lib/Makefile.am index 50f09c43..529ac67a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = ansi2knr noinst_LIBRARIES = libbison.a -INCLUDES = -I.. -I$(srcdir) -I../intl -I$(top_srcdir)/src +INCLUDES = -I.. -I$(srcdir) -I../intl # Heck, we are still using an old version of Automake which does not # understand LIBOBJ additions using $objext... @@ -14,7 +14,6 @@ EXTRA_DIST = malloc.c realloc.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 diff --git a/lib/Makefile.in b/lib/Makefile.in index 239b9fe8..11b91047 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -98,14 +98,14 @@ AUTOMAKE_OPTIONS = ansi2knr noinst_LIBRARIES = libbison.a -INCLUDES = -I.. -I$(srcdir) -I../intl -I$(top_srcdir)/src +INCLUDES = -I.. -I$(srcdir) -I../intl # 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 hash.h hash.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 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 @@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ ANSI2KNR = @ANSI2KNR@ -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 +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 AR = ar CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -136,10 +136,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best -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 +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 SOURCES = $(libbison_a_SOURCES) OBJECTS = $(libbison_a_OBJECTS) @@ -213,8 +213,6 @@ getopt_.c: getopt.c $(ANSI2KNR) $(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) @@ -235,9 +233,9 @@ xmalloc_.c: xmalloc.c $(ANSI2KNR) $(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 hash_.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 memchr_.o obstack_.o quote_.o \ +quotearg_.o stpcpy_.o strndup_.o strnlen_.o strspn_.o xmalloc_.o \ +xstrdup_.o : $(ANSI2KNR) tags: TAGS diff --git a/lib/hash.c b/lib/hash.c deleted file mode 100644 index fdf56948..00000000 --- a/lib/hash.c +++ /dev/null @@ -1,293 +0,0 @@ -/* hash.c -- hash table maintenance - Copyright (C) 1995 Free Software Foundation, Inc. - Written by Greg McGary - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include -#include -#include "hash.h" -#include "error.h" -#include "system.h" -#include "xalloc.h" - -static void hash_rehash __P((struct hash_table* ht)); -static unsigned long round_up_2 __P((unsigned long rough)); - -/* Implement double hashing with open addressing. The table size is - always a power of two. The secondary (`increment') hash function - is forced to return an odd-value, in order to be relatively prime - to the table size. This guarantees that the increment can - potentially hit every slot in the table during collision - resolution. */ - -void *hash_deleted_item = &hash_deleted_item; - -/* Force the table size to be a power of two, possibly rounding up the - given size. */ - -void -hash_init (struct hash_table* ht, unsigned long size, - hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp) -{ - ht->ht_size = round_up_2 (size); - if (ht->ht_size > (128 * 1024)) /* prevent size from getting out of hand */ - ht->ht_size /= 2; - ht->ht_vec = (void**) CALLOC (struct token *, ht->ht_size); - if (ht->ht_vec == 0) - error (1, 0, _("can't allocate %ld bytes for hash table: memory exhausted"), - ht->ht_size * sizeof(struct token *)); - ht->ht_capacity = ht->ht_size * 15 / 16; /* 93.75% loading factor */ - ht->ht_fill = 0; - ht->ht_collisions = 0; - ht->ht_lookups = 0; - ht->ht_rehashes = 0; - ht->ht_hash_1 = hash_1; - ht->ht_hash_2 = hash_2; - ht->ht_compare = hash_cmp; -} - -/* Load an array of items into `ht'. */ - -void -hash_load (struct hash_table* ht, void *item_table, unsigned long cardinality, unsigned long size) -{ - char *items = (char *) item_table; - while (cardinality--) - { - hash_insert (ht, items); - items += size; - } -} - -/* Returns the address of the table slot matching `key'. If `key' is - not found, return the address of an empty slot suitable for - inserting `key'. The caller is responsible for incrementing - ht_fill on insertion. */ - -void ** -hash_find_slot (struct hash_table* ht, void const *key) -{ - void **slot; - void **deleted_slot = 0; - unsigned int hash_2 = 0; - unsigned int hash_1 = (*ht->ht_hash_1) (key); - - ht->ht_lookups++; - for (;;) - { - hash_1 %= ht->ht_size; - slot = &ht->ht_vec[hash_1]; - - if (*slot == 0) - return slot; - if (*slot == hash_deleted_item) - { - if (deleted_slot == 0) - deleted_slot = slot; - } - else - { - if (key == *slot) - return slot; - if ((*ht->ht_compare) (key, *slot) == 0) - return slot; - ht->ht_collisions++; - } - if (!hash_2) - hash_2 = (*ht->ht_hash_2) (key) | 1; - hash_1 += hash_2; - } -} - -void * -hash_find_item (struct hash_table* ht, void const *key) -{ - void **slot = hash_find_slot (ht, key); - return ((HASH_VACANT (*slot)) ? 0 : *slot); -} - -void * -hash_insert (struct hash_table* ht, void *item) -{ - void **slot = hash_find_slot (ht, item); - return hash_insert_at (ht, item, slot); -} - -void * -hash_insert_at (struct hash_table* ht, void *item, void const *slot) -{ - void *old_item = *(void **) slot; - if (HASH_VACANT (old_item)) - { - ht->ht_fill++; - old_item = item; - } - *(void const **) slot = item; - if (ht->ht_fill >= ht->ht_capacity) - hash_rehash (ht); - return old_item; -} - -void * -hash_delete (struct hash_table* ht, void const *item) -{ - void **slot = hash_find_slot (ht, item); - return hash_delete_at (ht, slot); -} - -void * -hash_delete_at (struct hash_table* ht, void const *slot) -{ - void *item = *(void **) slot; - if (!HASH_VACANT (item)) - { - *(void const **) slot = hash_deleted_item; - ht->ht_fill--; - return item; - } - else - return 0; -} - -void -hash_free_items (struct hash_table* ht) -{ - void **vec = ht->ht_vec; - void **end = &vec[ht->ht_size]; - for (; vec < end; vec++) - { - void *item = *vec; - if (!HASH_VACANT (item)) - free (item); - *vec = 0; - } - ht->ht_fill = 0; -} - -void -hash_delete_items (struct hash_table* ht) -{ - void **vec = ht->ht_vec; - void **end = &vec[ht->ht_size]; - for (; vec < end; vec++) - *vec = 0; - ht->ht_fill = 0; - ht->ht_collisions = 0; - ht->ht_lookups = 0; - ht->ht_rehashes = 0; -} - -void -hash_free (struct hash_table* ht, int free_items) -{ - if (free_items) - hash_free_items (ht); - free (ht->ht_vec); - ht->ht_vec = 0; - ht->ht_fill = 0; - ht->ht_capacity = 0; -} - -void -hash_map (struct hash_table *ht, hash_map_func_t map) -{ - void **slot; - void **end = &ht->ht_vec[ht->ht_size]; - - for (slot = ht->ht_vec; slot < end; slot++) - { - if (!HASH_VACANT (*slot)) - (*map) (*slot); - } -} - -/* Double the size of the hash table in the event of overflow... */ - -static void -hash_rehash (struct hash_table* ht) -{ - unsigned long old_ht_size = ht->ht_size; - void **old_vec = ht->ht_vec; - void **ovp; - void **slot; - - ht->ht_size *= 2; - ht->ht_rehashes++; - ht->ht_capacity = ht->ht_size - (ht->ht_size >> 4); - ht->ht_vec = (void **) CALLOC (struct token *, ht->ht_size); - - for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++) - { - if (*ovp == 0) - continue; - slot = hash_find_slot (ht, *ovp); - *slot = *ovp; - } - free (old_vec); -} - -void -hash_print_stats (struct hash_table *ht, FILE *out_FILE) -{ - fprintf (out_FILE, _("Load=%ld/%ld=%.0f%%, "), ht->ht_fill, ht->ht_size, - 100.0 * (double) ht->ht_fill / (double) ht->ht_size); - fprintf (out_FILE, _("Rehash=%d, "), ht->ht_rehashes); - fprintf (out_FILE, _("Collisions=%ld/%ld=%.0f%%"), ht->ht_collisions, ht->ht_lookups, - (ht->ht_lookups - ? (100.0 * (double) ht->ht_collisions / (double) ht->ht_lookups) - : 0)); -} - -/* Dump all items into a NULL-terminated vector. Use the - user-supplied vector, or malloc one. */ - -void** -hash_dump (struct hash_table *ht, void **vector_0, qsort_cmp_t compare) -{ - void **vector; - void **slot; - void **end = &ht->ht_vec[ht->ht_size]; - - if (vector_0 == 0) - vector_0 = MALLOC (void *, ht->ht_fill + 1); - vector = vector_0; - - for (slot = ht->ht_vec; slot < end; slot++) - if (!HASH_VACANT (*slot)) - *vector++ = *slot; - *vector = 0; - - if (compare) - qsort (vector_0, ht->ht_fill, sizeof (void *), compare); - return vector_0; -} - -/* Round a given number up to the nearest power of 2. */ - -static unsigned long -round_up_2 (unsigned long rough) -{ - int round; - - round = 1; - while (rough) - { - round <<= 1; - rough >>= 1; - } - return round; -} diff --git a/lib/hash.h b/lib/hash.h deleted file mode 100644 index 56618931..00000000 --- a/lib/hash.h +++ /dev/null @@ -1,144 +0,0 @@ -/* hash.h -- decls for hash table - Copyright (C) 1995 Free Software Foundation, Inc. - Written by Greg McGary - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifndef _hash_h_ -#define _hash_h_ - -#include - -typedef unsigned long (*hash_func_t) __P((void const *key)); -typedef int (*hash_cmp_func_t) __P((void const *x, void const *y)); -typedef void (*hash_map_func_t) __P((void const *item)); - -struct hash_table -{ - void **ht_vec; - unsigned long ht_size; /* total number of slots (power of 2) */ - unsigned long ht_capacity; /* usable slots, limited by loading-factor */ - unsigned long ht_fill; /* items in table */ - unsigned long ht_collisions; /* # of failed calls to comparison function */ - unsigned long ht_lookups; /* # of queries */ - unsigned int ht_rehashes; /* # of times we've expanded table */ - hash_func_t ht_hash_1; /* primary hash function */ - hash_func_t ht_hash_2; /* secondary hash function */ - hash_cmp_func_t ht_compare; /* comparison function */ -}; - -typedef int (*qsort_cmp_t) __P((void const *, void const *)); - -void hash_init __P((struct hash_table *ht, unsigned long size, - hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp)); -void hash_load __P((struct hash_table *ht, void *item_table, - unsigned long cardinality, unsigned long size)); -void **hash_find_slot __P((struct hash_table *ht, void const *key)); -void *hash_find_item __P((struct hash_table *ht, void const *key)); -void *hash_insert __P((struct hash_table *ht, void *item)); -void *hash_insert_at __P((struct hash_table *ht, void *item, void const *slot)); -void *hash_delete __P((struct hash_table *ht, void const *item)); -void *hash_delete_at __P((struct hash_table *ht, void const *slot)); -void hash_delete_items __P((struct hash_table *ht)); -void hash_free_items __P((struct hash_table *ht)); -void hash_free __P((struct hash_table *ht, int free_items)); -void hash_map __P((struct hash_table *ht, hash_map_func_t map)); -void hash_print_stats __P((struct hash_table *ht, FILE *out_FILE)); -void **hash_dump __P((struct hash_table *ht, void **vector_0, qsort_cmp_t compare)); - -extern void *hash_deleted_item; -#define HASH_VACANT(item) ((item) == 0 || (void *) (item) == hash_deleted_item) - - -/* hash and comparison macros for string keys. */ - -#define STRING_HASH_1(_key_, _result_) { \ - unsigned char const *kk = (unsigned char const *) (_key_) - 1; \ - while (*++kk) \ - (_result_) += (*kk << (kk[1] & 0xf)); \ -} while (0) -#define return_STRING_HASH_1(_key_) do { \ - unsigned long result = 0; \ - STRING_HASH_1 ((_key_), result); \ - return result; \ -} while (0) - -#define STRING_HASH_2(_key_, _result_) do { \ - unsigned char const *kk = (unsigned char const *) (_key_) - 1; \ - while (*++kk) \ - (_result_) += (*kk << (kk[1] & 0x7)); \ -} while (0) -#define return_STRING_HASH_2(_key_) do { \ - unsigned long result = 0; \ - STRING_HASH_2 ((_key_), result); \ - return result; \ -} while (0) - -#define STRING_COMPARE(_x_, _y_, _result_) do { \ - unsigned char const *xx = (unsigned char const *) (_x_) - 1; \ - unsigned char const *yy = (unsigned char const *) (_y_) - 1; \ - do { \ - if (*++xx == '\0') { \ - yy++; \ - break; \ - } \ - } while (*xx == *++yy); \ - (_result_) = *xx - *yy; \ -} while (0) -#define return_STRING_COMPARE(_x_, _y_) do { \ - int result; \ - STRING_COMPARE (_x_, _y_, result); \ - return result; \ -} while (0) - -/* hash and comparison macros for integer keys. */ - -#define INTEGER_HASH_1(_key_, _result_) do { \ - (_result_) += ((unsigned long)(_key_)); \ -} while (0) -#define return_INTEGER_HASH_1(_key_) do { \ - unsigned long result = 0; \ - INTEGER_HASH_1 ((_key_), result); \ - return result; \ -} while (0) - -#define INTEGER_HASH_2(_key_, _result_) do { \ - (_result_) += ~((unsigned long)(_key_)); \ -} while (0) -#define return_INTEGER_HASH_2(_key_) do { \ - unsigned long result = 0; \ - INTEGER_HASH_2 ((_key_), result); \ - return result; \ -} while (0) - -#define INTEGER_COMPARE(_x_, _y_, _result_) do { \ - (_result_) = _x_ - _y_; \ -} while (0) -#define return_INTEGER_COMPARE(_x_, _y_) do { \ - int result; \ - INTEGER_COMPARE (_x_, _y_, result); \ - return result; \ -} while (0) - -/* hash and comparison macros for address keys. */ - -#define ADDRESS_HASH_1(_key_, _result_) INTEGER_HASH_1 (((unsigned long)(_key_)) >> 3, (_result_)) -#define ADDRESS_HASH_2(_key_, _result_) INTEGER_HASH_2 (((unsigned long)(_key_)) >> 3, (_result_)) -#define ADDRESS_COMPARE(_x_, _y_, _result_) INTEGER_COMPARE ((_x_), (_y_), (_result_)) -#define return_ADDRESS_HASH_1(_key_) return_INTEGER_HASH_1 (((unsigned long)(_key_)) >> 3) -#define return_ADDRESS_HASH_2(_key_) return_INTEGER_HASH_2 (((unsigned long)(_key_)) >> 3) -#define return_ADDRESS_COMPARE(_x_, _y_) return_INTEGER_COMPARE ((_x_), (_y_)) - -#endif /* not _hash_h_ */ diff --git a/lib/xalloc.h b/lib/xalloc.h index c84bccb8..098a6c2e 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -83,9 +83,5 @@ char *xstrdup PARAMS ((const char *str)); /* 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_ */ diff --git a/src/.cvsignore b/src/.cvsignore index ee7e4133..21d4b389 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -3,4 +3,3 @@ Makefile bison *.log -*.flc \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 17a32725..b757258e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ 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 macrotab.c nullable.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 @@ -20,7 +20,7 @@ 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 macrotab.h nullable.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 diff --git a/src/Makefile.in b/src/Makefile.in index 8469f276..f4e8b240 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -103,12 +103,12 @@ LDADD = @INTLLIBS@ ../lib/libbison.a 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 macrotab.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 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 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 +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 pkgdata_DATA = bison.simple bison.hairy @@ -125,8 +125,8 @@ LIBS = @LIBS@ 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 \ -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 +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 @@ TAR = tar 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/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 +.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 SOURCES = $(bison_SOURCES) $(EXTRA_bison_SOURCES) OBJECTS = $(bison_OBJECTS) @@ -226,6 +226,8 @@ bison: $(bison_OBJECTS) $(bison_DEPENDENCIES) $(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) @@ -244,10 +246,10 @@ lalr_.c: lalr.c $(ANSI2KNR) $(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) @@ -260,6 +262,14 @@ reader_.c: reader.c $(ANSI2KNR) $(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) @@ -268,9 +278,10 @@ vmsgetargs_.c: vmsgetargs.c $(ANSI2KNR) $(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 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 \ +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 \ vmsgetargs_.o warshall_.o : $(ANSI2KNR) install-pkgdataDATA: $(pkgdata_DATA) diff --git a/src/bison.simple b/src/bison.simple index de9da6c0..f8f026ca 100644 --- a/src/bison.simple +++ b/src/bison.simple @@ -1,8 +1,5 @@ -/* -*- C -*- */ - -/* A Bison parser, made from %%filename - by GNU bison %%version. */ - +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line /* Skeleton output parser for bison, Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc. @@ -31,14 +28,6 @@ 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 @@ -65,7 +54,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 @@ -89,162 +78,31 @@ # 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) @@ -252,6 +110,7 @@ while (0) #define YYTERROR 1 #define YYERRCODE 256 + /* YYLLOC_DEFAULT -- Compute the default location (before the actions are run). @@ -265,45 +124,47 @@ while (0) 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 %%initdepth +# define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -313,11 +174,9 @@ int %%yydebug; #endif #ifndef YYMAXDEPTH -# define YYMAXDEPTH %%maxdepth +# define YYMAXDEPTH 10000 #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 @@ -346,11 +205,10 @@ __yy_memcpy (char *to, const char *from, unsigned int count) while (i-- > 0) *t++ = *f++; } -#endif +#endif - -#line %%line "%%filename" +#line /* The user can define YYPARSE_PARAM as the name of an argument to be passed into yyparse. The argument should have type void *. @@ -374,9 +232,9 @@ __yy_memcpy (char *to, const char *from, unsigned int count) /* 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 @@ -385,13 +243,13 @@ int %%yyparse (void); #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 \ @@ -404,6 +262,7 @@ YYLTYPE yylloc; _YY_DECL_VARIABLES #endif + /* If nonreentrant, generate the variables here. */ #if !YYPURE @@ -411,7 +270,7 @@ YY_DECL_VARIABLES #endif /* !YYPURE */ int -%%yyparse (YYPARSE_PARAM_ARG) +yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL { /* If reentrant, generate the variables here. */ @@ -460,6 +319,7 @@ int int yystacksize = YYINITDEPTH; int yyfree_stacks = 0; + /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -475,8 +335,8 @@ int 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 @@ -489,6 +349,7 @@ int yylsp = yyls; #endif + /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ @@ -538,7 +399,7 @@ yynewstate: /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) { - %%yyerror ("parser stack overflow"); + yyerror ("parser stack overflow"); if (yyfree_stacks) { free (yyss); @@ -552,7 +413,7 @@ yynewstate: yystacksize *= 2; if (yystacksize > YYMAXDEPTH) yystacksize = YYMAXDEPTH; -# if !YYSTACK_USE_ALLOCA +# ifndef YYSTACK_USE_ALLOCA yyfree_stacks = 1; # endif yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); @@ -584,6 +445,7 @@ yynewstate: goto yybackup; + /*-----------. | yybackup. | `-----------*/ @@ -604,35 +466,35 @@ yybackup: /* 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"); } @@ -666,13 +528,13 @@ yybackup: 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 @@ -723,7 +585,7 @@ yyreduce: #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; @@ -736,11 +598,8 @@ yyreduce: fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); } #endif - switch (yyn) - { - %%action /* The action file replaces this line. */ - } -#line %%line "%%filename" +%% actions /* The action file replaces this line. */ +#line yyvsp -= yylen; yyssp -= yylen; @@ -749,7 +608,7 @@ yyreduce: #endif #if YYDEBUG - if (%%yydebug) + if (yydebug) { short *ssp1 = yyss - 1; fprintf (stderr, "state stack now"); @@ -786,9 +645,9 @@ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { - ++%%yynerrs; + ++yynerrs; -#if YYERROR_VERBOSE +#ifdef YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) @@ -804,36 +663,36 @@ yyerrlab: 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; @@ -848,11 +707,11 @@ yyerrlab1: 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 @@ -893,7 +752,7 @@ yyerrpop: #endif #if YYDEBUG - if (%%yydebug) + if (yydebug) { short *ssp1 = yyss - 1; fprintf (stderr, "Error: state stack now"); @@ -931,7 +790,7 @@ yyerrhandle: YYDPRINTF ((stderr, "Shifting error token, ")); - *++yyvsp = %%yylval; + *++yyvsp = yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif diff --git a/src/lex.c b/src/lex.c index 8bc65a19..4bd0a6f2 100644 --- a/src/lex.c +++ b/src/lex.c @@ -552,9 +552,8 @@ struct percent_table_struct percent_table[] = { "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 }, - { "define", NULL, tok_define }, + { "header_extension", NULL, tok_hdrext}, + { "source_extension", NULL, tok_srcext}, { "verbose", &verbose_flag, tok_noop }, /* -v */ { "debug", &debug_flag, tok_noop }, /* -t */ { "semantic_parser", &semantic_parser, tok_noop }, diff --git a/src/lex.h b/src/lex.h index e5d63882..c6330963 100644 --- a/src/lex.h +++ b/src/lex.h @@ -49,7 +49,6 @@ typedef enum token_e tok_thong, tok_hdrext, tok_srcext, - tok_define, tok_noop, tok_setopt, tok_illegal, diff --git a/src/macrotab.c b/src/macrotab.c deleted file mode 100644 index 91944ac2..00000000 --- a/src/macrotab.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Macro table manager for Bison, - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include - -#include "system.h" -#include "hash.h" -#include "files.h" -#include "macrotab.h" - -struct hash_table macro_table; - -static unsigned long -mhash1 (const void* item) -{ - return_STRING_HASH_1 (((macro_entry_t*) item)->key); -} - -static unsigned long -mhash2 (const void* item) -{ - return_STRING_HASH_2 (((macro_entry_t*) item)->key); -} - -static int -mcmp (const void* x, const void* y) -{ - return strcmp (((macro_entry_t*) x)->key, ((macro_entry_t*) y)->key); -} - -void -macro_init (void) -{ - hash_init (¯o_table, MTABSIZE, &mhash1, &mhash2, &mcmp); - - /* Version and input file. */ - macro_insert ("version", VERSION); - macro_insert ("filename", "a.y"); - - /* Types. */ - macro_insert ("stype", "int"); - macro_insert ("ltype", "yyltype"); - - /* Tokens. */ - macro_insert ("tokendef", ""); - - /* Tables. */ - macro_insert ("rhs", "0"); - macro_insert ("pact", "0"); - macro_insert ("prhs", "0"); - macro_insert ("stos", "0"); - macro_insert ("check", "0"); - macro_insert ("pgoto", "0"); - macro_insert ("table", "0"); - macro_insert ("tname", "0"); - macro_insert ("defact", "0"); - macro_insert ("toknum", "0"); - macro_insert ("defgoto", "0"); - macro_insert ("translate", "0"); - - /* Various macros. */ - macro_insert ("flag", "0"); - macro_insert ("last", "0"); - macro_insert ("pure", "0"); - macro_insert ("nsym", "0"); - macro_insert ("debug", "0"); - macro_insert ("final", "0"); - macro_insert ("maxtok", "0"); - macro_insert ("ntbase", "0"); - macro_insert ("verbose", "0"); - - /* Variable prefix names. */ - macro_insert ("yyparse", "yyparse"); - macro_insert ("yylex", "yylex"); - macro_insert ("yyerror", "yyerror"); - macro_insert ("yylval", "yylval"); - macro_insert ("yychar", "yychar"); - macro_insert ("yydebug", "yydebug"); - macro_insert ("yynerrs", "yynerrs"); - - /* No parser macros. */ - macro_insert ("nnts", "0"); - macro_insert ("nrules", "0"); - macro_insert ("nstates", "0"); - macro_insert ("ntokens", "0"); - - /* Stack parameters. */ - macro_insert ("maxdepth", "10000"); - macro_insert ("initdepth", "200"); - - /* C++ macros. */ - macro_insert ("name", "Parser"); -} - -void -macro_insert (char* key, char* value) -{ - macro_entry_t* pair = (macro_entry_t*) xmalloc (sizeof (macro_entry_t)); - pair->key = key; - pair->value = value; - hash_insert (¯o_table, pair); -} - -char* -macro_find (char* key) -{ - macro_entry_t pair = { key, 0 }; - macro_entry_t* result = hash_find_item (¯o_table, &pair); - return result ? result->value : 0; -} diff --git a/src/macrotab.h b/src/macrotab.h deleted file mode 100644 index 6c3a364f..00000000 --- a/src/macrotab.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Definitions for macrotab.c and callers, part of bison, - Copyright 2001 Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef MACROTAB_H_ -# define MACROTAB_H_ - -#define MTABSIZE 101 - -typedef struct macro_entry_s -{ - char* key; - char* value; -} macro_entry_t; - -void macro_init PARAMS ((void)); -void macro_insert PARAMS ((char* key, char* value)); -char* macro_find PARAMS ((char* key)); - -#endif /* not MACROTAB_H_ */ diff --git a/src/main.c b/src/main.c index 6a89f5c8..fb62ff2d 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,6 @@ main (int argc, char *argv[]) lineno = 0; getargs (argc, argv); - macro_init (); open_files (); /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE diff --git a/src/output.c b/src/output.c index 72e4048a..d5c3b990 100644 --- a/src/output.c +++ b/src/output.c @@ -103,10 +103,11 @@ #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; @@ -123,54 +124,211 @@ static short *check; static int lowzero; static int high; -struct obstack macro_obstack; -struct obstack output_obstack; -/* FIXME. */ static inline void -output_table_data (struct obstack* oout, - short* table, - short first, - short begin, - short end) +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; - int j = 1; - - obstack_fgrow1 (oout, "%6d", first); - for (i = begin; i < end; ++i) + 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++) { obstack_1grow (oout, ','); + if (j >= 10) { obstack_sgrow (oout, "\n "); j = 1; } else - ++j; - obstack_fgrow1 (oout, "%6d", table[i]); + { + j++; + } + + obstack_fgrow1 (oout, "%6d", short_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); +} + + +/*--------------------------------------------------------------. +| 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); } - obstack_1grow (oout, 0); } +/*-------------------------------------------------------. +| 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) { - output_table_data (&output_obstack, token_translations, - 0, 1, max_user_token_number + 1); - macro_insert ("translate", obstack_finish (&output_obstack)); + 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"); + } } static void output_gram (void) { - output_table_data (&output_obstack, rrhs, - 0, 1, nrules + 1); - macro_insert ("prhs", obstack_finish (&output_obstack)); - + /* 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); + { size_t yyrhs_size = 1; short *yyrhs, *sp; @@ -183,24 +341,21 @@ output_gram (void) for (sp = ritem + 1, i = 1; *sp; ++sp, ++i) yyrhs[i] = *sp > 0 ? *sp : 0; - output_table_data (&output_obstack, yyrhs, - ritem[0], 1, yyrhs_size); - macro_insert ("rhs", obstack_finish (&output_obstack)); - + output_short_table (&table_obstack, NULL, "yyrhs", yyrhs, + ritem[0], 1, yyrhs_size); 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_table_data (&output_obstack, accessing_symbol, - 0, 1, nstates); - macro_insert ("stos", obstack_finish (&output_obstack)); + output_short_table (&table_obstack, NULL, "yystos", accessing_symbol, + 0, 1, nstates); } @@ -211,9 +366,34 @@ output_rule_data (void) int j; short *short_tab = NULL; - output_table_data (&output_obstack, rline, - 0, 1, nrules + 1); - macro_insert ("rline", obstack_finish (&output_obstack)); + 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 "); j = 0; for (i = 0; i < nsyms; i++) @@ -236,61 +416,80 @@ output_rule_data (void) if (j + strsize > 75) { - obstack_sgrow (&output_obstack, "\n "); + obstack_sgrow (&table_obstack, "\n "); j = 2; } - obstack_1grow (&output_obstack, '\"'); + obstack_1grow (&table_obstack, '\"'); for (p = tags[i]; p && *p; p++) { if (*p == '"' || *p == '\\') - obstack_fgrow1 (&output_obstack, "\\%c", *p); + obstack_fgrow1 (&table_obstack, "\\%c", *p); else if (*p == '\n') - obstack_sgrow (&output_obstack, "\\n"); + obstack_sgrow (&table_obstack, "\\n"); else if (*p == '\t') - obstack_sgrow (&output_obstack, "\\t"); + obstack_sgrow (&table_obstack, "\\t"); else if (*p == '\b') - obstack_sgrow (&output_obstack, "\\b"); + obstack_sgrow (&table_obstack, "\\b"); else if (*p < 040 || *p >= 0177) - obstack_fgrow1 (&output_obstack, "\\%03o", *p); + obstack_fgrow1 (&table_obstack, "\\%03o", *p); else - obstack_1grow (&output_obstack, *p); + obstack_1grow (&table_obstack, *p); } - obstack_sgrow (&output_obstack, "\", "); + obstack_sgrow (&table_obstack, "\", "); j += strsize; } /* add a NULL entry to list of tokens */ - obstack_sgrow (&output_obstack, "NULL"); + obstack_sgrow (&table_obstack, "NULL\n};\n"); - /* Finish table and store. */ - obstack_1grow (&output_obstack, 0); - macro_insert ("tname", obstack_finish (&output_obstack)); + if (!token_table_flag && !no_parser_flag) + obstack_sgrow (&table_obstack, "#endif\n\n"); /* Output YYTOKNUM. */ - output_table_data (&output_obstack, user_toknums, - 0, 1, ntokens + 1); - macro_insert ("toknum", obstack_finish (&output_obstack)); + 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 YYR1. */ - output_table_data (&output_obstack, rlhs, - 0, 1, nrules + 1); - macro_insert ("r1", obstack_finish (&output_obstack)); + output_short_table (&table_obstack, + "YYR1[YYN] -- Symbol number of symbol that rule YYN derives", + "yyr1", rlhs, + 0, 1, nrules + 1); 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_table_data (&output_obstack, short_tab, - 0, 1, nrules + 1); - macro_insert ("r2", obstack_finish (&output_obstack)); + 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'); + 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 | @@ -531,12 +730,15 @@ token_actions (void) yydefact[i] = action_row (i); save_row (i); } - - output_table_data (&output_obstack, yydefact, - yydefact[0], 1, nstates); - macro_insert ("defact", obstack_finish (&output_obstack)); - 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'); XFREE (yydefact); } @@ -663,9 +865,10 @@ static void goto_actions (void) { int i; - short *yydefgoto = XMALLOC (short, nsyms - ntokens); + short *yydefgoto = XMALLOC (short, nsyms - ntokens); state_count = XCALLOC (short, nstates); + for (i = ntokens; i < nsyms; ++i) { int default_state = default_goto (i); @@ -673,9 +876,8 @@ goto_actions (void) yydefgoto[i - ntokens] = default_state; } - output_table_data (&output_obstack, yydefgoto, - yydefgoto[0], 1, nsyms - ntokens); - macro_insert ("defgoto", obstack_finish (&output_obstack)); + output_short_table (&table_obstack, NULL, "yydefgoto", yydefgoto, + yydefgoto[0], 1, nsyms - ntokens); XFREE (state_count); XFREE (yydefgoto); @@ -877,15 +1079,13 @@ pack_table (void) static void output_base (void) { - /* Output pact. */ - output_table_data (&output_obstack, base, - base[0], 1, nstates); - macro_insert ("pact", obstack_finish (&output_obstack)); + output_short_table (&table_obstack, NULL, "yypact", base, + base[0], 1, nstates); + + obstack_1grow (&table_obstack, '\n'); - /* 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); } @@ -894,9 +1094,9 @@ output_base (void) static void output_table (void) { - output_table_data (&output_obstack, table, - table[0], 1, high + 1); - macro_insert ("table", obstack_finish (&output_obstack)); + 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); XFREE (table); } @@ -904,9 +1104,8 @@ output_table (void) static void output_check (void) { - output_table_data (&output_obstack, check, - check[0], 1, high + 1); - macro_insert ("check", obstack_finish (&output_obstack)); + output_short_table (&table_obstack, NULL, "yycheck", check, + check[0], 1, high + 1); XFREE (check); } @@ -938,12 +1137,10 @@ output_actions (void) sort_actions (); pack_table (); - /* FIXME: See if this is useful. */ - /* obstack_1grow (&table_obstack, '\n'); */ + obstack_1grow (&table_obstack, '\n'); output_base (); output_table (); - /* FIXME: See if this is useful. */ - /* obstack_1grow (&table_obstack, '\n'); */ + obstack_1grow (&table_obstack, '\n'); output_check (); } @@ -959,6 +1156,9 @@ output_parser (void) 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) { @@ -969,49 +1169,114 @@ output_parser (void) } fskel = xfopen (skeleton, "r"); - /* New output code. */ - line = 1; - c = getc (fskel); - while (c != EOF) + /* 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) { - if (c != '%') + enum line_type_e { - if (c == '\n') - ++line; - obstack_1grow (&table_obstack, c); - c = getc (fskel); - } - else if ((c = getc (fskel)) == '%') + 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 == '#') { - /* 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); - } + /* 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, "#"); + } + else if (c == '%') + { + /* 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, "%%"); - obstack_sgrow (&table_obstack, macro_key); - } + 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); } - } - /* End. */ + if (c == EOF) + break; + obstack_1grow (&table_obstack, c); + line++; + } + assert (actions_dumped == 1); xfclose (fskel); } @@ -1020,6 +1285,10 @@ output_program (void) { 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); } @@ -1039,60 +1308,6 @@ free_itemsets (void) } } -/* 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. | @@ -1101,10 +1316,8 @@ prepare (void) void output (void) { - obstack_init (¯o_obstack); - obstack_init (&output_obstack); + /* output_token_defines(ftable); / * JF put out token defines FIRST */ -#if 0 /* If using a simple parser the definition of YYSTYPE are put into TABLE_OBSTACK. */ if (!semantic_parser) @@ -1112,25 +1325,42 @@ output (void) size_t size = obstack_object_size (&attrs_obstack); obstack_grow (&table_obstack, obstack_finish (&attrs_obstack), size); } -#endif + reader_output_yylsp (&table_obstack); + if (debug_flag) + obstack_sgrow (&table_obstack, "\ +#ifndef YYDEBUG\n\ +# define YYDEBUG 1\n\ +#endif\n\ +\n"); - /* reader_output_yylsp (&table_obstack); */ - free_itemsets (); + if (semantic_parser) + obstack_fgrow1 (&table_obstack, "#include %s\n", + quotearg_style (c_quoting_style, attrsfile)); + + 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"); + + 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) */ - prepare (); - output_parser (); + if (!no_parser_flag) + output_parser (); output_program (); - - obstack_free (¯o_obstack, 0); - obstack_free (&output_obstack, 0); } diff --git a/src/reader.c b/src/reader.c index cc8f90a0..7e23c0ef 100644 --- a/src/reader.c +++ b/src/reader.c @@ -34,7 +34,6 @@ #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; @@ -157,12 +156,11 @@ get_type_name (int n, symbol_list * rule) `------------------------------------------------------------*/ static inline void -copy_string2 (FILE *fin, struct obstack *oout, int match, int store) +copy_string (FILE *fin, struct obstack *oout, int match) { int c; - if (store) - obstack_1grow (oout, match); + obstack_1grow (oout, match); c = getc (fin); @@ -194,30 +192,9 @@ copy_string2 (FILE *fin, struct obstack *oout, int match, int store) c = getc (fin); } - if (store) - obstack_1grow (oout, c); -} - -/* FIXME. */ - -static inline void -copy_string (FILE *fin, struct obstack *oout, int match) -{ - copy_string2 (fin, oout, match, 1); + obstack_1grow (oout, c); } -/* 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 | @@ -426,11 +403,9 @@ copy_definition (void) /* -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; @@ -899,51 +874,6 @@ parse_thong_decl (void) 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. | `------------------------------------------*/ @@ -1051,10 +981,6 @@ read_declarations (void) parse_source_extension_decl (); break; - case tok_define: - parse_macro_decl (); - break; - case tok_noop: break; @@ -1638,7 +1564,6 @@ readgram (void) 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) @@ -1654,7 +1579,6 @@ readgram (void) # define YYSTYPE int\n\ # endif\n"); } -#endif /* Report any undefined symbols and consider them nonterminals. */ @@ -1717,7 +1641,7 @@ output_token_defines (struct obstack *oout) obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value); } - /* obstack_1grow (oout, '\n'); */ + obstack_1grow (oout, '\n'); } @@ -1839,12 +1763,8 @@ packsymbols (void) error_token_number = errtoken->value; - 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 (!no_parser_flag) + output_token_defines (&table_obstack); if (startval->class == unknown_sym) fatal (_("the start symbol %s is undefined"), startval->tag); @@ -1993,12 +1913,10 @@ reader (void) /* 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."); @@ -2008,22 +1926,30 @@ reader (void) /* 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_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_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 (); @@ -2033,3 +1959,30 @@ reader (void) 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"); +} diff --git a/tests/.cvsignore b/tests/.cvsignore index a9e1cc51..3e35ca4a 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -13,4 +13,3 @@ calc.[chy] calc.tab.* calc *.output *.vcg -*.flc \ No newline at end of file