Fixed first
authorThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 27 Oct 2005 00:28:14 +0000 (00:28 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 27 Oct 2005 00:28:14 +0000 (00:28 +0000)
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

first.c

diff --git a/first.c b/first.c
index 0b25ecb..da7d344 100644 (file)
--- 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);
                            }
                              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;
                            {
                              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. */
                              /* 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,
                                {
                                  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);
                                }
                            }
                                  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);
                        }
                    }