Provide functions to retrieve rules from Grammar
authorThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Sat, 17 Sep 2005 18:27:44 +0000 (18:27 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@dcc.ufmg.br>
Sat, 17 Sep 2005 18:27:44 +0000 (18:27 +0000)
Functions to retrieve rules for a symbol and symbols from a rule are
provided.

--This line, and those below, will be ignored--
Files to commit:
   <can't compute list>

This list might be incomplete or outdated if editing the log
message was not invoked from an up-to-date changes buffer!

git-archimport-id: cascardo@tlscascardo--private/libgrammatic--dev--0.1--patch-4

grammar.c
grammar.h

index 72248e0..9795468 100644 (file)
--- a/grammar.c
+++ b/grammar.c
@@ -124,6 +124,7 @@ rule_t* grammar_rule_new (Grammar* grammar, symbol_t* left)
                                     left, NULL, (gpointer*)&l))
     {
       l = g_malloc (sizeof (GList**));
+      *l = NULL;
       g_hash_table_insert (grammar->grammar, left, l);
     }
 
@@ -139,3 +140,19 @@ void grammar_rule_append (rule_t* rule, symbol_t* right)
 {
   rule_append (rule, right);
 }
+
+GList* grammar_get_rules (Grammar* grammar, symbol_t* left)
+{
+  GList** l;
+  if (!g_hash_table_lookup_extended (grammar->grammar,
+                                    left, NULL, (gpointer*)&l))
+    {
+      return NULL;
+    }
+  return g_list_first (*l);
+}
+
+GList* grammar_get_rule (rule_t* rule)
+{
+  return rule->right;
+}
index ee32492..81ec41d 100644 (file)
--- a/grammar.h
+++ b/grammar.h
@@ -42,5 +42,7 @@ symbol_t* symbol_new (gboolean, gint);
 
 rule_t* grammar_rule_new (Grammar*, symbol_t*);
 void grammar_rule_append (rule_t*, symbol_t*);
+GList* grammar_get_rules (Grammar*, symbol_t*);
+GList* grammar_get_rule (rule_t*);
 
 #endif