1 /* Symbol table manager for Bison. 
   3    Copyright (C) 1984, 1989, 2000-2002, 2004-2010 Free Software 
   6    This file is part of Bison, the GNU Compiler Compiler. 
   8    This program is free software: you can redistribute it and/or modify 
   9    it under the terms of the GNU General Public License as published by 
  10    the Free Software Foundation, either version 3 of the License, or 
  11    (at your option) any later version. 
  13    This program is distributed in the hope that it will be useful, 
  14    but WITHOUT ANY WARRANTY; without even the implied warranty of 
  15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  16    GNU General Public License for more details. 
  18    You should have received a copy of the GNU General Public License 
  19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */ 
  31 /*-------------------------------------------------------------------. 
  32 | Symbols sorted by tag.  Allocated by the first invocation of       | 
  33 | symbols_do, after which no more symbols should be created.         | 
  34 `-------------------------------------------------------------------*/ 
  36 static symbol 
**symbols_sorted 
= NULL
; 
  38 /*------------------------. 
  39 | Distinguished symbols.  | 
  40 `------------------------*/ 
  42 symbol 
*errtoken 
= NULL
; 
  43 symbol 
*undeftoken 
= NULL
; 
  44 symbol 
*endtoken 
= NULL
; 
  45 symbol 
*accept 
= NULL
; 
  46 symbol 
*startsymbol 
= NULL
; 
  47 location startsymbol_location
; 
  49 /*---------------------------------------. 
  50 | Default %destructor's and %printer's.  | 
  51 `---------------------------------------*/ 
  53 static code_props default_tagged_destructor 
= CODE_PROPS_NONE_INIT
; 
  54 static code_props default_tagless_destructor 
= CODE_PROPS_NONE_INIT
; 
  55 static code_props default_tagged_printer 
= CODE_PROPS_NONE_INIT
; 
  56 static code_props default_tagless_printer 
= CODE_PROPS_NONE_INIT
; 
  58 /*---------------------------------. 
  59 | Create a new symbol, named TAG.  | 
  60 `---------------------------------*/ 
  63 symbol_new (uniqstr tag
, location loc
) 
  65   symbol 
