\section{include/sphinxbase/jsgf.h File Reference}
\label{jsgf_8h}\index{include/sphinxbase/jsgf.\+h@{include/sphinxbase/jsgf.\+h}}


J\+S\+GF grammar compiler.  


{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/hash\+\_\+table.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/fsg\+\_\+model.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/logmath.\+h$>$}\newline
\subsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\mbox{\label{jsgf_8h_a7216bc3a99823fb509e0dd4f8ee02b75}} 
\#define \textbf{ jsgf\+\_\+rule\+\_\+iter\+\_\+next}(itor)~\textbf{ hash\+\_\+table\+\_\+iter\+\_\+next}(itor)
\begin{DoxyCompactList}\small\item\em Advance an iterator to the next rule in the grammar. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a23b17eb0a92ba7e3c4aa086a33e3c5e6}} 
\#define \textbf{ jsgf\+\_\+rule\+\_\+iter\+\_\+rule}(itor)~((\textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$)(itor)-\/$>$ent-\/$>$val)
\begin{DoxyCompactList}\small\item\em Get the current rule in a rule iterator. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a697875f60dede64c607180514e4ab2c4}} 
\#define \textbf{ jsgf\+\_\+rule\+\_\+iter\+\_\+free}(itor)~\textbf{ hash\+\_\+table\+\_\+iter\+\_\+free}(itor)
\begin{DoxyCompactList}\small\item\em Free a rule iterator (if the end hasn\textquotesingle{}t been reached). \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\mbox{\label{jsgf_8h_aee85cf9f007eac61cebba97d6aaccaea}} 
typedef struct \textbf{ jsgf\+\_\+s} {\bfseries jsgf\+\_\+t}
\item 
\mbox{\label{jsgf_8h_a3bb0c86e5f9ba2c29b1fa91e1583bf00}} 
typedef struct \textbf{ jsgf\+\_\+rule\+\_\+s} {\bfseries jsgf\+\_\+rule\+\_\+t}
\item 
\mbox{\label{jsgf_8h_ac1e450c03748feb7e1db2a487b21c3fa}} 
typedef \textbf{ hash\+\_\+iter\+\_\+t} \textbf{ jsgf\+\_\+rule\+\_\+iter\+\_\+t}
\begin{DoxyCompactList}\small\item\em Iterator over rules in a grammar. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+grammar\+\_\+new} (\textbf{ jsgf\+\_\+t} $\ast$parent)
\begin{DoxyCompactList}\small\item\em Create a new J\+S\+GF grammar. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+parse\+\_\+file} (const char $\ast$filename, \textbf{ jsgf\+\_\+t} $\ast$parent)
\begin{DoxyCompactList}\small\item\em Parse a J\+S\+GF grammar from a file. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a657b5dd6f51f3a034572c8ba57bed1d8}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT char const  $\ast$ \textbf{ jsgf\+\_\+grammar\+\_\+name} (\textbf{ jsgf\+\_\+t} $\ast$jsgf)
\begin{DoxyCompactList}\small\item\em Get the grammar name from the file. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a8bbbd8834e0248bd8c52252e93c9822b}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT void \textbf{ jsgf\+\_\+grammar\+\_\+free} (\textbf{ jsgf\+\_\+t} $\ast$jsgf)
\begin{DoxyCompactList}\small\item\em Free a J\+S\+GF grammar. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a9617a53c34041e32f0800795aa1341ca}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+rule\+\_\+iter\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+rule\+\_\+iter} (\textbf{ jsgf\+\_\+t} $\ast$grammar)
\begin{DoxyCompactList}\small\item\em Get an iterator over all rules in a grammar. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a0329f14f22c4253c975a448dc5e0c3ec}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+get\+\_\+rule} (\textbf{ jsgf\+\_\+t} $\ast$grammar, char const $\ast$name)
\begin{DoxyCompactList}\small\item\em Get a rule by name from a grammar. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_ab1e5791530b5075f76ab085f248e8f0f}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT char const  $\ast$ \textbf{ jsgf\+\_\+rule\+\_\+name} (\textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$rule)
\begin{DoxyCompactList}\small\item\em Get the rule name from a rule. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_a85d7895c7a11d82c85b4529f6009c213}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT int \textbf{ jsgf\+\_\+rule\+\_\+public} (\textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$rule)
\begin{DoxyCompactList}\small\item\em Test if a rule is public or not. \end{DoxyCompactList}\item 
\mbox{\label{jsgf_8h_ac355893a25aa071eba6874fae1d51ad2}} 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ fsg\+\_\+model\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+build\+\_\+fsg} (\textbf{ jsgf\+\_\+t} $\ast$grammar, \textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$rule, \textbf{ logmath\+\_\+t} $\ast$lmath, float32 lw)
\begin{DoxyCompactList}\small\item\em Build a Sphinx F\+SG object from a J\+S\+GF rule. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ fsg\+\_\+model\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+build\+\_\+fsg\+\_\+raw} (\textbf{ jsgf\+\_\+t} $\ast$grammar, \textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$rule, \textbf{ logmath\+\_\+t} $\ast$lmath, float32 lw)
\begin{DoxyCompactList}\small\item\em Build a Sphinx F\+SG object from a J\+S\+GF rule. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ fsg\+\_\+model\+\_\+t} $\ast$ \textbf{ jsgf\+\_\+read\+\_\+file} (const char $\ast$file, \textbf{ logmath\+\_\+t} $\ast$lmath, float32 lw)
\begin{DoxyCompactList}\small\item\em Read J\+S\+GF from file and return F\+SG object from it. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT int \textbf{ jsgf\+\_\+write\+\_\+fsg} (\textbf{ jsgf\+\_\+t} $\ast$grammar, \textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$rule, F\+I\+LE $\ast$outfh)
\begin{DoxyCompactList}\small\item\em Convert a J\+S\+GF rule to Sphinx F\+SG text form. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
J\+S\+GF grammar compiler. 

