-/*--------------------------------------------------------------.
-| For named tokens, but not literal ones, define the name. The |
-| value is the user token number. |
-`--------------------------------------------------------------*/
-
-static void
-output_token_defines (struct obstack *oout)
-{
- bucket *bp;
- char *cp, *symbol;
- char c;
-
- for (bp = firstsymbol; bp; bp = bp->next)
- {
- symbol = bp->tag; /* get symbol */
-
- if (bp->value >= ntokens)
- continue;
- if (bp->user_token_number == SALIAS)
- continue;
- if ('\'' == *symbol)
- continue; /* skip literal character */
- if (bp == errtoken)
- continue; /* skip error token */
- if ('\"' == *symbol)
- {
- /* use literal string only if given a symbol with an alias */
- if (bp->alias)
- symbol = bp->alias->tag;
- else
- continue;
- }
-
- /* Don't #define nonliteral tokens whose names contain periods. */
- cp = symbol;
- while ((c = *cp++) && c != '.');
- if (c != '\0')
- continue;
-
- obstack_fgrow2 (oout, "# define\t%s\t%d\n",
- symbol,
- (translations ? bp->user_token_number : bp->value));
- if (semantic_parser)
- obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
- }
-}
-
-
-/*------------------------------------------------------------------.
-| Assign symbol numbers, and write definition of token names into |
-| FDEFINES. Set up vectors TAGS and SPREC of names and precedences |
-| of symbols. |
-`------------------------------------------------------------------*/
-
-static void
-packsymbols (void)
-{
- bucket *bp;
- int tokno = 1;
- int i;
- int last_user_token_number;
- static char DOLLAR[] = "$";
-
- tags = XCALLOC (char *, nsyms + 1);
- tags[0] = DOLLAR;
- user_toknums = XCALLOC (short, nsyms + 1);
- user_toknums[0] = 0;
-
- sprec = XCALLOC (short, nsyms);
- sassoc = XCALLOC (short, nsyms);
-
- max_user_token_number = 256;
- last_user_token_number = 256;
-
- for (bp = firstsymbol; bp; bp = bp->next)
- {
- if (bp->class == nterm_sym)
- {
- bp->value += ntokens;
- }
- else if (bp->alias)
- {
- /* this symbol and its alias are a single token defn.
- allocate a tokno, and assign to both check agreement of
- ->prec and ->assoc fields and make both the same */
- if (bp->value == 0)
- bp->value = bp->alias->value = tokno++;
-
- if (bp->prec != bp->alias->prec)
- {
- if (bp->prec != 0 && bp->alias->prec != 0
- && bp->user_token_number == SALIAS)
- complain (_("conflicting precedences for %s and %s"),
- bp->tag, bp->alias->tag);
- if (bp->prec != 0)
- bp->alias->prec = bp->prec;
- else
- bp->prec = bp->alias->prec;
- }
-
- if (bp->assoc != bp->alias->assoc)
- {
- if (bp->assoc != 0 && bp->alias->assoc != 0
- && bp->user_token_number == SALIAS)
- complain (_("conflicting assoc values for %s and %s"),
- bp->tag, bp->alias->tag);
- if (bp->assoc != 0)
- bp->alias->assoc = bp->assoc;
- else
- bp->assoc = bp->alias->assoc;
- }
-
- if (bp->user_token_number == SALIAS)
- continue; /* do not do processing below for SALIASs */
-
- }
- else /* bp->class == token_sym */
- {
- bp->value = tokno++;
- }
-
- if (bp->class == token_sym)
- {
- if (translations && !(bp->user_token_number))
- 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;
- }
-
- tags[bp->value] = bp->tag;
- user_toknums[bp->value] = bp->user_token_number;
- sprec[bp->value] = bp->prec;
- sassoc[bp->value] = bp->assoc;
-
- }
-
- if (translations)
- {
- int j;
-
- token_translations = XCALLOC (short, max_user_token_number + 1);
-
- /* initialize all entries for literal tokens to 2, the internal
- token number for $undefined., which represents all invalid
- inputs. */
- for (j = 0; j <= max_user_token_number; j++)
- token_translations[j] = 2;
-
- for (bp = firstsymbol; bp; bp = bp->next)
- {
- if (bp->value >= ntokens)
- continue; /* non-terminal */
- if (bp->user_token_number == SALIAS)
- continue;
- if (token_translations[bp->user_token_number] != 2)
- complain (_("tokens %s and %s both assigned number %d"),
- tags[token_translations[bp->user_token_number]],
- bp->tag, bp->user_token_number);
- token_translations[bp->user_token_number] = bp->value;
- }
- }
-
- error_token_number = errtoken->value;
-
- output_token_defines (&output_obstack);
- obstack_1grow (&output_obstack, 0);
- muscle_insert ("tokendef", obstack_finish (&output_obstack));
-
-#if 0
- if (!no_parser_flag)
- output_token_defines (&table_obstack);
-#endif
-
- if (startval->class == unknown_sym)
- fatal (_("the start symbol %s is undefined"), startval->tag);
- else if (startval->class == token_sym)
- fatal (_("the start symbol %s is a token"), startval->tag);
-
- start_symbol = startval->value;
-
- if (defines_flag)
- {
- output_token_defines (&defines_obstack);
-
- if (!pure_parser)
- {
- if (spec_name_prefix)
- obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n",
- spec_name_prefix);
- else
- obstack_sgrow (&defines_obstack,
- "\nextern YYSTYPE yylval;\n");
- }
-
- if (semantic_parser)
- for (i = ntokens; i < nsyms; i++)
- {
- /* don't make these for dummy nonterminals made by gensym. */
- if (*tags[i] != '@')
- obstack_fgrow2 (&defines_obstack,
- "# define\tNT%s\t%d\n", tags[i], i);
- }
-#if 0
- /* `fdefines' is now a temporary file, so we need to copy its
- contents in `done', so we can't close it here. */
- fclose (fdefines);
- fdefines = NULL;
-#endif
- }
-}
-
-