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


J\+S\+G\+F grammar compiler.  


{\ttfamily \#include $<$stdio.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/hash\+\_\+table.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/fsg\+\_\+model.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/logmath.\+h$>$}\\*
\subsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define {\bf jsgf\+\_\+rule\+\_\+iter\+\_\+next}(itor)~{\bf hash\+\_\+table\+\_\+iter\+\_\+next}(itor)\label{jsgf_8h_a7216bc3a99823fb509e0dd4f8ee02b75}

\begin{DoxyCompactList}\small\item\em Advance an iterator to the next rule in the grammar. \end{DoxyCompactList}\item 
\#define {\bf jsgf\+\_\+rule\+\_\+iter\+\_\+rule}(itor)~(({\bf jsgf\+\_\+rule\+\_\+t} $\ast$)(itor)-\/$>$ent-\/$>$val)\label{jsgf_8h_a23b17eb0a92ba7e3c4aa086a33e3c5e6}

\begin{DoxyCompactList}\small\item\em Get the current rule in a rule iterator. \end{DoxyCompactList}\item 
\#define {\bf jsgf\+\_\+rule\+\_\+iter\+\_\+free}(itor)~{\bf hash\+\_\+table\+\_\+iter\+\_\+free}(itor)\label{jsgf_8h_a697875f60dede64c607180514e4ab2c4}

\begin{DoxyCompactList}\small\item\em Free a rule iterator (if the end hasn't been reached). \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct {\bf jsgf\+\_\+s} {\bfseries jsgf\+\_\+t}\label{jsgf_8h_aee85cf9f007eac61cebba97d6aaccaea}

\item 
typedef struct {\bf jsgf\+\_\+rule\+\_\+s} {\bfseries jsgf\+\_\+rule\+\_\+t}\label{jsgf_8h_a3bb0c86e5f9ba2c29b1fa91e1583bf00}

\item 
typedef {\bf hash\+\_\+iter\+\_\+t} {\bf jsgf\+\_\+rule\+\_\+iter\+\_\+t}\label{jsgf_8h_ac1e450c03748feb7e1db2a487b21c3fa}

\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\+R\+T {\bf jsgf\+\_\+t} $\ast$ {\bf jsgf\+\_\+grammar\+\_\+new} ({\bf jsgf\+\_\+t} $\ast$parent)
\begin{DoxyCompactList}\small\item\em Create a new J\+S\+G\+F grammar. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf jsgf\+\_\+t} $\ast$ {\bf jsgf\+\_\+parse\+\_\+file} (const char $\ast$filename, {\bf jsgf\+\_\+t} $\ast$parent)
\begin{DoxyCompactList}\small\item\em Parse a J\+S\+G\+F grammar from a file. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T char const $\ast$ {\bf jsgf\+\_\+grammar\+\_\+name} ({\bf jsgf\+\_\+t} $\ast$jsgf)\label{jsgf_8h_a657b5dd6f51f3a034572c8ba57bed1d8}

\begin{DoxyCompactList}\small\item\em Get the grammar name from the file. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf jsgf\+\_\+grammar\+\_\+free} ({\bf jsgf\+\_\+t} $\ast$jsgf)\label{jsgf_8h_a8bbbd8834e0248bd8c52252e93c9822b}

\begin{DoxyCompactList}\small\item\em Free a J\+S\+G\+F grammar. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T \\*
{\bf jsgf\+\_\+rule\+\_\+iter\+\_\+t} $\ast$ {\bf jsgf\+\_\+rule\+\_\+iter} ({\bf jsgf\+\_\+t} $\ast$grammar)\label{jsgf_8h_a9617a53c34041e32f0800795aa1341ca}

\begin{DoxyCompactList}\small\item\em Get an iterator over all rules in a grammar. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf jsgf\+\_\+rule\+\_\+t} $\ast$ {\bf jsgf\+\_\+get\+\_\+rule} ({\bf jsgf\+\_\+t} $\ast$grammar, char const $\ast$name)\label{jsgf_8h_a0329f14f22c4253c975a448dc5e0c3ec}

\begin{DoxyCompactList}\small\item\em Get a rule by name from a grammar. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T char const $\ast$ {\bf jsgf\+\_\+rule\+\_\+name} ({\bf jsgf\+\_\+rule\+\_\+t} $\ast$rule)\label{jsgf_8h_ab1e5791530b5075f76ab085f248e8f0f}

\begin{DoxyCompactList}\small\item\em Get the rule name from a rule. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf jsgf\+\_\+rule\+\_\+public} ({\bf jsgf\+\_\+rule\+\_\+t} $\ast$rule)\label{jsgf_8h_a85d7895c7a11d82c85b4529f6009c213}

\begin{DoxyCompactList}\small\item\em Test if a rule is public or not. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf fsg\+\_\+model\+\_\+t} $\ast$ {\bf jsgf\+\_\+build\+\_\+fsg} ({\bf jsgf\+\_\+t} $\ast$grammar, {\bf jsgf\+\_\+rule\+\_\+t} $\ast$rule, {\bf logmath\+\_\+t} $\ast$lmath, float32 lw)\label{jsgf_8h_ac355893a25aa071eba6874fae1d51ad2}