This file defines the data structures for parsing J\+S\+GF grammars into Sphinx finite-\/state grammars. 

\subsection{Function Documentation}
\mbox{\label{jsgf_8h_a5873c31ddf99379d123c0db2e36600ba}} 
\index{jsgf.\+h@{jsgf.\+h}!jsgf\+\_\+build\+\_\+fsg\+\_\+raw@{jsgf\+\_\+build\+\_\+fsg\+\_\+raw}}
\index{jsgf\+\_\+build\+\_\+fsg\+\_\+raw@{jsgf\+\_\+build\+\_\+fsg\+\_\+raw}!jsgf.\+h@{jsgf.\+h}}
\subsubsection{jsgf\+\_\+build\+\_\+fsg\+\_\+raw()}
{\footnotesize\ttfamily S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ fsg\+\_\+model\+\_\+t}$\ast$ jsgf\+\_\+build\+\_\+fsg\+\_\+raw (\begin{DoxyParamCaption}\item[{\textbf{ jsgf\+\_\+t} $\ast$}]{grammar,  }\item[{\textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$}]{rule,  }\item[{\textbf{ logmath\+\_\+t} $\ast$}]{lmath,  }\item[{float32}]{lw }\end{DoxyParamCaption})}



Build a Sphinx F\+SG object from a J\+S\+GF rule. 

This differs from \doxyref{jsgf\+\_\+build\+\_\+fsg()}{p.}{jsgf_8h_ac355893a25aa071eba6874fae1d51ad2} in that it does not do closure on epsilon transitions or any other postprocessing. For the time being this is necessary in order to write it to a file -\/ the F\+SG code will be fixed soon. 

Definition at line 504 of file jsgf.\+c.



Referenced by jsgf\+\_\+write\+\_\+fsg().

\mbox{\label{jsgf_8h_a504181dfffafe125df5763e4b841b658}} 
\index{jsgf.\+h@{jsgf.\+h}!jsgf\+\_\+grammar\+\_\+new@{jsgf\+\_\+grammar\+\_\+new}}
\index{jsgf\+\_\+grammar\+\_\+new@{jsgf\+\_\+grammar\+\_\+new}!jsgf.\+h@{jsgf.\+h}}
\subsubsection{jsgf\+\_\+grammar\+\_\+new()}
{\footnotesize\ttfamily S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+t}$\ast$ jsgf\+\_\+grammar\+\_\+new (\begin{DoxyParamCaption}\item[{\textbf{ jsgf\+\_\+t} $\ast$}]{parent }\end{DoxyParamCaption})}



Create a new J\+S\+GF grammar. 


