Grammar Reference > Example Grammar Files

Example Grammar Files
The following sample grammar files contains the gram_edk_place.xml grammar.
grammar.xml
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE grammars SYSTEM "../published/edk.dtd">
<!-- Sample Eduction grammar file showing all elements and attributes in the DTD -->
<grammars debug="true" case="sensitive">
  <include path="grammar_include.xml" type="private">
    <publish name="grammar2/g2e2"/> <!-- publish previously private entity -->
  </include>
  <grammar name="grammar1" case="inherited" extend="disallow" debug="inherited">
    <extern name="grammar2"/> <!-- removes the need to refer explicitly to grammar2 -->
    <entity name="entity1" type="public" case="insensitive" extend="disallow" debug="true">
    <!-- the following entity definitions are not useful but are provided only to illustrate the options and combinations of elements and attributes available -->
    <pattern score=".1" case="insensitive" replace="replacechars" insert_before="prefix_" insert_after="_suffix">cat</pattern>
    <pattern score=".2">sat</pattern>
    <entry headword="mat" score=".3" case="inherited" debug="inherited">
      <synonym case="inherited">rug</synonym> <!-- will locate rug but return mat -->
      <!-- will locate rug but return mat -->
      <synonym case="inherited"><![CDATA[carpet]]></synonym> <!-- illustrates allowing CDATA in this element -->
      </entry>
      <entry headword="dog" score=".6"/>
      <entry>
        <headword score=".8"><![CDATA[rabbit<hi!>&abc&amp;]]></headword>
        <synonym>bunny</synonym>
      </entry>
    </entity>
    <entity name="entity2" type="public">
      <pattern>(?A:g2e1)</pattern>
    </entity>
  </grammar>
</grammars>
grammar_include.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE grammars SYSTEM "../published/edk.dtd">
<grammars>
  <grammar name="grammar2">
    <entity name="g2e1">
      <pattern>animal</pattern>         <!-- default visibility -->
    </entity>
    <entity name="g2e2" type="private"> <!-- explicitly private -->
      <pattern>mineral</pattern>
    </entity>
    <entity name="g2e3" type="public"> <!-- explicitly public -->
      <pattern>vegetable</pattern>
    </entity>
  </grammar>
</grammars>