+2002-06-17 Akim Demaille <akim@epita.fr>
+
+ * src/symlist.h, src/symlist.c (symbol_list_length): New.
+ * src/scan-gram.l (handle_dollar, handle_at): Compute the
+ rule_length only when needed.
+ * src/output.c (actions_output, token_definitions_output): Output
+ the full M4 block.
+ * src/symtab.c: Don't access directly to the symbol tag, use
+ symbol_tag_get.
+ * src/parse-gram.y: Use symbol_list_free.
+
+
2002-06-17 Akim Demaille <akim@epita.fr>
* src/reader.h, src/reader.c (symbol_list, symbol_list_new)
actions_output (FILE *out)
{
int rule;
+
+ fputs ("m4_define([b4_actions], \n[[", out);
for (rule = 1; rule < nrules + 1; ++rule)
if (rules[rule].action)
{
fprintf (out, " %s\n break;\n\n",
rules[rule].action);
}
+ fputs ("]])\n\n", out);
}
{
int i;
int first = 1;
+
+ fputs ("m4_define([b4_tokens], \n[", out);
for (i = 0; i < ntokens; ++i)
{
symbol_t *symbol = symbols[i];
first = 0;
}
+ fputs ("])\n\n", out);
}
fputs ("m4_changecom()\n", out);
fputs ("m4_init()\n", out);
- fputs ("m4_define([b4_actions], \n[[", out);
actions_output (out);
- fputs ("]])\n\n", out);
-
- fputs ("m4_define([b4_tokens], \n[", out);
token_definitions_output (out);
- fputs ("])\n\n", out);
muscles_m4_output (out);
symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next)
symbol_type_set (list->sym, list->location, yyvsp[-1].string);
- LIST_FREE (symbol_list_t, yyvsp[0].list);
+ symbol_list_free (yyvsp[0].list);
}
break;
symbol_type_set (list->sym, list->location, current_type);
symbol_precedence_set (list->sym, list->location, current_prec, yyvsp[-2].assoc);
}
- LIST_FREE (symbol_list_t, yyvsp[0].list);
+ symbol_list_free (yyvsp[0].list);
current_type = NULL;
}
break;
symbol_list_t *list;
for (list = $3; list; list = list->next)
symbol_type_set (list->sym, list->location, $2);
- LIST_FREE (symbol_list_t, $3);
+ symbol_list_free ($3);
}
;
symbol_type_set (list->sym, list->location, current_type);
symbol_precedence_set (list->sym, list->location, current_prec, $1);
}
- LIST_FREE (symbol_list_t, $3);
+ symbol_list_free ($3);
current_type = NULL;
}
;
{
const char *type_name = NULL;
- /* RULE_LENGTH 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. It is not the same as the rule->length in the case of mid
- rule actions. */
- int rule_length = 0;
- symbol_list_t *rhs;
- for (rhs = current_rule->next; rhs; rhs = rhs->next)
- ++rule_length;
-
++cp;
/* Get the type name if explicit. */
}
else if (isdigit (*cp) || *cp == '-')
{
+ /* RULE_LENGTH 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. It is not the same as the rule->length in the
+ case of mid rule actions. */
+ int rule_length = symbol_list_length (current_rule->next);
int n = strtol (cp, &cp, 10);
if (n > rule_length)
static void
handle_at (char *cp)
{
- /* RULE_LENGTH 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. It is not the same as the rule->length in the case of mid
- rule actions. */
- int rule_length = 0;
- symbol_list_t *rhs;
- for (rhs = current_rule->next; rhs; rhs = rhs->next)
- ++rule_length;
-
locations_flag = 1;
++cp;
}
else if (isdigit (*cp) || *cp == '-')
{
+ /* RULE_LENGTH 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. It is not the same as the rule->length in the
+ case of mid rule actions. */
+ int rule_length = symbol_list_length (current_rule->next);
int n = strtol (cp, &cp, 10);
+
if (n > rule_length)
complain (_("invalid value: %s%d"), "@", n);
else
{
const char *type_name = NULL;
- /* RULE_LENGTH 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. It is not the same as the rule->length in the case of mid
- rule actions. */
- int rule_length = 0;
- symbol_list_t *rhs;
- for (rhs = current_rule->next; rhs; rhs = rhs->next)
- ++rule_length;
-
++cp;
/* Get the type name if explicit. */
}
else if (isdigit (*cp) || *cp == '-')
{
+ /* RULE_LENGTH 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. It is not the same as the rule->length in the
+ case of mid rule actions. */
+ int rule_length = symbol_list_length (current_rule->next);
int n = strtol (cp, &cp, 10);
if (n > rule_length)
static void
handle_at (char *cp)
{
- /* RULE_LENGTH 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. It is not the same as the rule->length in the case of mid
- rule actions. */
- int rule_length = 0;
- symbol_list_t *rhs;
- for (rhs = current_rule->next; rhs; rhs = rhs->next)
- ++rule_length;
-
locations_flag = 1;
++cp;
}
else if (isdigit (*cp) || *cp == '-')
{
+ /* RULE_LENGTH 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. It is not the same as the rule->length in the
+ case of mid rule actions. */
+ int rule_length = symbol_list_length (current_rule->next);
int n = strtol (cp, &cp, 10);
+
if (n > rule_length)
complain (_("invalid value: %s%d"), "@", n);
else
}
+/*--------------------.
+| Return its length. |
+`--------------------*/
+
+unsigned int
+symbol_list_length (symbol_list_t *list)
+{
+ int res = 0;
+ for (/* Nothing. */; list; list = list->next)
+ ++res;
+ return res;
+}
+
+
/*--------------------------------------------------------------.
| Get the data type (alternative in the union) of the value for |
| symbol N in rule RULE. |
/* Free the LIST, but not the symbols it contains. */
void symbol_list_free PARAMS ((symbol_list_t *list));
+/* Return its length. */
+unsigned int symbol_list_length PARAMS ((symbol_list_t *list));
/* Get the data type (alternative in the union) of the value for
symbol N in rule RULE. */
{
if (symbol->type_name)
complain_at (location,
- _("type redeclaration for %s"), symbol->tag);
+ _("type redeclaration for %s"), symbol_tag_get (symbol));
symbol->type_name = type_name;
}
}
{
if (symbol->prec != 0)
complain_at (location,
- _("redefining precedence of %s"), symbol->tag);
+ _("redefining precedence of %s"),
+ symbol_tag_get (symbol));
symbol->prec = prec;
symbol->assoc = assoc;
}
symbol_class_set (symbol_t *symbol, symbol_class class)
{
if (symbol->class != unknown_sym && symbol->class != class)
- complain (_("symbol %s redefined"), symbol->tag);
+ complain (_("symbol %s redefined"), symbol_tag_get (symbol));
if (class == nterm_sym && symbol->class != nterm_sym)
symbol->number = nvars++;
if (symbol->user_token_number != USER_NUMBER_UNDEFINED
&& symbol->user_token_number != user_token_number)
- complain (_("redefining user token number of %s"), symbol->tag);
+ complain (_("redefining user token number of %s"),
+ symbol_tag_get (symbol));
symbol->user_token_number = user_token_number;
/* User defined EOF token? */
complain_at
(this->location,
_("symbol %s is used, but is not defined as a token and has no rules"),
- this->tag);
+ symbol_tag_get (this));
this->class = nterm_sym;
this->number = nvars++;
}
{
if (symval->alias)
warn (_("symbol `%s' used more than once as a literal string"),
- symval->tag);
+ symbol_tag_get (symval));
else if (symbol->alias)
warn (_("symbol `%s' given more than one literal string"),
- symbol->tag);
+ symbol_tag_get (symbol));
else
{
symval->class = token_sym;
{
if (this->prec != 0 && this->alias->prec != 0)
complain (_("conflicting precedences for %s and %s"),
- this->tag, this->alias->tag);
+ symbol_tag_get (this), symbol_tag_get (this->alias));
if (this->prec != 0)
this->alias->prec = this->prec;
else
if (this->assoc != right_assoc
&& this->alias->assoc != right_assoc)
complain (_("conflicting associativities for %s and %s"),
- this->tag, this->alias->tag);
+ symbol_tag_get (this), symbol_tag_get (this->alias));
if (this->assoc != 0)
this->alias->assoc = this->assoc;
else
/* A token which translation has already been set? */
if (token_translations[this->user_token_number] != undeftoken->number)
complain (_("tokens %s and %s both assigned number %d"),
- symbols[token_translations[this->user_token_number]]->tag,
- this->tag, this->user_token_number);
+ symbol_tag_get (symbols[token_translations[this->user_token_number]]),
+ symbol_tag_get (this), this->user_token_number);
token_translations[this->user_token_number] = this->number;
}
if (startsymbol->class == unknown_sym)
fatal_at (startsymbol_location,
- _("the start symbol %s is undefined"), startsymbol->tag);
+ _("the start symbol %s is undefined"),
+ symbol_tag_get (startsymbol));
else if (startsymbol->class == token_sym)
fatal_at (startsymbol_location,
- _("the start symbol %s is a token"), startsymbol->tag);
+ _("the start symbol %s is a token"),
+ symbol_tag_get (startsymbol));
}