\begin{DoxyParams}{Parameters}
{\em parent} & optional parent grammar for this one (N\+U\+LL, usually). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
new J\+S\+GF grammar object, or N\+U\+LL on failure. 
\end{DoxyReturn}


Definition at line 79 of file jsgf.\+c.



References ckd\+\_\+calloc, hash\+\_\+table\+\_\+new(), jsgf\+\_\+s\+::imports, jsgf\+\_\+s\+::parent, jsgf\+\_\+s\+::rules, and jsgf\+\_\+s\+::searchpath.

\mbox{\label{jsgf_8h_ac67cab54fdb6ead62a3be79ccffb0836}} 
\index{jsgf.\+h@{jsgf.\+h}!jsgf\+\_\+parse\+\_\+file@{jsgf\+\_\+parse\+\_\+file}}
\index{jsgf\+\_\+parse\+\_\+file@{jsgf\+\_\+parse\+\_\+file}!jsgf.\+h@{jsgf.\+h}}
\subsubsection{jsgf\+\_\+parse\+\_\+file()}
{\footnotesize\ttfamily S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ jsgf\+\_\+t}$\ast$ jsgf\+\_\+parse\+\_\+file (\begin{DoxyParamCaption}\item[{const char $\ast$}]{filename,  }\item[{\textbf{ jsgf\+\_\+t} $\ast$}]{parent }\end{DoxyParamCaption})}



Parse a J\+S\+GF grammar from a file. 


\begin{DoxyParams}{Parameters}
{\em filename} & the name of the file to parse. \\
\hline
{\em parent} & optional parent grammar for this one (N\+U\+LL, usually). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
new J\+S\+GF grammar object, or N\+U\+LL on failure. 
\end{DoxyReturn}


Definition at line 734 of file jsgf.\+c.



Referenced by jsgf\+\_\+read\+\_\+file().

\mbox{\label{jsgf_8h_a5ed2b423b8ecacdda900e0b1e28b4e46}} 
\index{jsgf.\+h@{jsgf.\+h}!jsgf\+\_\+read\+\_\+file@{jsgf\+\_\+read\+\_\+file}}
\index{jsgf\+\_\+read\+\_\+file@{jsgf\+\_\+read\+\_\+file}!jsgf.\+h@{jsgf.\+h}}
\subsubsection{jsgf\+\_\+read\+\_\+file()}
{\footnotesize\ttfamily S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT \textbf{ fsg\+\_\+model\+\_\+t}$\ast$ jsgf\+\_\+read\+\_\+file (\begin{DoxyParamCaption}\item[{const char $\ast$}]{file,  }\item[{\textbf{ logmath\+\_\+t} $\ast$}]{lmath,  }\item[{float32}]{lw }\end{DoxyParamCaption})}



Read J\+S\+GF from file and return F\+SG object from it. 

This function looks for a first public rule in jsgf and constructs J\+S\+GF from it. 

Definition at line 511 of file jsgf.\+c.



References jsgf\+\_\+parse\+\_\+file().

\mbox{\label{jsgf_8h_abc18712a5a7bda442a8afba38f5827e7}} 
\index{jsgf.\+h@{jsgf.\+h}!jsgf\+\_\+write\+\_\+fsg@{jsgf\+\_\+write\+\_\+fsg}}
\index{jsgf\+\_\+write\+\_\+fsg@{jsgf\+\_\+write\+\_\+fsg}!jsgf.\+h@{jsgf.\+h}}
\subsubsection{jsgf\+\_\+write\+\_\+fsg()}
{\footnotesize\ttfamily S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+RT int jsgf\+\_\+write\+\_\+fsg (\begin{DoxyParamCaption}\item[{\textbf{ jsgf\+\_\+t} $\ast$}]{grammar,  }\item[{\textbf{ jsgf\+\_\+rule\+\_\+t} $\ast$}]{rule,  }\item[{F\+I\+LE $\ast$}]{outfh }\end{DoxyParamCaption})}



Convert a J\+S\+GF rule to Sphinx F\+SG text form. 

This does a direct conversion without doing transitive closure on null transitions and so forth. 

Definition at line 542 of file jsgf.\+c.



References jsgf\+\_\+build\+\_\+fsg\+\_\+raw(), and logmath\+\_\+init().

