Generates LR(1) table from Items
[cascardo/grammar.git] / first.c
diff --git a/first.c b/first.c
index cd3f524..da7d344 100644 (file)
--- a/first.c
+++ b/first.c
@@ -376,10 +376,16 @@ void first_iterate (gpointer key, gpointer val, gpointer data)
                            {
                              symbol_t* next_symbol;
                              next_symbol = next_symbols->data;
-                             /* TODO: Check this assertion is correct. */
-                             assert (next_symbol->terminal == FALSE);
+                             /*
+                              * 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,
@@ -457,7 +463,7 @@ void first_check (gpointer key, gpointer val, gpointer data)
  * We should iterate through the rules for each nonterminal until only
  * terminals are known to be in the first set of it.
  */
-GHashTable* grammar_first (Grammar* grammar)
+GHashTable* grammar_first (grammar_t* grammar)
 {
   GHashTable* first;
   gboolean stop;
@@ -474,7 +480,7 @@ GHashTable* grammar_first (Grammar* grammar)
   return first;
 }
 
-void put_key_on_list (gpointer key, gpointer val, gpointer data)
+static void put_key_on_list (gpointer key, gpointer val, gpointer data)
 {
   GList** l;
   l = (GList**) data;