SphinxBase  0.6
jsgf_internal.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2007 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 
38 #ifndef __JSGF_INTERNAL_H__
39 #define __JSGF_INTERNAL_H__
40 
45 #define YY_NO_UNISTD_H 1
46 #include <stdio.h>
47 
48 #include <sphinxbase/hash_table.h>
49 #include <sphinxbase/glist.h>
50 #include <sphinxbase/fsg_model.h>
51 #include <sphinxbase/logmath.h>
52 #include <sphinxbase/strfuncs.h>
53 #include <sphinxbase/jsgf.h>
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 #if 0
59 /* Fool Emacs. */
60 }
61 #endif
62 
63 #define YY_NO_INPUT /* Silence a compiler warning. */
64 
65 typedef struct jsgf_rhs_s jsgf_rhs_t;
66 typedef struct jsgf_atom_s jsgf_atom_t;
67 typedef struct jsgf_link_s jsgf_link_t;
68 
69 struct jsgf_s {
70  char *version;
71  char *charset;
72  char *locale;
73  char *name;
80  /* Scratch variables for FSG conversion. */
81  int nstate;
84 };
85 
86 struct jsgf_rule_s {
87  int refcnt;
88  char *name;
89  int public;
92  int entry;
93  int exit;
94 };
95 
96 struct jsgf_rhs_s {
99 };
100 
101 struct jsgf_atom_s {
102  char *name;
104  float weight;
105 };
106 
107 struct jsgf_link_s {
109  int from;
110  int to;
111 };
112 
113 #define jsgf_atom_is_rule(atom) ((atom)->name[0] == '<')
114 
115 void jsgf_add_link(jsgf_t *grammar, jsgf_atom_t *atom, int from, int to);
116 jsgf_atom_t *jsgf_atom_new(char *name, float weight);
117 jsgf_atom_t *jsgf_kleene_new(jsgf_t *jsgf, jsgf_atom_t *atom, int plus);
118 jsgf_rule_t *jsgf_optional_new(jsgf_t *jsgf, jsgf_rhs_t *exp);
119 jsgf_rule_t *jsgf_define_rule(jsgf_t *jsgf, char *name, jsgf_rhs_t *rhs, int public);
120 jsgf_rule_t *jsgf_import_rule(jsgf_t *jsgf, char *name);
121 
122 int jsgf_atom_free(jsgf_atom_t *atom);
123 int jsgf_rule_free(jsgf_rule_t *rule);
124 jsgf_rule_t *jsgf_rule_retain(jsgf_rule_t *rule);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 
131 #endif /* __JSGF_H__ */
Miscellaneous useful string functions.
glist_t tags
Tags, if any (glist_t of char *)
glist_t links
Generated FSG links.
Definition: jsgf_internal.h:82
A node in a generic list.
Definition: glist.h:100
int entry
Entry state for current instance of this rule.
Definition: jsgf_internal.h:92
glist_t searchpath
List of directories to search for grammars.
Definition: jsgf_internal.h:78
char * name
Grammar name.
Definition: jsgf_internal.h:73
jsgf_rhs_t * alt
Linked list of alternates.
Definition: jsgf_internal.h:98
glist_t rulestack
Stack of currently expanded rules.
Definition: jsgf_internal.h:83
int exit
Exit state for current instance of this rule.
Definition: jsgf_internal.h:93
int nstate
Number of generated states.
Definition: jsgf_internal.h:81
char * charset
JSGF charset (default UTF-8)
Definition: jsgf_internal.h:71
jsgf_rhs_t * rhs
Expansion.
Definition: jsgf_internal.h:90
char * name
Rule name (NULL for an alternation/grouping)
Definition: jsgf_internal.h:88
int refcnt
Reference count.
Definition: jsgf_internal.h:87
Generic linked-lists maintenance.
char * version
JSGF version (from header)
Definition: jsgf_internal.h:70
glist_t atoms
Sequence of items.
Definition: jsgf_internal.h:97
jsgf_t * parent
Parent grammar (if this is an imported one)
Definition: jsgf_internal.h:77
char * name
Rule or token name.
JSGF grammar compiler.
hash_table_t * rules
Defined or imported rules in this grammar.
Definition: jsgf_internal.h:75
Hash table implementation.
char * locale
JSGF locale (default C)
Definition: jsgf_internal.h:72
Fast integer logarithmic addition operations.
float weight
Weight (default 1)
hash_table_t * imports
Pointers to imported grammars.
Definition: jsgf_internal.h:76