-/*----------------------------------------------------------------.
-| Read from finput until `%%' is seen. Discard the `%%'. Handle |
-| any `%' declarations, and copy the contents of any `%{ ... %}' |
-| groups to fattrs. |
-`----------------------------------------------------------------*/
-
-static void
-read_declarations (void)
-{
- int c;
- int tok;
-
- for (;;)
- {
- c = skip_white_space ();
-
- if (c == '%')
- {
- tok = parse_percent_token ();
-
- switch (tok)
- {
- case TWO_PERCENTS:
- return;
-
- case PERCENT_LEFT_CURLY:
- copy_definition ();
- break;
-
- case TOKEN:
- parse_token_decl (token_sym, nterm_sym);
- break;
-
- case NTERM:
- parse_token_decl (nterm_sym, token_sym);
- break;
-
- case TYPE:
- parse_type_decl ();
- break;
-
- case START:
- parse_start_decl ();
- break;
-
- case UNION:
- parse_union_decl ();
- break;
-
- case EXPECT:
- parse_expect_decl ();
- break;
- case THONG:
- parse_thong_decl ();
- break;
-
- case LEFT:
- parse_assoc_decl (left_assoc);
- break;
-
- case RIGHT:
- parse_assoc_decl (right_assoc);
- break;
-
- case NONASSOC:
- parse_assoc_decl (non_assoc);
- break;
-
- case SEMANTIC_PARSER:
- if (semantic_parser == 0)
- {
- semantic_parser = 1;
- open_extra_files ();
- }
- break;
-
- case PURE_PARSER:
- pure_parser = 1;
- break;
-
- case NOOP:
- break;
-
- default:
- complain (_("unrecognized: %s"), token_buffer);
- skip_to_char ('%');
- }
- }
- else if (c == EOF)
- fatal (_("no input grammar"));
- else
- {
- char buf[] = "c";
- buf[0] = c;
- complain (_("unknown character: %s"), quote (buf));
- skip_to_char ('%');
- }
- }
-}
-\f
-/*-------------------------------------------------------------------.
-| Assuming that a `{' has just been seen, copy everything up to the |
-| matching `}' into the actions file. 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 void
-copy_action (symbol_list * rule, int stack_offset)
-{
- int c;
- int n;
- int count;
- char *type_name;
-
- /* offset is always 0 if parser has already popped the stack pointer */
- if (semantic_parser)
- stack_offset = 0;
-
- fprintf (faction, "\ncase %d:\n", nrules);
- if (!no_lines_flag)
- fprintf (faction, "#line %d \"%s\"\n", lineno, infile);
- putc ('{', faction);
-
- count = 1;
- c = getc (finput);
-
- while (count > 0)
- {
- while (c != '}')
- {
- switch (c)
- {
- case '\n':
- putc (c, faction);
- lineno++;
- break;
-
- case '{':
- putc (c, faction);
- count++;
- break;
-
- case '\'':
- case '"':
- copy_string (finput, faction, c);
- break;
-
- case '/':
- putc (c, faction);
- c = getc (finput);
- if (c != '*' && c != '/')
- continue;
- copy_comment (finput, faction, c);
- break;
-
- case '$':
- c = getc (finput);
- type_name = NULL;
-
- if (c == '<')
- {
- char *cp = token_buffer;
-
- while ((c = getc (finput)) != '>' && c > 0)
- {
- if (cp == token_buffer + maxtoken)
- cp = grow_token_buffer (cp);
-
- *cp++ = c;
- }
- *cp = 0;
- type_name = token_buffer;
- value_components_used = 1;
-
- c = getc (finput);
- }
- if (c == '$')
- {
- fprintf (faction, "yyval");
- if (!type_name)
- type_name = get_type_name (0, rule);
- if (type_name)
- fprintf (faction, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$$ of `%s' has no declared type"),
- rule->sym->tag);
- }
- else if (isdigit (c) || c == '-')
- {
- ungetc (c, finput);
- n = read_signed_integer (finput);
- c = getc (finput);
-
- if (!type_name && n > 0)
- type_name = get_type_name (n, rule);
-
- fprintf (faction, "yyvsp[%d]", n - stack_offset);
- if (type_name)
- fprintf (faction, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$%d of `%s' has no declared type"),
- n, rule->sym->tag);
- continue;
- }
- else
- {
- char buf[] = "$c";
- buf[1] = c;
- complain (_("%s is invalid"), quote (buf));
- }
-
- break;
-
- case '@':
- copy_at (finput, faction, stack_offset);
- break;
-
- case EOF:
- fatal (_("unmatched %s"), "`{'");
-
- default:
- putc (c, faction);
- }
-
- c = getc (finput);
- }
-
- /* above loop exits when c is '}' */
-
- if (--count)
- {
- putc (c, faction);
- c = getc (finput);
- }
- }
-
- fprintf (faction, ";\n break;}");
-}
-\f
-/*-------------------------------------------------------------------.
-| After `%guard' is seen in the input file, copy the actual guard |
-| into the guards file. If the guard is followed by an action, copy |
-| that into the actions file. 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, for the simple parser in which |
-| the stack is not popped until after the guard is run. |
-`-------------------------------------------------------------------*/
-
-static void
-copy_guard (symbol_list * rule, int stack_offset)
-{
- int c;
- int n;
- int count;
- char *type_name;
- int brace_flag = 0;
-
- /* offset is always 0 if parser has already popped the stack pointer */
- if (semantic_parser)
- stack_offset = 0;
-
- fprintf (fguard, "\ncase %d:\n", nrules);
- if (!no_lines_flag)
- fprintf (fguard, "#line %d \"%s\"\n", lineno, infile);
- putc ('{', fguard);
-
- count = 0;
- c = getc (finput);
-
- while (brace_flag ? (count > 0) : (c != ';'))
- {
- switch (c)
- {
- case '\n':
- putc (c, fguard);
- lineno++;
- break;
-
- case '{':
- putc (c, fguard);
- brace_flag = 1;
- count++;
- break;
-
- case '}':
- putc (c, fguard);
- if (count > 0)
- count--;
- else
- {
- complain (_("unmatched %s"), "`}'");
- c = getc (finput); /* skip it */
- }
- break;
-
- case '\'':
- case '"':
- copy_string (finput, fguard, c);
- break;
-
- case '/':
- putc (c, fguard);
- c = getc (finput);
- if (c != '*' && c != '/')
- continue;
- copy_comment (finput, fguard, c);
- break;
-
- case '$':
- c = getc (finput);
- type_name = NULL;
-
- if (c == '<')
- {
- char *cp = token_buffer;
-
- while ((c = getc (finput)) != '>' && c > 0)
- {
- if (cp == token_buffer + maxtoken)
- cp = grow_token_buffer (cp);
-
- *cp++ = c;
- }
- *cp = 0;
- type_name = token_buffer;
-
- c = getc (finput);
- }
-
- if (c == '$')
- {
- fprintf (fguard, "yyval");
- if (!type_name)
- type_name = rule->sym->type_name;
- if (type_name)
- fprintf (fguard, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$$ of `%s' has no declared type"),
- rule->sym->tag);
- }
- else if (isdigit (c) || c == '-')
- {
- ungetc (c, finput);
- n = read_signed_integer (finput);
- c = getc (finput);
-
- if (!type_name && n > 0)
- type_name = get_type_name (n, rule);
-
- fprintf (fguard, "yyvsp[%d]", n - stack_offset);
- if (type_name)
- fprintf (fguard, ".%s", type_name);
- if (!type_name && typed)
- complain (_("$%d of `%s' has no declared type"),
- n, rule->sym->tag);
- continue;
- }
- else
- {
- char buf[] = "$c";
- buf[1] = c;
- complain (_("%s is invalid"), quote (buf));
- }
- break;
-
- case '@':
- copy_at (finput, fguard, stack_offset);
- break;
-
- case EOF:
- fatal ("%s", _("unterminated %guard clause"));
-
- default:
- putc (c, fguard);
- }
-
- if (c != '}' || count != 0)
- c = getc (finput);
- }
-
- c = skip_white_space ();
-
- fprintf (fguard, ";\n break;}");
- if (c == '{')
- copy_action (rule, stack_offset);
- else if (c == '=')
- {
- c = getc (finput); /* why not skip_white_space -wjh */
- if (c == '{')
- copy_action (rule, stack_offset);
- }
- else
- ungetc (c, finput);
-}
-\f
-
-static void
-record_rule_line (void)