#include "conflicts.h"
#include "muscle_tab.h"
-/* Number of slots allocated (but not necessarily used yet) in `rline' */
-static int rline_allocated;
-
typedef struct symbol_list
{
struct symbol_list *next;
bucket *sym;
+ int line;
bucket *ruleprec;
}
symbol_list;
static bucket *errtoken;
static bucket *undeftoken;
+
+
+static symbol_list *
+symbol_list_new (bucket *sym)
+{
+ symbol_list *res = XMALLOC (symbol_list, 1);
+ res->next = NULL;
+ res->sym = sym;
+ res->line = lineno;
+ res->ruleprec = NULL;
+ return res;
+}
+
\f
/*===================\
`--------------------------------------------------------------*/
static char *
-get_type_name (int n, symbol_list * rule)
+get_type_name (int n, symbol_list *rule)
{
int i;
symbol_list *rp;
/* -1 while reading a character if prev char was %. */
int after_percent;
-#if 0
if (!no_lines_flag)
{
obstack_fgrow2 (&attrs_obstack, muscle_find ("linef"),
lineno, quotearg_style (c_quoting_style,
muscle_find("filename")));
}
-#endif
after_percent = 0;
else
{
complain (_("`%s' is invalid in %s"),
- token_buffer, (what_is == token_sym) ? "%token" : "%nterm");
+ token_buffer,
+ (what_is == token_sym) ? "%token" : "%nterm");
skip_to_char ('%');
}
}
int c;
int count = 0;
struct obstack union_obstack;
+ const char *prologue = "\
+#ifndef YYSTYPE\n\
+typedef union";
+ const char *epilogue = "\
+ yystype;\n\
+# define YYSTYPE yystype\n\
+#endif\n";
if (typed)
complain (_("multiple %s declarations"), "%union");
/* FIXME: I'm worried: are you sure attrs_obstack is properly
filled? */
+ /* I don't see any reasons to keep this line, because we should
+ create a special skeleton for this option. */
if (no_lines_flag)
obstack_1grow (&attrs_obstack, '\n');
obstack_init (&union_obstack);
obstack_sgrow (&union_obstack, "union");
if (defines_flag)
- obstack_sgrow (&defines_obstack, "typedef union");
+ obstack_sgrow (&defines_obstack, prologue);
c = getc (finput);
if (count <= 0)
{
if (defines_flag)
- obstack_sgrow (&defines_obstack, " YYSTYPE;\n");
+ obstack_sgrow (&defines_obstack, epilogue);
/* JF don't choke on trailing semi */
c = skip_white_space ();
if (c != ';')
}
+
+/*---------------------------------.
+| Parse a double quoted parameter. |
+`---------------------------------*/
+
+static const char *
+parse_dquoted_param (const char *from)
+{
+ struct obstack param_obstack;
+ const char *param = NULL;
+ int c;
+
+ obstack_init (¶m_obstack);
+ c = skip_white_space ();
+
+ if (c != '"')
+ {
+ complain (_("invalid %s declaration"), from);
+ ungetc (c, finput);
+ skip_to_char ('%');
+ return NULL;
+ }
+
+ for (;;)
+ {
+ if (literalchar (NULL, &c, '\"'))
+ obstack_1grow (¶m_obstack, c);
+ else
+ break;
+ }
+
+ obstack_1grow (¶m_obstack, '\0');
+ param = obstack_finish (¶m_obstack);
+
+ if (c != '"' || strlen (param) == 0)
+ {
+ complain (_("invalid %s declaration"), from);
+ if (c != '"')
+ ungetc (c, finput);
+ skip_to_char ('%');
+ return NULL;
+ }
+
+ return param;
+}
+
/*----------------------------------.
| Parse what comes after %skeleton. |
`----------------------------------*/
-void
+static void
parse_skel_decl (void)
{
- /* Complete with parse_dquoted_param () on the CVS branch 1.29. */
+ skeleton = parse_dquoted_param ("%skeleton");
}
/*----------------------------------------------------------------.
static void
read_declarations (void)
{
- int c;
- int tok;
-
for (;;)
{
- c = skip_white_space ();
+ int c = skip_white_space ();
if (c == '%')
{
- tok = parse_percent_token ();
+ token_t tok = parse_percent_token ();
switch (tok)
{
case tok_noop:
break;
+ case tok_stropt:
+ case tok_intopt:
+ case tok_obsolete:
+ abort ();
+ break;
+
+ case tok_illegal:
default:
complain (_("unrecognized: %s"), token_buffer);
skip_to_char ('%');
{
int c;
int count;
- char buf[4096];
/* offset is always 0 if parser has already popped the stack pointer */
if (semantic_parser)
}
\f
-static void
-record_rule_line (void)
-{
- /* Record each rule's source line number in rline table. */
-
- if (nrules >= rline_allocated)
- {
- rline_allocated = nrules * 2;
- rline = XREALLOC (rline, short, rline_allocated);
- }
- rline[nrules] = lineno;
-}
-
-
/*-------------------------------------------------------------------.
| Generate a dummy symbol, a nonterminal, whose name cannot conflict |
| with the user's names. |
nrules++;
nitems++;
- record_rule_line ();
-
- p = XCALLOC (symbol_list, 1);
- p->sym = lhs;
+ p = symbol_list_new (lhs);
crule1 = p1;
if (p1)
non-terminal. */
if (action_flag)
{
- bucket *sdummy;
-
/* Since the action was written out with this rule's
number, we must give the new rule this number by
inserting the new rule before it. */
/* Make a dummy nonterminal, a gensym. */
- sdummy = gensym ();
+ bucket *sdummy = gensym ();
- /* Make a new rule, whose body is empty,
- before the current one, so that the action
- just read can belong to it. */
+ /* Make a new rule, whose body is empty, before the
+ current one, so that the action just read can
+ belong to it. */
nrules++;
nitems++;
- record_rule_line ();
- p = XCALLOC (symbol_list, 1);
+ p = symbol_list_new (sdummy);
+ /* Attach its lineno to that of the host rule. */
+ p->line = crule->line;
if (crule1)
crule1->next = p;
else
grammar = p;
- p->sym = sdummy;
- crule1 = XCALLOC (symbol_list, 1);
- p->next = crule1;
+ /* End of the rule. */
+ crule1 = symbol_list_new (NULL);
crule1->next = crule;
+ p->next = crule1;
+
/* Insert the dummy generated by that rule into this
rule. */
nitems++;
- p = XCALLOC (symbol_list, 1);
- p->sym = sdummy;
+ p = symbol_list_new (sdummy);
p1->next = p;
p1 = p;
if (t == tok_identifier)
{
nitems++;
- p = XCALLOC (symbol_list, 1);
- p->sym = symval;
+ p = symbol_list_new (symval);
p1->next = p;
p1 = p;
}
} /* end of read rhs of rule */
/* Put an empty link in the list to mark the end of this rule */
- p = XCALLOC (symbol_list, 1);
+ p = symbol_list_new (NULL);
p1->next = p;
p1 = p;
error_token_number = errtoken->value;
+ 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;
+}
+
+
+/*-----------------------------------.
+| Output definition of token names. |
+`-----------------------------------*/
+
+static void
+symbols_output (void)
+{
{
struct obstack tokendefs;
obstack_init (&tokendefs);
obstack_free (&tokendefs, NULL);
}
-#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");
- }
-
+ obstack_fgrow1 (&defines_obstack, "\nextern YYSTYPE %slval;\n",
+ spec_name_prefix);
if (semantic_parser)
{
int i;
int ruleno;
symbol_list *p;
- bucket *ruleprec;
-
ritem = XCALLOC (short, nitems + 1);
- rlhs = XCALLOC (short, nrules) - 1;
- rrhs = XCALLOC (short, nrules) - 1;
- rprec = XCALLOC (short, nrules) - 1;
- rprecsym = XCALLOC (short, nrules) - 1;
- rassoc = XCALLOC (short, nrules) - 1;
+ rule_table = XCALLOC (rule_t, nrules) - 1;
itemno = 0;
ruleno = 1;
p = grammar;
while (p)
{
- rlhs[ruleno] = p->sym->value;
- rrhs[ruleno] = itemno;
- ruleprec = p->ruleprec;
+ bucket *ruleprec = p->ruleprec;
+ rule_table[ruleno].lhs = p->sym->value;
+ rule_table[ruleno].rhs = itemno;
+ rule_table[ruleno].line = p->line;
+ rule_table[ruleno].useful = TRUE;
p = p->next;
while (p && p->sym)
of the last token in it. */
if (p->sym->class == token_sym)
{
- rprec[ruleno] = p->sym->prec;
- rassoc[ruleno] = p->sym->assoc;
+ rule_table[ruleno].prec = p->sym->prec;
+ rule_table[ruleno].assoc = p->sym->assoc;
}
if (p)
p = p->next;
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
- rprec[ruleno] = ruleprec->prec;
- rassoc[ruleno] = ruleprec->assoc;
- rprecsym[ruleno] = ruleprec->value;
+ rule_table[ruleno].prec = ruleprec->prec;
+ rule_table[ruleno].assoc = ruleprec->assoc;
+ rule_table[ruleno].precsym = ruleprec->value;
}
ritem[itemno++] = -ruleno;
}
ritem[itemno] = 0;
+
+ if (trace_flag)
+ ritem_print (stderr);
}
\f
/*-------------------------------------------------------------------.
nvars = 0;
nrules = 0;
nitems = 0;
- rline_allocated = 10;
- rline = XCALLOC (short, rline_allocated);
typed = 0;
lastprec = 0;
packsymbols ();
/* Convert the grammar into the format described in gram.h. */
packgram ();
+ /* Output the headers. */
+ symbols_output ();
}