Added GPLv2+ as license for libgrammatic
[cascardo/grammar.git] / dfa_gen.c
1 /*
2  *  Copyright (C) 2005  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19
20
21 /*
22  * Copyright 2005 Thadeu Lima de Souza Cascardo
23  *
24  * libgrammatic
25  *
26  * Translate a grammar to a DFA table, if it is possible, i.e., it's a
27  * regular grammar and has no non-determinism.
28  *
29  */
30
31 #include <grammar.h>
32 #include <dfa.h>
33
34 void dfa_gen_add (gpointer key, gpointer val, gpointer data)
35 {
36
37   symbol_t* left;
38   rule_t* right;
39   dfa_t* dfa;
40   GList* l;
41
42   left = (symbol_t*) key;
43   right = (rule_t*) val;
44   dfa = (dfa_t*) data;
45
46 }
47
48 dfa_t* dfa_gen (grammar_t* grammar, symbol_t* start, nextcb cb, gpointer data)
49 {
50
51   dfa_t* dfa;
52
53   dfa = dfa_new (cb, data, dfa_state_new (start->value, FALSE));
54
55   g_hash_table_foreach (grammar->grammar, dfa_gen_add, dfa);
56
57   return dfa;
58
59 }