From: Thadeu Lima de Souza Cascardo Date: Thu, 27 Oct 2005 00:28:14 +0000 (+0000) Subject: Fixed first X-Git-Tag: cascardo@tlscascardo--private,libgrammatic--regular--0.1--base-0~1 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fgrammar.git;a=commitdiff_plain;h=aa906f5400c41bc101734eea0e7cbce0f64b2273 Fixed first Previous fix in first was not correct because it used a variable not yet declared. This version checks for the rule starting with a terminal instead of ignoring them. git-archimport-id: cascardo@tlscascardo--private/libgrammatic--nogobject-lr1--0.1--patch-11 --- diff --git a/first.c b/first.c index 0b25ecb..da7d344 100644 --- a/first.c +++ b/first.c @@ -372,12 +372,20 @@ void first_iterate (gpointer key, gpointer val, gpointer data) first_set->has_empty = TRUE; rule_delete (next_rule); } - else if (next_symbol->terminal == FALSE) + else { symbol_t* next_symbol; next_symbol = next_symbols->data; + /* + * This rule starts with a terminal. Ignore it. + * We could add it as an optimization. TODO + */ + if (next_symbol->terminal) + { + rule_delete (next_rule); + } /* This is an indirect recursive rule. */ - if (next_symbol->value == symbol->value) + else if (next_symbol->value == symbol->value) { first_set->recursive = g_list_prepend (first_set->recursive, @@ -390,10 +398,6 @@ void first_iterate (gpointer key, gpointer val, gpointer data) new_rules = g_list_prepend (new_rules, next_rule); } } - else - { - rule_delete (next_rule); - } next_rules = g_list_next (next_rules); } }