Fixed assertion in first
authorThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 27 Oct 2005 00:00:36 +0000 (00:00 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 27 Oct 2005 00:00:36 +0000 (00:00 +0000)
The implementation assumed there would be no rules starting with
terminals since they were eliminated at the first chance. However, rules
starting with a non-terminal which produced the empty string followed by
a terminal were added to the set of rules.

git-archimport-id: cascardo@tlscascardo--private/libgrammatic--nogobject-lr1--0.1--patch-10

first.c

diff --git a/first.c b/first.c
index 040a04c..0b25ecb 100644 (file)
--- a/first.c
+++ b/first.c
@@ -372,12 +372,10 @@ void first_iterate (gpointer key, gpointer val, gpointer data)
                              first_set->has_empty = TRUE;
                              rule_delete (next_rule);
                            }
                              first_set->has_empty = TRUE;
                              rule_delete (next_rule);
                            }
-                         else
+                         else if (next_symbol->terminal == FALSE)
                            {
                              symbol_t* next_symbol;
                              next_symbol = next_symbols->data;
                            {
                              symbol_t* next_symbol;
                              next_symbol = next_symbols->data;
-                             /* TODO: Check this assertion is correct. */
-                             assert (next_symbol->terminal == FALSE);
                              /* This is an indirect recursive rule. */
                              if (next_symbol->value == symbol->value)
                                {
                              /* This is an indirect recursive rule. */
                              if (next_symbol->value == symbol->value)
                                {
@@ -392,6 +390,10 @@ void first_iterate (gpointer key, gpointer val, gpointer data)
                                  new_rules = g_list_prepend (new_rules, next_rule);
                                }
                            }
                                  new_rules = g_list_prepend (new_rules, next_rule);
                                }
                            }
+                         else
+                           {
+                             rule_delete (next_rule);
+                           }
                          next_rules = g_list_next (next_rules);
                        }
                    }
                          next_rules = g_list_next (next_rules);
                        }
                    }