\begin{DoxyCompactList}\small\item\em Build a Sphinx F\+S\+G object from a J\+S\+G\+F rule. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf fsg\+\_\+model\+\_\+t} $\ast$ {\bf jsgf\+\_\+build\+\_\+fsg\+\_\+raw} ({\bf jsgf\+\_\+t} $\ast$grammar, {\bf jsgf\+\_\+rule\+\_\+t} $\ast$rule, {\bf logmath\+\_\+t} $\ast$lmath, float32 lw)
\begin{DoxyCompactList}\small\item\em Build a Sphinx F\+S\+G object from a J\+S\+G\+F rule. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf fsg\+\_\+model\+\_\+t} $\ast$ {\bf jsgf\+\_\+read\+\_\+file} (const char $\ast$file, {\bf logmath\+\_\+t} $\ast$lmath, float32 lw)
\begin{DoxyCompactList}\small\item\em Read J\+S\+G\+F from file and return F\+S\+G object from it. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf jsgf\+\_\+write\+\_\+fsg} ({\bf jsgf\+\_\+t} $\ast$grammar, {\bf jsgf\+\_\+rule\+\_\+t} $\ast$rule, F\+I\+L\+E $\ast$outfh)
\begin{DoxyCompactList}\small\item\em Convert a J\+S\+G\+F rule to Sphinx F\+S\+G text form. \end{DoxyCompactList}\end{DoxyCompactItemize}


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

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

Definition in file {\bf jsgf.\+h}.



\subsection{Function Documentation}
\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}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf fsg\+\_\+model\+\_\+t}$\ast$ jsgf\+\_\+build\+\_\+fsg\+\_\+raw (
\begin{DoxyParamCaption}
\item[{{\bf jsgf\+\_\+t} $\ast$}]{grammar, }
\item[{{\bf jsgf\+\_\+rule\+\_\+t} $\ast$}]{rule, }
\item[{{\bf logmath\+\_\+t} $\ast$}]{lmath, }
\item[{float32}]{lw}
\end{DoxyParamCaption}
)}\label{jsgf_8h_a5873c31ddf99379d123c0db2e36600ba}


Build a Sphinx F\+S\+G object from a J\+S\+G\+F 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\+S\+G code will be fixed soon. 

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



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

\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}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf jsgf\+\_\+t}$\ast$ jsgf\+\_\+grammar\+\_\+new (
\begin{DoxyParamCaption}
\item[{{\bf jsgf\+\_\+t} $\ast$}]{parent}
\end{DoxyParamCaption}
)}\label{jsgf_8h_a504181dfffafe125df5763e4b841b658}


Create a new J\+S\+G\+F grammar. 


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


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



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



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

\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}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf jsgf\+\_\+t}$\ast$ jsgf\+\_\+parse\+\_\+file (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{filename, }
\item[{{\bf jsgf\+\_\+t} $\ast$}]{parent}
\end{DoxyParamCaption}
)}\label{jsgf_8h_ac67cab54fdb6ead62a3be79ccffb0836}


Parse a J\+S\+G\+F 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\+L\+L, usually). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
new J\+S\+G\+F grammar object, or N\+U\+L\+L on failure. 
\end{DoxyReturn}


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



References E\+\_\+\+E\+R\+R\+O\+R, E\+\_\+\+E\+R\+R\+O\+R\+\_\+\+S\+Y\+S\+T\+E\+M, jsgf\+\_\+grammar\+\_\+free(), and jsgf\+\_\+grammar\+\_\+new().



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

\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}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf fsg\+\_\+model\+\_\+t}$\ast$ jsgf\+\_\+read\+\_\+file (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{file, }
\item[{{\bf logmath\+\_\+t} $\ast$}]{lmath, }
\item[{float32}]{lw}
\end{DoxyParamCaption}
)}\label{jsgf_8h_a5ed2b423b8ecacdda900e0b1e28b4e46}


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

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

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



References E\+\_\+\+E\+R\+R\+O\+R, jsgf\+\_\+build\+\_\+fsg(), jsgf\+\_\+grammar\+\_\+free(), jsgf\+\_\+parse\+\_\+file(), jsgf\+\_\+rule\+\_\+iter(), jsgf\+\_\+rule\+\_\+iter\+\_\+free, jsgf\+\_\+rule\+\_\+iter\+\_\+next, jsgf\+\_\+rule\+\_\+iter\+\_\+rule, and jsgf\+\_\+rule\+\_\+public().

\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}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int jsgf\+\_\+write\+\_\+fsg (
\begin{DoxyParamCaption}
\item[{{\bf jsgf\+\_\+t} $\ast$}]{grammar, }
\item[{{\bf jsgf\+\_\+rule\+\_\+t} $\ast$}]{rule, }
\item[{F\+I\+L\+E $\ast$}]{outfh}
\end{DoxyParamCaption}
)}\label{jsgf_8h_abc18712a5a7bda442a8afba38f5827e7}


Convert a J\+S\+G\+F rule to Sphinx F\+S\+G 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(), logmath\+\_\+free(), and logmath\+\_\+init().

