Debug for LR(1) parser cascardo@tlscascardo--private,libgrammatic--regular--0.1--base-0
authorThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 10 Nov 2005 17:36:09 +0000 (17:36 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Thu, 10 Nov 2005 17:36:09 +0000 (17:36 +0000)
Inserted debug code for LR(1) parser.

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

lr1.c

diff --git a/lr1.c b/lr1.c
index 2124bb1..afbc9e0 100644 (file)
--- a/lr1.c
+++ b/lr1.c
@@ -1,6 +1,9 @@
 #include <grammar.h>
 #include <stdlib.h>
 #include <lr1.h>
+#ifdef DEBUG
+#include <stdio.h>
+#endif
 
 enum { PARSER_SHIFT, PARSER_REDUCE, PARSER_ACCEPT };
 
@@ -216,9 +219,17 @@ gpointer lr1_build (lr1_t* parser)
       if (!lr1_lookup (parser, state->state, symbol, &transition))
        return NULL;
 
+#ifdef DEBUG
+         printf ("State: %x, Symbol: %s\n", state->state,
+                 g_quark_to_string (symbol->value));
+#endif
+
       if (transition->action == PARSER_SHIFT)
        {
          gint st;
+#ifdef DEBUG
+         printf ("SHIFT: %x\n", transition->state);
+#endif
          lr1_push (parser, transition->state, leaf_new (attrib));
          symbol->value = parser->cb (parser->data, &attrib);
          symbol->terminal = TRUE;
@@ -246,13 +257,26 @@ gpointer lr1_build (lr1_t* parser)
 
          l = g_list_first (parser->stack);
          state = (state_t*) l->data;
+
+#ifdef DEBUG
+         printf ("REDUCE: back to %x, ", state->state);
+#endif
+
          lr1_lookup (parser, state->state, transition->left, &trans);
+
+#ifdef DEBUG
+         printf ("%x\n", trans->state);
+#endif
+
          lr1_push (parser, trans->state, attrib);
 
        }
 
       else if (transition->action == PARSER_ACCEPT)
        {
+#ifdef DEBUG
+         printf ("ACCEPT\n");
+#endif
          l = g_list_first (parser->stack);
          state = (state_t*) l->data;
          return state->attrib;