<?php $isip_window_title = "ISIP Homepage"; ?>
<?php include("/data/isip/www/templates/documentation/header/header.html"); ?>

<!--#set var="isip_page_title" value="LanguageModelABNF" -->
<?php include("/data/isip/www/templates/documentation/body/index_class.html"); ?>
<?php include("/data/isip/www/templates/documentation/body/bar.html"); ?>

<a name="name">
<b>name: <a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF.h">LanguageModelABNF</a></b>

<br><br>

<a name="synopsis">
<b>synopsis:</b>
<br><br>

<blockquote>
<pre> 
g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_mmedia.a

#include &lt;LanguageModelABNF.h&gt;

boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);
</pre>
</blockquote>

<a name="quick_start">
<b>quick start:</b>
<br><br>

<blockquote>
<pre>
Sof sof;
sof.open("lm_abnf_obj.sof", File::READ_ONLY);

LanguageModelABNF lmabnf;
lmabnf.read(sof, 0);

</pre>
</blockquote>

<a name="description"> 
<b>description:</b>
<br><br>

The LanguageModelABNF is a class that reads in ABNF grammars and gives out a
set of Producitons in BNF form. In ABNF there are certain meta symbols that 
are used, that make sit difficult to be converted into IHD (ISIP Hierarchial
Di-Graph).

<a href="../../search/HierarchicalDigraph/index.html">HierarchicalDigraph</a>

BNF uses recursion unlike ABNF which uses iteration. This makes it easy to
convert BNF Productions into IHD. The implementation of the LanguageModelABNF is such that one methos auto matically calls other methods. convertABNFGrammars 
method, first look for ALTERNATION in the input Production. If it exists, it 
passes the Production together with the position of ALTERNATION and the nesting epth till that point. removeAlternation method removes the OR symbol in the 
input Production and passes it to removeKleenePlus, which in turn calls removeKleeneStar and this continues. In case there is not ALTERNATION in the input Produciton, it is passes directly to removeKleenePlus method. By the end of the conversion process, we have a set of productions which are free of the meta symbols.


<br><br>

<a name="dependencies">
<b>dependencies:</b>
<br><br>

<ul>
  <li> <a href="../../dstr/DiGraph/index.html">DiGraph</a> 
  <li> <a href="../../shell/Filename/index.html">Filename</a>
  <li> <a href="../../system/File/index.html">File</a>
  <li> <a href="../../system/DoubleLinkedList/index.html">DoubleLinkedList</a>
  <li> <a href="../../system/Console/index.html">Console</a>
  <li> <a href="../../pr/LanguageModel/index.html">LanguageModelBase</a> 
  <li> <a href="../../dstr/Pair/index.html">Pair</a>	
  <li> <a href="../../math/scalar/Short/index.html">Short</a>
  <li> <a href="../../io/Sof/index.html">Sof</a>
  <li> <a href="../../dstr/Triple/index.html">Triple</a>
  <li> <a href="../../math/scalar/Ulong/index.html">Ulong</a>
  <li> <a href="../../pr/ProductionRuleTokenType/index.html">ProductionRuleTokenType</a>
  <li> <a href="../../pr/ProductionRule/index.html">ProductionRule</a>
  <li> <a href="../../pr/LanguageModelXML/index.html">LanguageModelXML</a>

</ul>

<a name="constants">
<b>public constants:</b>
<br><br>

<ul>
  <li> define the class name:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_00.cc&constant=CLASS_NAME">static const String LanguageModelABNF::CLASS_NAME = L"LanguageModelABNF";</a></pre>

 <li> other i/o constants:
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_00.cc&constant=DEF_PARAM">static const String LanguageModelABNF::DEF_PARAM;</a></pre>

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_00.cc&constant=DEF_LEVEL">static const long LanguageModelABNF::DEF_LEVEL;</a></pre>

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_00.cc&constant=PARAM_GRAMMARS">static const String LanguageModelABNF::PARAM_ABNF;</a></pre>

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_00.cc&constant=DEF_TAG">static const String LanguageModelABNF::DEF_TAG;</a></pre>
</ul>

<a name="error">
<b>error codes:</b>
<br><br>
<ul>
  <li> error code indicating LanguageModelABNF class general error:
       <pre><a href="/perl/ifc_document.pl?err=100800">static const long ERR = 100800;</a></pre>
       <pre><a href="/perl/ifc_document.pl?err_ctxt_inv_sym=100801">static const long ERR_CTXT_INV_SYM = 100801;</a></pre>
       <pre><a href="/perl/ifc_document.pl?err_rule_empty=100802">static const long ERR_RULE_EMPTY = 100802;</a></pre>

</ul>

