Last reviewed: 3/23/2024 8:06:47 AM

Compiling Grammars

The GrammarKit class is designed to provide you a lot of flexiblity and minimize the programming necessary to manage the compilation of your grammars. Your grammar source can be in a variety of formats (e.g., text, embedded resource name, and file) and optionally your compiled binary can be saved to a file.

To compile your grammar and determine if there are any errors, all you need to do is pass the name of your grammar file source and the syntax type. For example:


_Recognizer.CompileFile("SAPI5XML", "c:\\myvocab.xml");
    

_Recognizer->CompileFile(L"SAPI5XML", L"c:\\myvocab.xml");
    

_Recognizer->CompileFile("SAPI5XML", "c:\\myvocab.xml");
    

_Recognizer.CompileFile('SAPI5XML', 'c:\\myvocab.xml');
    

_Recognizer.compileFile("SAPI5XML", "c:\\myvocab.xml");
    

_Recognizer.CompileFile("SAPI5XML", "c:\\myvocab.xml")
    

The CompileGrammar method initiates the compilation process, but where does the compiled output go? Nowhere, unless you say you are interested in saving it to a file.


_Recognizer.CompileFile("SAPI5XML", "c:\\myvocab.xml", "myvocab.dat");
    

_Recognizer->CompileFile(L"SAPI5XML", L"c:\\myvocab.xml", L"myvocab.dat");
    

_Recognizer->CompileFile("SAPI5XML", "c:\\myvocab.xml", "myvocab.dat");
    

_Recognizer.CompileFile('SAPI5XML', 'c:\\myvocab.xml', 'myvocab.dat');
    

_Recognizer.compileFile("SAPI5XML", "c:\\myvocab.xml", "myvocab.dat");
    

_Recognizer.CompileFile("SAPI5XML", "c:\\myvocab.xml", "myvocab.dat")