- c = getc (fin);
- if (c == '$')
- {
- obstack_sgrow (oout, "yyloc");
- locations_flag = 1;
- }
- else if (isdigit (c) || c == '-')
- {
- int n;
-
- ungetc (c, fin);
- n = read_signed_integer (fin);
-
- obstack_fgrow1 (oout, "yylsp[%d]", n - stack_offset);
- locations_flag = 1;
- }
- else
- {
- char buf[] = "@c";
- buf[1] = c;
- complain (_("%s is invalid"), quote (buf));
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| FIN is pointing to a wannabee semantic value (i.e., a `$'). |
-| |
-| Possible inputs: $[<TYPENAME>]($|integer) |
-| |
-| Output to OOUT a reference to this semantic value. STACK_OFFSET is |
-| the number of values in the current rule so far, which says where |
-| to find `$0' with respect to the top of the stack. |
-`-------------------------------------------------------------------*/
-
-static inline void
-copy_dollar (FILE *fin, struct obstack *oout,
- symbol_list *rule, int stack_offset)
-{
- int c = getc (fin);
- const char *type_name = NULL;
-
- /* Get the type name if explicit. */
- if (c == '<')
- {
- read_type_name (fin);
- type_name = token_buffer;
- value_components_used = 1;
- c = getc (fin);
- }
-
- if (c == '$')
- {
- obstack_sgrow (oout, "yyval");
-
- if (!type_name)
- type_name = get_type_name (0, rule);
- if (type_name)
- obstack_fgrow1 (oout, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$$ of `%s' has no declared type"),
- rule->sym->tag);
- }
- else if (isdigit (c) || c == '-')
- {
- int n;
- ungetc (c, fin);
- n = read_signed_integer (fin);
-
- if (!type_name && n > 0)
- type_name = get_type_name (n, rule);
-
- obstack_fgrow1 (oout, "yyvsp[%d]", n - stack_offset);
-
- if (type_name)
- obstack_fgrow1 (oout, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$%d of `%s' has no declared type"),
- n, rule->sym->tag);
- }
- else
- {
- char buf[] = "$c";
- buf[1] = c;
- complain (_("%s is invalid"), quote (buf));
- }
-}
-\f
-/*-------------------------------------------------------------------.
-| Copy the contents of a `%{ ... %}' into the definitions file. The |
-| `%{' has already been read. Return after reading the `%}'. |
-`-------------------------------------------------------------------*/
-
-static void
-copy_definition (void)
-{
- int c;
- /* -1 while reading a character if prev char was %. */
- int after_percent;
-
- if (!no_lines_flag)
- {
- obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"),
- lineno, quotearg_style (c_quoting_style,
- muscle_find("filename")));
- }
-
- after_percent = 0;
-
- c = getc (finput);
-
- for (;;)
- {
- switch (c)
- {
- case '\n':
- obstack_1grow (&attrs_obstack, c);
- lineno++;
- break;
-
- case '%':
- after_percent = -1;
- break;
-
- case '\'':
- case '"':
- copy_string (finput, &attrs_obstack, c);
- break;
-
- case '/':
- copy_comment (finput, &attrs_obstack);
- break;
-
- case EOF:
- fatal ("%s", _("unterminated `%{' definition"));
-
- default:
- obstack_1grow (&attrs_obstack, c);
- }
-
- c = getc (finput);
-
- if (after_percent)
- {
- if (c == '}')
- return;
- obstack_1grow (&attrs_obstack, '%');
- }
- after_percent = 0;
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| Parse what comes after %token or %nterm. For %token, WHAT_IS is |
-| token_sym and WHAT_IS_NOT is nterm_sym. For %nterm, the arguments |
-| are reversed. |
-`-------------------------------------------------------------------*/
-
-static void
-parse_token_decl (symbol_class what_is, symbol_class what_is_not)
-{
- token_t token = tok_undef;
- char *typename = NULL;
-
- /* The symbol being defined. */
- struct bucket *symbol = NULL;
-
- /* After `%token' and `%nterm', any number of symbols maybe be
- defined. */
- for (;;)
- {
- int tmp_char = ungetc (skip_white_space (), finput);
-
- /* `%' (for instance from `%token', or from `%%' etc.) is the
- only valid means to end this declaration. */
- if (tmp_char == '%')
- return;
- if (tmp_char == EOF)
- fatal (_("Premature EOF after %s"), token_buffer);
-
- token = lex ();
- if (token == tok_comma)
- {
- symbol = NULL;
- continue;
- }
- if (token == tok_typename)
- {
- typename = xstrdup (token_buffer);
- value_components_used = 1;
- symbol = NULL;
- }
- else if (token == tok_identifier && *symval->tag == '\"' && symbol)
- {
- if (symval->alias)
- warn (_("symbol `%s' used more than once as a literal string"),
- symval->tag);
- else if (symbol->alias)
- warn (_("symbol `%s' given more than one literal string"),
- symbol->tag);
- else
- {
- symval->class = token_sym;
- symval->type_name = typename;
- symval->user_token_number = symbol->user_token_number;
- symbol->user_token_number = SALIAS;
- symval->alias = symbol;
- symbol->alias = symval;
- /* symbol and symval combined are only one symbol */
- nsyms--;
- }
- symbol = NULL;
- }
- else if (token == tok_identifier)
- {
- int oldclass = symval->class;
- symbol = symval;
-
- if (symbol->class == what_is_not)
- complain (_("symbol %s redefined"), symbol->tag);
- symbol->class = what_is;
- if (what_is == nterm_sym && oldclass != nterm_sym)
- symbol->value = nvars++;
-
- if (typename)
- {
- if (symbol->type_name == NULL)
- symbol->type_name = typename;
- else if (strcmp (typename, symbol->type_name) != 0)
- complain (_("type redeclaration for %s"), symbol->tag);
- }
- }
- else if (symbol && token == tok_number)
- {
- symbol->user_token_number = numval;
- }
- else
- {
- complain (_("`%s' is invalid in %s"),
- token_buffer,
- (what_is == token_sym) ? "%token" : "%nterm");
- skip_to_char ('%');
- }
- }
-
-}
-
-
-/*------------------------------.
-| Parse what comes after %start |
-`------------------------------*/
-
-static void
-parse_start_decl (void)