Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / C#

An extensible math expression parser with plug-ins

Rate me:
Please Sign up or sign in to vote.
4.92/5 (147 votes)
13 Mar 2008CPOL51 min read 1.4M   29K   364  
Design and code for an extensible, maintainable, robust, and easy to use math parser.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>MTParserLib: MTCompilerDefState Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>MTCompilerDefState Class Reference</h1><!-- doxytag: class="MTCompilerDefState" --><!-- doxytag: inherits="MTCompilerStateI" --><code>#include &lt;<a class="el" href="MTParserCompiler_8h-source.html">MTParserCompiler.h</a>&gt;</code>
<p>
<p>Inheritance diagram for MTCompilerDefState:
<p><center><img src="classMTCompilerDefState.png" usemap="#MTCompilerDefState_map" border="0" alt=""></center>
<map name="MTCompilerDefState_map">
<area href="classMTCompilerStateI.html" alt="MTCompilerStateI" shape="rect" coords="0,0,128,24">
</map>
<a href="classMTCompilerDefState-members.html">List of all members.</a><hr><a name="_details"></a><h2>Detailed Description</h2>
Default compiler state. 
<p>

<p>
Definition at line <a class="el" href="MTParserCompiler_8h-source.html#l00293">293</a> of file <a class="el" href="MTParserCompiler_8h-source.html">MTParserCompiler.h</a>.<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a0"></a><!-- doxytag: member="MTCompilerDefState::enter" ref="a0" args="(MTCompilerI *pCompiler, MTRegistrarI *pRegistrar)" -->
virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTCompilerDefState.html#a0">enter</a> (<a class="el" href="classMTCompilerI.html">MTCompilerI</a> *pCompiler, <a class="el" href="classMTRegistrarI.html">MTRegistrarI</a> *pRegistrar)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Called when entering the state. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTCompilerDefState.html#a1">onOp</a> (const MTSTRING &amp;opSymbol)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Called when an operator is detected.  <a href="#a1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a2"></a><!-- doxytag: member="MTCompilerDefState::onOpenBracket" ref="a2" args="()" -->
virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTCompilerDefState.html#a2">onOpenBracket</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Called when an open bracket is detected. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a3"></a><!-- doxytag: member="MTCompilerDefState::onCloseBracket" ref="a3" args="()" -->
virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTCompilerDefState.html#a3">onCloseBracket</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Called when a close bracket is detected. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a4"></a><!-- doxytag: member="MTCompilerDefState::onArgSeparator" ref="a4" args="()" -->
virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTCompilerDefState.html#a4">onArgSeparator</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Called when an argument separator is detected. <br></td></tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="a1"></a><!-- doxytag: member="MTCompilerDefState::onOp" ref="a1" args="(const MTSTRING &amp;opSymbol)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top">void MTCompilerDefState::onOp           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const MTSTRING &amp;&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>opSymbol</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [virtual]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Called when an operator is detected. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>opSymbol</em>&nbsp;</td><td>The detected operator symbol</td></tr>
  </table>
</dl>

<p>
Reimplemented from <a class="el" href="classMTCompilerStateI.html#z11_0">MTCompilerStateI</a>.
<p>
Definition at line <a class="el" href="MTParserCompiler_8cpp-source.html#l01046">1046</a> of file <a class="el" href="MTParserCompiler_8cpp-source.html">MTParserCompiler.cpp</a>.
<p>
References <a class="el" href="MTParserCompiler_8h-source.html#l00082">MTParserCompiler::SOpStackItem::exprStrPos</a>, <a class="el" href="classMTRegistrarI.html#a3">MTRegistrarI::findOp()</a>, <a class="el" href="classMTCompilerI.html#z10_3">MTCompilerI::getCurPos()</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00140">MTParserCompiler::getExprLength()</a>, <a class="el" href="classMTRegistrarPublicI.html#z13_11">MTRegistrarPublicI::getOp()</a>, <a class="el" href="classMTOperatorI.html#a0">MTOperatorI::getPrecedence()</a>, <a class="el" href="MTParserCompiler_8cpp-source.html#l00211">MTParserCompiler::getPrevItemType()</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00142">MTParserCompiler::getRegistrar()</a>, <a class="el" href="classMTParserItemI.html#a1">MTParserItemI::getSymbol()</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00091">MTParserCompiler::SOpStackItem::itemID</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00090">MTParserCompiler::SOpStackItem::itemType</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00149">MTParserCompiler::m_opStack</a>, <a class="el" href="MTParserPrivate_8h-source.html#l00392">MTCompilerStateI::m_pCompiler</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00011">MTOPEN_BRACKET_PRECEDENCE</a>, <a class="el" href="MTParserException_8h-source.html#l00188">MTPARSINGEXCEP_InvalidOpSyntax</a>, <a class="el" href="MTParserException_8h-source.html#l00210">MTPARSINGEXCEP_UnexpectedOp</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00084">MTParserCompiler::SOpStackItem::nbArgs</a>, <a class="el" href="MTParserCompiler_8cpp-source.html#l00543">MTParserCompiler::parseWord()</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00092">MTParserCompiler::SOpStackItem::pEval</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00081">MTParserCompiler::SOpStackItem::precedence</a>, <a class="el" href="MTParserCompiler_8cpp-source.html#l00495">MTParserCompiler::pushOnExprStack()</a>, <a class="el" href="MTParserCompiler_8cpp-source.html#l00231">MTParserCompiler::setArgValueFlag()</a>, <a class="el" href="MTParserCompiler_8cpp-source.html#l00204">MTParserCompiler::setCurItemType()</a>, <a class="el" href="MTParserCompiler_8h-source.html#l00137">MTParserCompiler::setCurPos()</a>, and <a class="el" href="MTParserCompiler_8cpp-source.html#l00981">MTParserCompiler::throwParsingExcep()</a>.    </td>
  </tr>
</table>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="MTParserCompiler_8h-source.html">MTParserCompiler.h</a><li><a class="el" href="MTParserCompiler_8cpp-source.html">MTParserCompiler.cpp</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Sun Mar 9 17:39:36 2008 for MTParserLib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
Software Engineer working at a fun and smart startup company

Comments and Discussions