- register bucket *bp;
- register int tokno = 1;
- register int i;
- register int last_user_token_number;
- static char DOLLAR[] = "$";
-
- /* int lossage = 0; JF set but not used */
-
- tags = NEW2(nsyms + 1, char *);
- tags[0] = DOLLAR;
- user_toknums = NEW2(nsyms + 1, int);
- user_toknums[0] = 0;
-
- sprec = NEW2(nsyms, short);
- sassoc = NEW2(nsyms, short);
-
- max_user_token_number = 256;
- last_user_token_number = 256;
-
- for (bp = firstsymbol; bp; bp = bp->next)
- {
- if (bp->class == SNTERM)
- {
- 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 == STOKEN */
- {
- bp->value = tokno++;
- }
-
- if (bp->class == STOKEN)
- {
- 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)
- {
- register int j;
-
- token_translations = NEW2(max_user_token_number+1, short);
-
- /* 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;
-
- if (! noparserflag)
- output_token_defines(ftable);
-
- if (startval->class == SUNKNOWN)
- fatal (_("the start symbol %s is undefined"), startval->tag);
- else if (startval->class == STOKEN)
- fatal (_("the start symbol %s is a token"), startval->tag);
-
- start_symbol = startval->value;
-
- if (definesflag)
- {
- output_token_defines(fdefines);
-
- if (!pure_parser)
- {
- if (spec_name_prefix)
- fprintf(fdefines, "\nextern YYSTYPE %slval;\n", spec_name_prefix);
- else
- fprintf(fdefines, "\nextern YYSTYPE yylval;\n");
- }