<a name="protected">
<b>protected data:</b>
<br><br>

<ul> <!-- list of categories -->

  <li> search direction
    <pre>enum DIRECTION {RIGHT=0, LEFT};</pre>

  <li> rulemodel name
    <pre>RuleModel abnf_model_d;</pre>

  <li> holds count for non-conflicting variable names
    <pre>long count_d;</pre>

</ul>

<a name="public">
<b>required public methods:</b>
<br><br>

<ul>
  <li> static methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=name">static const String& name();</a></pre>

  <li> debug methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF.h&method=diagnose">static boolean diagnose(Integral::DEBUG level);</a></pre>
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc&method=debug">boolean debug(const unichar* msg) const;</a></pre>
       
  <li> default constructor:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=default+constructor">LanguageModelABNF();</a></pre>

  <li> assign methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc&method=assign">boolean assign(const LanguageModelABNF& arg);</a></pre>
          
  <li> i/o methods:
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_03.cc&method=read">boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);</a></pre>

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_03.cc&method=readData">boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);</a></pre>
  
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_03.cc&method=write">boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;</a></pre>
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_04.cc&method=writeData">boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;</a></pre>

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=sofSize">long sofSize() const;</a></pre>

  <li> equality methods:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc.h&method=eq&instance=0">boolean eq(const LanguageModelABNF& arg) const;</a></pre>
       
       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc.h&method=eq&instance=1">boolean eq(const LanguageModelBase& arg) const;</a></pre>

  <li> operator method:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc.h&method=operator=&instance=0">boolean operator=(const LanguageModelABNF& lmabnf_a);</a></pre>

  <li> clear method:

       <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_01.cc&method=clear">boolean clear(Integral::CMODE ctype);</a></pre>

</ul>

<a name="private">
<b>class-specific public methods:</b>
<br><br>

<ul>
  <li> equivalent BNF production rules methods:
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method= retrieve equivalent BNF">RuleModel getRuleModel();;</a></pre>

   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=pass in equivalent BNF">boolean setRuleModel(const RuleModel& model_a);</a></pre>

<li> equivalent ABNF production rules methods:
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=retrieve equivalent ABNF">RuleModel getABNFRuleModel();</a></pre>

   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/LanguageModelABNF.h&method=pass in equivalent ABNF">boolean setABNFRuleModel(const RuleModel& model_a);</a></pre>
</ul>


<a name="protected">
<b>class-specific protected methods:</b>
<br><br>

<ul>
  <li> ABNF to BNF conversion methods:
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=findRightSymbols">WeightedSymbols findRightSymbols(ProductionRuleSet rules, long index, long nest_level, long position, Float weight);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=findLeftSymbols">Vector&lt;SearchSymbol&gt; findLeftSymbols(ProductionRuleSet rules, long index, long nest_level, long position);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=buildNormBNFRules">boolean buildNormBNFRules(Vector&lt;SearchSymbol&gt; left_symbols, WeightedSymbols right_symbols, ProductionRuleSet& bnf_rules);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=findEndOfNestLevel">long findEndOfNestLevel(ProductionRule current_rule, long index, DIRECTION dir);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=findToken">long findToken(ProductionRule current_rule, long index, ProductionRuleTokenType::TYPE token, DIRECTION dir);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=restoreSymbols">boolean restoreSymbols(ProductionRuleSet& rules, Vector&lt;Pair&lt;SearchSymbol, SearchSymbol&gt;&gt; chart);</a></pre>
   <pre><a href="/perl/ifc_document.pl?file=$isip/class/pr/LanguageModelABNF/lmabnf_06.cc&method=createStartRules">boolean createStartRules(RuleModel abnf_rules, ProductionRuleSet& bnf_rules, long level_index, long graph_index);</a></pre>
</ul>

<a name="examples">
<b>examples:</b>
<br><br>

<ul>
  <li> This example shows how to use a LanguageModelABNF object to read
       a LanguageModelABNF object from a file, and retrieve the parsed
       grammars in BNF form.
   
<pre>

// declare an sof object to parse the file
//
Sof sof;

// open the file for reading
//
sof.open("lm_abnf_obj.sof", File::READ_ONLY);

// declare a LMABNF object to read the grammars
//
LanguageModelABNF lmabnf;

// read the grammars
//
lmabnf.read(sof, 0);

// declare an HierarchicalDigraph object to store the grammars in DiGraph form
//
HierarchicalDigraph hg;

// retrieve the grammars from the LMABNF object, and store them in the HD object
//


</pre>
</ul>

<br><br>
<ul>

</ul>

<!--#include virtual="/hse/ies/templates/documentation/footer/footer.html" -->