*res 
= xmalloc (sizeof *res
); 
  69   /* If the tag is not a string (starts with a double quote), check 
  70      that it is valid for Yacc. */ 
  71   if (tag
[0] != '\"' && tag
[0] != '\'' && strchr (tag
, '-')) 
  72     yacc_at (loc
, _("POSIX Yacc forbids dashes in symbol names: %s"), 
  78   res
->type_name 
= NULL
; 
  79   code_props_none_init (&res
->destructor
); 
  80   code_props_none_init (&res
->printer
); 
  82   res
->number 
= NUMBER_UNDEFINED
; 
  84   res
->assoc 
= undef_assoc
; 
  85   res
->user_token_number 
= USER_NUMBER_UNDEFINED
; 
  88   res
->class = unknown_sym
; 
  89   res
->declared 
= false; 
  91   if (nsyms 
== SYMBOL_NUMBER_MAXIMUM
) 
  92     fatal (_("too many symbols in input grammar (limit is %d)"), 
  93            SYMBOL_NUMBER_MAXIMUM
); 
  98 /*----------------------------------------. 
  99 | Create a new semantic type, named TAG.  | 
 100 `----------------------------------------*/ 
 102 static semantic_type 
* 
 103 semantic_type_new (uniqstr tag
) 
 105   semantic_type 
*res 
= xmalloc (sizeof *res
); 
 107   uniqstr_assert (tag
); 
 109   code_props_none_init (&res
->destructor
); 
 110   code_props_none_init (&res
->printer
); 
 120 #define SYMBOL_ATTR_PRINT(Attr)                         \ 
 122     fprintf (f, " %s { %s }", #Attr, s->Attr) 
 124 #define SYMBOL_CODE_PRINT(Attr)                         \ 
 126     fprintf (f, " %s { %s }", #Attr, s->Attr.code) 
 129 symbol_print (symbol 
*s
, FILE *f
) 
 133       fprintf (f
, "\"%s\"", s
->tag
); 
 134       SYMBOL_ATTR_PRINT (type_name
); 
 135       SYMBOL_CODE_PRINT (destructor
); 
 136       SYMBOL_CODE_PRINT (printer
); 
 139     fprintf (f
, "<NULL>"); 
 142 #undef SYMBOL_ATTR_PRINT 
 143 #undef SYMBOL_CODE_PRINT 
 146 /*----------------------------------. 
 147 | Whether S is a valid identifier.  | 
 148 `----------------------------------*/ 
 151 is_identifier (uniqstr s
) 
 153   static char const alphanum
[26 + 26 + 1 + 10] = 
 154     "abcdefghijklmnopqrstuvwxyz" 
 155     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
 158   if (!s 
|| ! memchr (alphanum
, *s
, sizeof alphanum 
- 10)) 
 161     if (! memchr (alphanum
, *s
, sizeof alphanum
)) 
 167 /*-----------------------------------------------. 
 168 | Get the identifier associated to this symbol.  | 
 169 `-----------------------------------------------*/ 
 171 symbol_id_get (symbol 
const *sym
) 
 173   aver (sym
->user_token_number 
!= USER_NUMBER_HAS_STRING_ALIAS
); 
 176   return is_identifier (sym
->tag
) ? sym
->tag 
: 0; 
 180 /*------------------------------------------------------------------. 
 181 | Complain that S's WHAT is redeclared at SECOND, and was first set | 
 183 `------------------------------------------------------------------*/ 
 186 symbol_redeclaration (symbol 
*s
, const char *what
, location first
, 
 189   complain_at (second
, _("%s redeclaration for %s"), what
, s
->tag
); 
 190   complain_at (first
, _("previous declaration")); 
 194 semantic_type_redeclaration (semantic_type 
*s
, const char *what
, location first
, 
 197   complain_at (second
, _("%s redeclaration for <%s>"), what
, s
->tag
); 
 198   complain_at (first
, _("previous declaration")); 
 203 /*-----------------------------------------------------------------. 
 204 | Set the TYPE_NAME associated with SYM.  Does nothing if passed 0 | 
 206 `-----------------------------------------------------------------*/ 
 209 symbol_type_set (symbol 
*sym
, uniqstr type_name
, location loc
) 
 214         symbol_redeclaration (sym
, "%type", sym
->type_location
, loc
); 
 215       uniqstr_assert (type_name
); 
 216       sym
->type_name 
= type_name
; 
 217       sym
->type_location 
= loc
; 
 221 /*-----------------------------------------. 
 222 | Set the DESTRUCTOR associated with SYM.  | 
 223 `-----------------------------------------*/ 
 226 symbol_destructor_set (symbol 
*sym
, code_props 
const *destructor
) 
 228   if (sym
->destructor
.code
) 
 229     symbol_redeclaration (sym
, "%destructor", sym
->destructor
.location
, 
 230                           destructor
->location
); 
 231   sym
->destructor 
= *destructor
; 
 234 /*------------------------------------------. 
 235 | Set the DESTRUCTOR associated with TYPE.  | 
 236 `------------------------------------------*/ 
 239 semantic_type_destructor_set (semantic_type 
*type
, 
 240                               code_props 
const *destructor
) 
 242   if (type
->destructor
.code
) 
 243     semantic_type_redeclaration (type
, "%destructor", 
 244                                  type
->destructor
.location
, 
 245                                  destructor
->location
); 
 246   type
->destructor 
= *destructor
; 
 249 /*---------------------------------------. 
 250 | Get the computed %destructor for SYM.  | 
 251 `---------------------------------------*/ 
 254 symbol_destructor_get (symbol 
const *sym
) 
 256   /* Per-symbol %destructor.  */ 
 257   if (sym
->destructor
.code
) 
 258     return &sym
->destructor
; 
 260   /* Per-type %destructor.  */ 
 263       code_props 
const *destructor 
= 
 264         &semantic_type_get (sym
->type_name
)->destructor
; 
 265       if (destructor
->code
) 
 269   /* Apply default %destructor's only to user-defined symbols.  */ 
 270   if (sym
->tag
[0] == '$' || sym 
== errtoken
) 
 271     return &code_props_none
; 
 274     return &default_tagged_destructor
; 
 275   return &default_tagless_destructor
; 
 278 /*--------------------------------------. 
 279 | Set the PRINTER associated with SYM.  | 
 280 `--------------------------------------*/ 
 283 symbol_printer_set (symbol 
*sym
, code_props 
const *printer
) 
 285   if (sym
->printer
.code
) 
 286     symbol_redeclaration (sym
, "%printer", 
 287                           sym
->printer
.location
, printer
->location
); 
 288   sym
->printer 
= *printer
; 
 291 /*---------------------------------------. 
 292 | Set the PRINTER associated with TYPE.  | 
 293 `---------------------------------------*/ 
 296 semantic_type_printer_set (semantic_type 
*type
, code_props 
const *printer
) 
 298   if (type
->printer
.code
) 
 299     semantic_type_redeclaration (type
, "%printer", 
 300                                  type
->printer
.location
, printer
->location
); 
 301   type
->printer 
= *printer
; 
 304 /*------------------------------------. 
 305 | Get the computed %printer for SYM.  | 
 306 `------------------------------------*/ 
 309 symbol_printer_get (symbol 
const *sym
) 
 311   /* Per-symbol %printer.  */ 
 312   if (sym
->printer
.code
) 
 313     return &sym
->printer
; 
 315   /* Per-type %printer.  */ 
 318       code_props 
const *printer 
= &semantic_type_get (sym
->type_name
)->printer
; 
 323   /* Apply the default %printer only to user-defined symbols.  */ 
 324   if (sym
->tag
[0] == '$' || sym 
== errtoken
) 
 325     return &code_props_none
; 
 328     return &default_tagged_printer
; 
 329   return &default_tagless_printer
; 
 332 /*-----------------------------------------------------------------. 
 333 | Set the PRECEDENCE associated with SYM.  Does nothing if invoked | 
 334 | with UNDEF_ASSOC as ASSOC.                                       | 
 335 `-----------------------------------------------------------------*/ 
 338 symbol_precedence_set (symbol 
*sym
, int prec
, assoc a
, location loc
) 
 340   if (a 
!= undef_assoc
) 
 343         symbol_redeclaration (sym
, assoc_to_string (a
), sym
->prec_location
, 
 347       sym
->prec_location 
= loc
; 
 350   /* Only terminals have a precedence. */ 
 351   symbol_class_set (sym
, token_sym
, loc
, false); 
 355 /*------------------------------------. 
 356 | Set the CLASS associated with SYM.  | 
 357 `------------------------------------*/ 
 360 symbol_class_set (symbol 
*sym
, symbol_class 
class, location loc
, bool declaring
) 
 362   if (sym
->class != unknown_sym 
&& sym
->class != class) 
 364       complain_at (loc
, _("symbol %s redefined"), sym
->tag
); 
 365       sym
->declared 
= false; 
 368   if (class == nterm_sym 
&& sym
->class != nterm_sym
) 
 369     sym
->number 
= nvars
++; 
 370   else if (class == token_sym 
&& sym
->number 
== NUMBER_UNDEFINED
) 
 371     sym
->number 
= ntokens
++; 
 378         warn_at (loc
, _("symbol %s redeclared"), sym
->tag
); 
 379       sym
->declared 
= true; 
 384 /*------------------------------------------------. 
 385 | Set the USER_TOKEN_NUMBER associated with SYM.  | 
 386 `------------------------------------------------*/ 
 389 symbol_user_token_number_set (symbol 
*sym
, int user_token_number
, location loc
) 
 391   int *user_token_numberp
; 
 393   if (sym
->user_token_number 
!= USER_NUMBER_HAS_STRING_ALIAS
) 
 394     user_token_numberp 
= &sym
->user_token_number
; 
 396     user_token_numberp 
= &sym
->alias
->user_token_number
; 
 397   if (*user_token_numberp 
!= USER_NUMBER_UNDEFINED
 
 398       && *user_token_numberp 
!= user_token_number
) 
 399     complain_at (loc
, _("redefining user token number of %s"), sym
->tag
); 
 401   *user_token_numberp 
= user_token_number
; 
 402   /* User defined $end token? */ 
 403   if (user_token_number 
== 0) 
 406       endtoken
->number 
= 0; 
 407       /* It is always mapped to 0, so it was already counted in 
 414 /*----------------------------------------------------------. 
 415 | If SYM is not defined, report an error, and consider it a | 
 417 `----------------------------------------------------------*/ 
 420 symbol_check_defined (symbol 
*sym
) 
 422   if (sym
->class == unknown_sym
) 
 426          _("symbol %s is used, but is not defined as a token and has no rules"), 
 428       sym
->class = nterm_sym
; 
 429       sym
->number 
= nvars
++; 
 436 symbol_check_defined_processor (void *sym
, void *null ATTRIBUTE_UNUSED
) 
 438   return symbol_check_defined (sym
); 
 443 symbol_make_alias (symbol 
*sym
, symbol 
*str
, location loc
) 
 446     warn_at (loc
, _("symbol `%s' used more than once as a literal string"), 
 449     warn_at (loc
, _("symbol `%s' given more than one literal string"), 
 453       str
->class = token_sym
; 
 454       str
->user_token_number 
= sym
->user_token_number
; 
 455       sym
->user_token_number 
= USER_NUMBER_HAS_STRING_ALIAS
; 
 458       str
->number 
= sym
->number
; 
 459       symbol_type_set (str
, sym
->type_name
, loc
); 
 464 /*---------------------------------------------------------. 
 465 | Check that THIS, and its alias, have same precedence and | 
 467 `---------------------------------------------------------*/ 
 470 symbol_check_alias_consistency (symbol 
*this) 
 473   symbol 
*str 
= this->alias
; 
 475   /* Check only the symbol in the symbol-string pair.  */ 
 477         && this->user_token_number 
== USER_NUMBER_HAS_STRING_ALIAS
)) 
 480   if (str
->type_name 
!= sym
->type_name
) 
 483         symbol_type_set (sym
, str
->type_name
, str
->type_location
); 
 485         symbol_type_set (str
, sym
->type_name
, sym
->type_location
); 
 489   if (str
->destructor
.code 
|| sym
->destructor
.code
) 
 491       if (str
->destructor
.code
) 
 492         symbol_destructor_set (sym
, &str
->destructor
); 
 494         symbol_destructor_set (str
, &sym
->destructor
); 
 497   if (str
->printer
.code 
|| sym
->printer
.code
) 
 499       if (str
->printer
.code
) 
 500         symbol_printer_set (sym
, &str
->printer
); 
 502         symbol_printer_set (str
, &sym
->printer
); 
 505   if (sym
->prec 
|| str
->prec
) 
 508         symbol_precedence_set (sym
, str
->prec
, str
->assoc
, 
 511         symbol_precedence_set (str
, sym
->prec
, sym
->assoc
, 
 517 symbol_check_alias_consistency_processor (void *this, 
 518                                           void *null ATTRIBUTE_UNUSED
) 
 520   symbol_check_alias_consistency (this); 
 525 /*-------------------------------------------------------------------. 
 526 | Assign a symbol number, and write the definition of the token name | 
 527 | into FDEFINES.  Put in SYMBOLS.                                    | 
 528 `-------------------------------------------------------------------*/ 
 531 symbol_pack (symbol 
*this) 
 533   aver (this->number 
!= NUMBER_UNDEFINED
); 
 534   if (this->class == nterm_sym
) 
 535     this->number 
+= ntokens
; 
 536   else if (this->user_token_number 
== USER_NUMBER_HAS_STRING_ALIAS
) 
 539   symbols
[this->number
] = this; 
 544 symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED
) 
 546   return symbol_pack (this); 
 551 user_token_number_redeclaration (int num
, symbol 
*first
, symbol 
*second
) 
 553   /* User token numbers are not assigned during the parsing, but in a 
 554      second step, via a traversal of the symbol table sorted on tag. 
 556      However, error messages make more sense if we keep the first 
 557      declaration first.  */ 
 558   if (location_cmp (first
->location
, second
->location
) > 0) 
 564   complain_at (second
->location
, 
 565                _("user token number %d redeclaration for %s"), 
 567   complain_at (first
->location
, _("previous declaration for %s"), 
 571 /*--------------------------------------------------. 
 572 | Put THIS in TOKEN_TRANSLATIONS if it is a token.  | 
 573 `--------------------------------------------------*/ 
 576 symbol_translation (symbol 
*this) 
 579   if (this->class == token_sym
 
 580       && this->user_token_number 
!= USER_NUMBER_HAS_STRING_ALIAS
) 
 582       /* A token which translation has already been set? */ 
 583       if (token_translations
[this->user_token_number
] != undeftoken
->number
) 
 584         user_token_number_redeclaration
 
 585           (this->user_token_number
, 
 586            symbols
[token_translations
[this->user_token_number
]], 
 589       token_translations
[this->user_token_number
] = this->number
; 
 596 symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED
) 
 598   return symbol_translation (this); 
 602 /*---------------------------------------. 
 603 | Symbol and semantic type hash tables.  | 
 604 `---------------------------------------*/ 
 606 /* Initial capacity of symbol and semantic type hash table.  */ 
 607 #define HT_INITIAL_CAPACITY 257 
 609 static struct hash_table 
*symbol_table 
= NULL
; 
 610 static struct hash_table 
*semantic_type_table 
= NULL
; 
 613 hash_compare_symbol (const symbol 
*m1
, const symbol 
*m2
) 
 615   /* Since tags are unique, we can compare the pointers themselves.  */ 
 616   return UNIQSTR_EQ (m1
->tag
, m2
->tag
); 
 620 hash_compare_semantic_type (const semantic_type 
*m1
, const semantic_type 
*m2
) 
 622   /* Since names are unique, we can compare the pointers themselves.  */ 
 623   return UNIQSTR_EQ (m1
->tag
, m2
->tag
); 
 627 hash_symbol_comparator (void const *m1
, void const *m2
) 
 629   return hash_compare_symbol (m1
, m2
); 
 633 hash_semantic_type_comparator (void const *m1
, void const *m2
) 
 635   return hash_compare_semantic_type (m1
, m2
); 
 639 hash_symbol (const symbol 
*m
, size_t tablesize
) 
 641   /* Since tags are unique, we can hash the pointer itself.  */ 
 642   return ((uintptr_t) m
->tag
) % tablesize
; 
 646 hash_semantic_type (const semantic_type 
*m
, size_t tablesize
) 
 648   /* Since names are unique, we can hash the pointer itself.  */ 
 649   return ((uintptr_t) m
->tag
) % tablesize
; 
 653 hash_symbol_hasher (void const *m
, size_t tablesize
) 
 655   return hash_symbol (m
, tablesize
); 
 659 hash_semantic_type_hasher (void const *m
, size_t tablesize
) 
 661   return hash_semantic_type (m
, tablesize
); 
 664 /*-------------------------------. 
 665 | Create the symbol hash table.  | 
 666 `-------------------------------*/ 
 671   symbol_table 
= hash_initialize (HT_INITIAL_CAPACITY
, 
 674                                   hash_symbol_comparator
, 
 676   semantic_type_table 
= hash_initialize (HT_INITIAL_CAPACITY
, 
 678                                          hash_semantic_type_hasher
, 
 679                                          hash_semantic_type_comparator
, 
 684 /*----------------------------------------------------------------. 
 685 | Find the symbol named KEY, and return it.  If it does not exist | 
 687 `----------------------------------------------------------------*/ 
 690 symbol_from_uniqstr (const uniqstr key
, location loc
) 
 696   entry 
= hash_lookup (symbol_table
, &probe
); 
 700       /* First insertion in the hash. */ 
 701       aver (!symbols_sorted
); 
 702       entry 
= symbol_new (key
, loc
); 
 703       if (!hash_insert (symbol_table
, entry
)) 
 710 /*-----------------------------------------------------------------------. 
 711 | Find the semantic type named KEY, and return it.  If it does not exist | 
 713 `-----------------------------------------------------------------------*/ 
 716 semantic_type_from_uniqstr (const uniqstr key
) 
 719   semantic_type 
*entry
; 
 722   entry 
= hash_lookup (semantic_type_table
, &probe
); 
 726       /* First insertion in the hash. */ 
 727       entry 
= semantic_type_new (key
); 
 728       if (!hash_insert (semantic_type_table
, entry
)) 
 735 /*----------------------------------------------------------------. 
 736 | Find the symbol named KEY, and return it.  If it does not exist | 
 738 `----------------------------------------------------------------*/ 
 741 symbol_get (const char *key
, location loc
) 
 743   return symbol_from_uniqstr (uniqstr_new (key
), loc
); 
 747 /*-----------------------------------------------------------------------. 
 748 | Find the semantic type named KEY, and return it.  If it does not exist | 
 750 `-----------------------------------------------------------------------*/ 
 753 semantic_type_get (const char *key
) 
 755   return semantic_type_from_uniqstr (uniqstr_new (key
)); 
 759 /*------------------------------------------------------------------. 
 760 | Generate a dummy nonterminal, whose name cannot conflict with the | 
 762 `------------------------------------------------------------------*/ 
 765 dummy_symbol_get (location loc
) 
 767   /* Incremented for each generated symbol.  */ 
 768   static int dummy_count 
= 0; 
 769   static char buf
[256]; 
 773   sprintf (buf
, "$@%d", ++dummy_count
); 
 774   sym 
= symbol_get (buf
, loc
); 
 775   sym
->class = nterm_sym
; 
 776   sym
->number 
= nvars
++; 
 781 symbol_is_dummy (const symbol 
*sym
) 
 783   return sym
->tag
[0] == '@' || (sym
->tag
[0] == '$' && sym
->tag
[1] == '@'); 
 786 /*-------------------. 
 787 | Free the symbols.  | 
 788 `-------------------*/ 
 793   hash_free (symbol_table
); 
 794   hash_free (semantic_type_table
); 
 796   free (symbols_sorted
); 
 800 /*---------------------------------------------------------------. 
 801 | Look for undefined symbols, report an error, and consider them | 
 803 `---------------------------------------------------------------*/ 
 806 symbols_cmp (symbol 
const *a
, symbol 
const *b
) 
 808   return strcmp (a
->tag
, b
->tag
); 
 812 symbols_cmp_qsort (void const *a
, void const *b
) 
 814   return symbols_cmp (*(symbol 
* const *)a
, *(symbol 
* const *)b
); 
 818 symbols_do (Hash_processor processor
, void *processor_data
) 
 820   size_t count 
= hash_get_n_entries (symbol_table
); 
 823       symbols_sorted 
= xnmalloc (count
, sizeof *symbols_sorted
); 
 824       hash_get_entries (symbol_table
, (void**)symbols_sorted
, count
); 
 825       qsort (symbols_sorted
, count
, sizeof *symbols_sorted
, 
 830     for (i 
= 0; i 
< count
; ++i
) 
 831       processor (symbols_sorted
[i
], processor_data
); 
 835 /*--------------------------------------------------------------. 
 836 | Check that all the symbols are defined.  Report any undefined | 
 837 | symbols and consider them nonterminals.                       | 
 838 `--------------------------------------------------------------*/ 
 841 symbols_check_defined (void) 
 843   symbols_do (symbol_check_defined_processor
, NULL
); 
 846 /*------------------------------------------------------------------. 
 847 | Set TOKEN_TRANSLATIONS.  Check that no two symbols share the same | 
 849 `------------------------------------------------------------------*/ 
 852 symbols_token_translations_init (void) 
 854   bool num_256_available_p 
= true; 
 857   /* Find the highest user token number, and whether 256, the POSIX 
 858      preferred user token number for the error token, is used.  */ 
 859   max_user_token_number 
= 0; 
 860   for (i 
= 0; i 
< ntokens
; ++i
) 
 862       symbol 
*this = symbols
[i
]; 
 863       if (this->user_token_number 
!= USER_NUMBER_UNDEFINED
) 
 865           if (this->user_token_number 
> max_user_token_number
) 
 866             max_user_token_number 
= this->user_token_number
; 
 867           if (this->user_token_number 
== 256) 
 868             num_256_available_p 
= false; 
 872   /* If 256 is not used, assign it to error, to follow POSIX.  */ 
 873   if (num_256_available_p
 
 874       && errtoken
->user_token_number 
== USER_NUMBER_UNDEFINED
) 
 875     errtoken
->user_token_number 
= 256; 
 877   /* Set the missing user numbers. */ 
 878   if (max_user_token_number 
< 256) 
 879     max_user_token_number 
= 256; 
 881   for (i 
= 0; i 
< ntokens
; ++i
) 
 883       symbol 
*this = symbols
[i
]; 
 884       if (this->user_token_number 
== USER_NUMBER_UNDEFINED
) 
 885         this->user_token_number 
= ++max_user_token_number
; 
 886       if (this->user_token_number 
> max_user_token_number
) 
 887         max_user_token_number 
= this->user_token_number
; 
 890   token_translations 
= xnmalloc (max_user_token_number 
+ 1, 
 891                                  sizeof *token_translations
); 
 893   /* Initialize all entries for literal tokens to the internal token 
 894      number for $undefined, which represents all invalid inputs.  */ 
 895   for (i 
= 0; i 
< max_user_token_number 
+ 1; i
++) 
 896     token_translations
[i
] = undeftoken
->number
; 
 897   symbols_do (symbol_translation_processor
, NULL
); 
 901 /*----------------------------------------------------------------. 
 902 | Assign symbol numbers, and write definition of token names into | 
 903 | FDEFINES.  Set up vectors SYMBOL_TABLE, TAGS of symbols.        | 
 904 `----------------------------------------------------------------*/ 
 909   symbols_do (symbol_check_alias_consistency_processor
, NULL
); 
 911   symbols 
= xcalloc (nsyms
, sizeof *symbols
); 
 912   symbols_do (symbol_pack_processor
, NULL
); 
 914   /* Aliases leave empty slots in symbols, so remove them.  */ 
 918     int nsyms_old 
= nsyms
; 
 919     for (writei 
= 0, readi 
= 0; readi 
< nsyms_old
; readi 
+= 1) 
 921         if (symbols
[readi
] == NULL
) 
 928             symbols
[writei
] = symbols
[readi
]; 
 929             symbols
[writei
]->number 
= writei
; 
 930             if (symbols
[writei
]->alias
) 
 931               symbols
[writei
]->alias
->number 
= writei
; 
 936   symbols 
= xnrealloc (symbols
, nsyms
, sizeof *symbols
); 
 938   symbols_token_translations_init (); 
 940   if (startsymbol
->class == unknown_sym
) 
 941     fatal_at (startsymbol_location
, 
 942               _("the start symbol %s is undefined"), 
 944   else if (startsymbol
->class == token_sym
) 
 945     fatal_at (startsymbol_location
, 
 946               _("the start symbol %s is a token"), 
 951 /*--------------------------------------------------. 
 952 | Set default tagged/tagless %destructor/%printer.  | 
 953 `--------------------------------------------------*/ 
 956 default_tagged_destructor_set (code_props 
const *destructor
) 
 958   if (default_tagged_destructor
.code
) 
 960       complain_at (destructor
->location
, 
 961                    _("redeclaration for default tagged %%destructor")); 
 962       complain_at (default_tagged_destructor
.location
, 
 963                    _("previous declaration")); 
 965   default_tagged_destructor 
= *destructor
; 
 969 default_tagless_destructor_set (code_props 
const *destructor
) 
 971   if (default_tagless_destructor
.code
) 
 973       complain_at (destructor
->location
, 
 974                    _("redeclaration for default tagless %%destructor")); 
 975       complain_at (default_tagless_destructor
.location
, 
 976                    _("previous declaration")); 
 978   default_tagless_destructor 
= *destructor
; 
 982 default_tagged_printer_set (code_props 
const *printer
) 
 984   if (default_tagged_printer
.code
) 
 986       complain_at (printer
->location
, 
 987                    _("redeclaration for default tagged %%printer")); 
 988       complain_at (default_tagged_printer
.location
, 
 989                    _("previous declaration")); 
 991   default_tagged_printer 
= *printer
; 
 995 default_tagless_printer_set (code_props 
const *printer
) 
 997   if (default_tagless_printer
.code
) 
 999       complain_at (printer
->location
, 
1000                    _("redeclaration for default tagless %%printer")); 
1001       complain_at (default_tagless_printer
.location
, 
1002                    _("previous declaration")); 
1004   default_tagless_printer 
= *printer
;