Commit 6e204561 authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

2005-06-27 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>

	* monoburg.c (check_varname): Fix typo in yyerror call.
	* monoburg.c,
	* monoburg.h: Check the use of named rules with multiple rules.
	* parser.y: Call the named rules check with multiple rules.
parent be4e00aa
from Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
2005-06-27 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* monoburg.c (check_varname): Fix typo in yyerror call.
* monoburg.c,
* monoburg.h: Check the use of named rules with multiple rules.
* parser.y: Call the named rules check with multiple rules.
2005-06-27 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* parser.y: Add parsing of optional `name:' before a rule member.
* monoburg.h,
......
......@@ -101,18 +101,39 @@ create_rule (char *id, Tree *tree, char *code, char *cost, char *cfunc)
rule_add (rule, code, cost, cfunc);
}
void
static void
check_has_varname (Tree *t)
{
if (t->varname)
yyerror ("can't use named rules with multiple rules");
if (t->left)
check_has_varname (t->left);
if (t->right)
check_has_varname (t->right);
}
GList *
rule_list_prepend (GList *list, Rule *rule)
{
if (list && !list->next)
check_has_varname (((Rule *) list->data)->tree);
if (list)
check_has_varname (rule->tree);
return g_list_prepend (list, rule);
}
static void
check_varname (char *varname, Tree *t)
{
if (t->varname && !strcmp (varname, t->varname))
yyerror ("variable name `%s' redefined");
yyerror ("variable name `%s' redefined", varname);
if (t->left)
check_varname (varname, t->left);
if (t->right)
check_varname (varname, t->right);
}
void
static void
check_varnames (Tree *t_source, Tree *t_on)
{
if (t_source->varname)
......
......@@ -75,6 +75,8 @@ Term *create_term (char *id, int num);
void create_term_prefix (char *id);
GList *rule_list_prepend (GList *list, Rule *rule);
NonTerm *nonterm (char *id);
void start_nonterm (char *id);
......
......@@ -72,8 +72,8 @@ decls : /* empty */
rule : IDENT ':' tree { $$ = make_rule ($1, $3); }
;
rule_list : rule { $$ = g_list_append (NULL, $1); }
| rule ',' rule_list { $$ = g_list_prepend ($3, $1); }
rule_list : rule { $$ = rule_list_prepend (NULL, $1); }
| rule ',' rule_list { $$ = rule_list_prepend ($3, $1); }
;
optcode : /* empty */ { $$ = NULL; }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment