1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 2007 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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.
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.
34 * ====================================================================
38 #ifndef __JSGF_INTERNAL_H__
39 #define __JSGF_INTERNAL_H__
42 * @file jsgf_internal.h Internal definitions for JSGF grammar compiler
45 #define YY_NO_UNISTD_H 1
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>
63 #define YY_NO_INPUT /* Silence a compiler warning. */
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;
70 char *version; /**< JSGF version (from header) */
71 char *charset; /**< JSGF charset (default UTF-8) */
72 char *locale; /**< JSGF locale (default C) */
73 char *name; /**< Grammar name */
75 hash_table_t *rules; /**< Defined or imported rules in this grammar. */
76 hash_table_t *imports; /**< Pointers to imported grammars. */
77 jsgf_t *parent; /**< Parent grammar (if this is an imported one) */
78 glist_t searchpath; /**< List of directories to search for grammars. */
80 /* Scratch variables for FSG conversion. */
81 int nstate; /**< Number of generated states. */
82 glist_t links; /**< Generated FSG links. */
83 glist_t rulestack; /**< Stack of currently expanded rules. */
87 int refcnt; /**< Reference count. */
88 char *name; /**< Rule name (NULL for an alternation/grouping) */
89 int public; /**< Is this rule marked 'public'? */
90 jsgf_rhs_t *rhs; /**< Expansion */
92 int entry; /**< Entry state for current instance of this rule. */
93 int exit; /**< Exit state for current instance of this rule. */
97 glist_t atoms; /**< Sequence of items */
98 jsgf_rhs_t *alt; /**< Linked list of alternates */
102 char *name; /**< Rule or token name */
103 glist_t tags; /**< Tags, if any (glist_t of char *) */
104 float weight; /**< Weight (default 1) */
108 jsgf_atom_t *atom; /**< Name, tags, weight */
109 int from; /**< From state */
110 int to; /**< To state */
113 #define jsgf_atom_is_rule(atom) ((atom)->name[0] == '<')
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);
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);
131 #endif /* __JSGF_H__ */