fd69f0086b4380ea26fce834649bfa81cce379cc
[cascardo/grammar.git] / dfa_gen.c
1 /*
2  * Copyright 2005 Thadeu Lima de Souza Cascardo
3  *
4  * libgrammatic
5  *
6  * Translate a grammar to a DFA table, if it is possible, i.e., it's a
7  * regular grammar and has no non-determinism.
8  *
9  */
10
11 #include <grammar.h>
12 #include <dfa.h>
13
14 void dfa_gen_add (gpointer key, gpointer val, gpointer data)
15 {
16
17   symbol_t* left;
18   rule_t* right;
19   dfa_t* dfa;
20   GList* l;
21
22   left = (symbol_t*) key;
23   right = (rule_t*) val;
24   dfa = (dfa_t*) data;
25
26 }
27
28 dfa_t* dfa_gen (grammar_t* grammar, symbol_t* start, nextcb cb, gpointer data)
29 {
30
31   dfa_t* dfa;
32
33   dfa = dfa_new (cb, data, dfa_state_new (start->value, FALSE));
34
35   g_hash_table_foreach (grammar->grammar, dfa_gen_add, dfa);
36
37   return dfa;
38
39 }