Click here to Skip to main content
15,893,594 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: MTVariableI 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>MTVariableI Class Reference</h1><!-- doxytag: class="MTVariableI" --><!-- doxytag: inherits="MTParserItemI" --><code>#include &lt;<a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.h</a>&gt;</code>
<p>
<p>Inheritance diagram for MTVariableI:
<p><center><img src="classMTVariableI.png" usemap="#MTVariableI_map" border="0" alt=""></center>
<map name="MTVariableI_map">
<area href="classMTParserItemI.html" alt="MTParserItemI" shape="rect" coords="0,0,108,24">
<area href="classMTDoubleVector.html" alt="MTDoubleVector" shape="rect" coords="0,112,108,136">
</map>
<a href="classMTVariableI-members.html">List of all members.</a><hr><a name="_details"></a><h2>Detailed Description</h2>
Specialized variable evaluator. 
<p>
Implement this interface to create a new variable type. For example, variables that get their values in a DataBase.
<p>

<p>
Definition at line <a class="el" href="MTParserPublic_8h-source.html#l00309">309</a> of file <a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.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">virtual <a class="el" href="classMTVariableI.html">MTVariableI</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a0">spawn</a> ()=0</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create a new instance of itself.  <a href="#a0"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a1">isConstant</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Indicate whether an item is constant.  <a href="#a1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual const MTCHAR *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a2">getHelpString</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get the helpstring.  <a href="#a2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual const MTCHAR *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a3">getDescription</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get a short description.  <a href="#a3"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a4"></a><!-- doxytag: member="MTVariableI::getNbArgs" ref="a4" args="()" -->
virtual int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a4">getNbArgs</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="a5"></a><!-- doxytag: member="MTVariableI::~MTVariableI" ref="a5" args="()" -->
virtual&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classMTVariableI.html#a5">~MTVariableI</a> ()</td></tr>

</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="a3"></a><!-- doxytag: member="MTVariableI::getDescription" ref="a3" args="()" --><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">virtual const MTCHAR* MTVariableI::getDescription           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [inline, virtual]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Get a short description. 
<p>
A description of what the item is about.<p>
<dl compact><dt><b>Returns:</b></dt><dd>The description</dd></dl>

<p>
Implements <a class="el" href="classMTParserItemI.html#a3">MTParserItemI</a>.
<p>
Definition at line <a class="el" href="MTParserPublic_8h-source.html#l00331">331</a> of file <a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.h</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a2"></a><!-- doxytag: member="MTVariableI::getHelpString" ref="a2" args="()" --><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">virtual const MTCHAR* MTVariableI::getHelpString           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [inline, virtual]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Get the helpstring. 
<p>
An helpstring gives hint to the user on how to use an item.<p>
<dl compact><dt><b>Returns:</b></dt><dd>The helpstring</dd></dl>

<p>
Implements <a class="el" href="classMTParserItemI.html#a2">MTParserItemI</a>.
<p>
Definition at line <a class="el" href="MTParserPublic_8h-source.html#l00328">328</a> of file <a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.h</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a1"></a><!-- doxytag: member="MTVariableI::isConstant" ref="a1" args="()" --><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">virtual bool MTVariableI::isConstant           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [inline, virtual]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Indicate whether an item is constant. 
<p>
A constant item can be evaluated only once and its value cached, thus optimizing performance. For example, a constant function always returns the same result when evaluated with the same arguments. An example of non-constant function is the random function.<p>
This method is called after the first evaluation.<p>
<dl compact><dt><b>Returns:</b></dt><dd>True if the item is constant</dd></dl>

<p>
Implements <a class="el" href="classMTParserItemI.html#a4">MTParserItemI</a>.
<p>
Definition at line <a class="el" href="MTParserPublic_8h-source.html#l00325">325</a> of file <a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.h</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a0"></a><!-- doxytag: member="MTVariableI::spawn" ref="a0" args="()=0" --><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">virtual <a class="el" href="classMTVariableI.html">MTVariableI</a>* MTVariableI::spawn           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [pure virtual]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Create a new instance of itself. 
<p>
This method is used to duplicate a parser object.<p>
<dl compact><dt><b>Returns:</b></dt><dd>A new independant object representing the same variable</dd></dl>

<p>
Implemented in <a class="el" href="classMTDoubleVector.html#a3">MTDoubleVector</a>.    </td>
  </tr>
</table>
<hr>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="MTParserPublic_8h-source.html">MTParserPublic.h</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Sun Mar 9 17:39:37 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