Many of the rules in a grammar — such as those for recognizing numbers, dates, currencies, and times — can be used by almost every other grammar. One grammar can use another grammar's rules by linking to that grammar.
Links allow an application to create a grammar that exports common rules, serving a purpose similar to a C run-time library. Any grammar that has these rules on its imported-rules list automatically links to them when it is loaded, saving development time and system memory. Some engines may provide exported rules that are already defined and ready for the application to use. Eventually, third-party tool developers may develop and license common sets of rules.
To export a rule, the application writes an SRCFGXRULE structure in the grammar format. To link to an exported rule, the application specifies its rule identifier in the context-free grammar format in the same way as if they were internal to the grammar. However, instead of writing an SRCFGRULE structure that describes the rule, the application writes an SRCFGIMPRULE structure in the standard context-free grammar format.
When an application loads a grammar that imports rules, the engine checks all other context-free grammars in the system (including the one just loaded) to see if any of them export the requested rules. If so, the engine links the rules to the grammar. Any imported rules that are not linked at this time are automatically linked as soon as a grammar that exports them is loaded. If a link remains unconnected the grammar still works, although recognition paths that encounter the link are not possible. To determine whether or not a link is connected, the application can call the ISRGramCFG::LinkQuery member function.