From: Akim Demaille Date: Fri, 2 Nov 2001 15:26:33 +0000 (+0000) Subject: * src/symtab.h (SUNDEF): New. X-Git-Tag: BISON-1_30a~8 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/239e5c1a9adcb5f4ac268e9424c3ae5206740397 * src/symtab.h (SUNDEF): New. * src/symtab.c (bucket_new): Init user_token_number to SUNDEF to stand for `uninitialized', instead of 0. * src/reader.c (packsymbols, parse_thong_decl): Adjust. * src/lex.c (lex): Adjust. * tests/calc.at (_AT_DATA_CALC_Y): Declare a token for EOF. Number it 0. Let yylex return it instead of a plain 0. Reported by Dick Streefland. --- diff --git a/ChangeLog b/ChangeLog index 8d585fe6..3784234d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2001-11-02 Akim Demaille + + * src/symtab.h (SUNDEF): New. + * src/symtab.c (bucket_new): Init user_token_number to SUNDEF to + stand for `uninitialized', instead of 0. + * src/reader.c (packsymbols, parse_thong_decl): Adjust. + * src/lex.c (lex): Adjust. + + * tests/calc.at (_AT_DATA_CALC_Y): Declare a token for EOF. + Number it 0. + Let yylex return it instead of a plain 0. + Reported by Dick Streefland. + 2001-11-02 Akim Demaille * tests/regression.at (Mixing %token styles): New test. diff --git a/NEWS b/NEWS index 662c129b..99fb25f3 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ Changes in version 1.30a: * Fixed incorrect processing of some invalid input. * Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H. + +* %token MY_EOF 0 is supported. + Before, MY_EOF was silently renumbered as 257. Changes in version 1.30: diff --git a/src/lex.c b/src/lex.c index 6d1ec27e..a9c0b0d5 100644 --- a/src/lex.c +++ b/src/lex.c @@ -445,7 +445,7 @@ lex (void) token_buffer = obstack_finish (&token_obstack); symval = getsym (token_buffer); symval->class = token_sym; - if (!symval->user_token_number) + if (symval->user_token_number == SUNDEF) symval->user_token_number = code; return tok_identifier; } diff --git a/src/reader.c b/src/reader.c index 6c7a9eec..4d87026f 100644 --- a/src/reader.c +++ b/src/reader.c @@ -695,7 +695,6 @@ token_buffer); } prev = t; - } } @@ -821,7 +820,7 @@ parse_thong_decl (void) token_t token; struct bucket *symbol; char *typename = 0; - int usrtoknum = 0; + int usrtoknum = SUNDEF; token = lex (); /* fetch typename or first token */ if (token == tok_typename) @@ -1689,6 +1688,9 @@ token_translations_init (void) /* A token string alias? */ if (bp->user_token_number == SALIAS) continue; + + assert (bp->user_token_number != SUNDEF); + /* A token which translation has already been set? */ if (token_translations[bp->user_token_number] != 2) complain (_("tokens %s and %s both assigned number %d"), @@ -1775,7 +1777,7 @@ packsymbols (void) if (bp->class == token_sym) { - if (bp->user_token_number == 0) + if (bp->user_token_number == SUNDEF) bp->user_token_number = ++last_user_token_number; if (bp->user_token_number > max_user_token_number) max_user_token_number = bp->user_token_number; diff --git a/src/symtab.c b/src/symtab.c index 6e5d5ea9..455e74e2 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -1,5 +1,5 @@ /* Symbol table manager for Bison, - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -58,7 +58,7 @@ bucket_new (const char *tag, int hashval) res->value = 0; res->prec = 0; res->assoc = right_assoc; - res->user_token_number = 0; + res->user_token_number = SUNDEF; res->alias = NULL; res->class = unknown_sym; diff --git a/src/symtab.h b/src/symtab.h index 909b24f5..b98902e1 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -1,5 +1,5 @@ /* Definitions for symtab.c and callers, part of bison, - Copyright 1984, 1989, 1992, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -33,6 +33,7 @@ typedef enum nterm_sym /* non-terminal */ } symbol_class; +#define SUNDEF -1 /* For undefined user number. */ #define SALIAS -9991 /* for symbol generated with an alias */ typedef struct bucket diff --git a/tests/calc.at b/tests/calc.at index f1064634..a366cd85 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -64,7 +64,8 @@ static void yyungetc (int c); extern void perror (const char *s); %} -/* BISON Declarations */ +/* Bison Declarations */ +%token CALC_EOF 0 %token NUM %nonassoc '=' /* comparison */ @@ -204,7 +205,7 @@ yylex (void) /* Return end-of-file. */ if (c == EOF) - return 0; + return CALC_EOF; /* Return single chars. */ return c;