Click here to Skip to main content
15,892,697 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: MTParserMacroFunc.h Source File</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>MTParserMacroFunc.h</h1><a href="MTParserMacroFunc_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/** @file MTParserMacroFunc.h</span>
<a name="l00002"></a>00002 <span class="comment">        @brief Implementation for macro functions</span>
<a name="l00003"></a>00003 <span class="comment">        @author (c) 2008 Mathieu Jacques</span>
<a name="l00004"></a>00004 <span class="comment">*/</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="preprocessor">#ifndef _MTPARSERMACROFUNC_INCLUDED</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#define _MTPARSERMACROFUNC_INCLUDED</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span>
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="MTParserPublic_8h.html">MTParserPublic.h</a>"</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">/** @brief Macro function</span>
<a name="l00012"></a>00012 <span class="comment">*/</span>
<a name="l00013"></a><a class="code" href="classMTMacroFct.html">00013</a> <span class="keyword">class </span><a class="code" href="classMTMacroFct.html">MTMacroFct</a> : <span class="keyword">public</span> <a class="code" href="classMTFunctionI.html">MTFunctionI</a>
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015 <span class="keyword">public</span>:
<a name="l00016"></a>00016 <span class="comment"></span>
<a name="l00017"></a>00017 <span class="comment">        /** @brief Initialize the macro object</span>
<a name="l00018"></a>00018 <span class="comment">        @param prototype        The macro prototype: macro(arg1, arg2, arg3...)</span>
<a name="l00019"></a>00019 <span class="comment">        @param macro            The macro function</span>
<a name="l00020"></a>00020 <span class="comment">        @param description      The macro description</span>
<a name="l00021"></a>00021 <span class="comment">        @param pCompiler        The compiler template</span>
<a name="l00022"></a>00022 <span class="comment">        @param pRegistrar       The registrar template</span>
<a name="l00023"></a>00023 <span class="comment">        */</span>
<a name="l00024"></a>00024         <span class="keywordtype">void</span> <a class="code" href="classMTMacroFct.html#a0">create</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> &amp;prototype, <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> &amp;macro, <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> &amp;description, <a class="code" href="classMTCompilerI.html">MTCompilerI</a> *pCompiler, <a class="code" href="classMTRegistrarI.html">MTRegistrarI</a> *pRegistrar ) <span class="keywordflow">throw</span>(<a class="code" href="classMTChainedExceptions.html">MTParserException</a>);
<a name="l00025"></a>00025         
<a name="l00026"></a>00026         <span class="comment">// MTFunctionI implementation</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028         <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>* <a class="code" href="classMTMacroFct.html#a1">getSymbol</a>();
<a name="l00029"></a>00029         <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>* <a class="code" href="classMTMacroFct.html#a2">getHelpString</a>();
<a name="l00030"></a>00030         <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>* <a class="code" href="classMTMacroFct.html#a3">getDescription</a>();
<a name="l00031"></a>00031         <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classMTMacroFct.html#a4">getNbArgs</a>();
<a name="l00032"></a>00032         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classMTMacroFct.html#a5">doLateInitialization</a>(<span class="keyword">class</span> <a class="code" href="classMTCompilerI.html">MTCompilerI</a> *pCompiler, <span class="keyword">class</span> <a class="code" href="classMTRegistrarI.html">MTRegistrarI</a> *pRegistrar) <span class="keywordflow">throw</span>(<a class="code" href="classMTChainedExceptions.html">MTParserException</a>);
<a name="l00033"></a>00033         <span class="keyword">virtual</span> <a class="code" href="MTParserPublic_8h.html#a8">MTDOUBLE</a> <a class="code" href="classMTMacroFct.html#a6">evaluate</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nbArgs, <span class="keyword">const</span> <a class="code" href="MTParserPublic_8h.html#a8">MTDOUBLE</a> *pArg);           
<a name="l00034"></a>00034         <span class="keyword">virtual</span> <a class="code" href="classMTFunctionI.html">MTFunctionI</a>* <a class="code" href="classMTMacroFct.html#a7">spawn</a>();
<a name="l00035"></a>00035 
<a name="l00036"></a>00036         <a class="code" href="classMTMacroFct.html#a8">MTMacroFct</a>();
<a name="l00037"></a>00037         <a class="code" href="classMTMacroFct.html#a8">MTMacroFct</a>(<span class="keyword">const</span> <a class="code" href="classMTMacroFct.html">MTMacroFct</a> &amp;obj);
<a name="l00038"></a>00038         <a class="code" href="classMTMacroFct.html#a10">~MTMacroFct</a>();
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">private</span>:
<a name="l00041"></a>00041 
<a name="l00042"></a>00042         <span class="comment">// free memory</span>
<a name="l00043"></a>00043         <span class="keywordtype">void</span> clean();
<a name="l00044"></a>00044         <span class="comment"></span>
<a name="l00045"></a>00045 <span class="comment">        /** Parse a macro prototype string</span>
<a name="l00046"></a>00046 <span class="comment">        </span>
<a name="l00047"></a>00047 <span class="comment">                Syntax: macro(arg1, arg2, arg3...)</span>
<a name="l00048"></a>00048 <span class="comment"></span>
<a name="l00049"></a>00049 <span class="comment">                @param  prototype               The prototype string</span>
<a name="l00050"></a>00050 <span class="comment">                @param  syntax                  The current syntax</span>
<a name="l00051"></a>00051 <span class="comment">                @param  name                    [out] The detected macro name</span>
<a name="l00052"></a>00052 <span class="comment">                @param  args                    [out] The detected macro arguments</span>
<a name="l00053"></a>00053 <span class="comment">        */</span>
<a name="l00054"></a>00054         <span class="keywordtype">void</span> parsePrototype(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> &amp;prototype, <span class="keyword">const</span> <a class="code" href="structMTSyntax.html">MTSyntax</a> &amp;syntax, <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> &amp;name, std::vector&lt;MTSTRING&gt; &amp;args) <span class="keywordflow">throw</span>(<a class="code" href="classMTChainedExceptions.html">MTParserException</a>);
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="keyword">private</span>:
<a name="l00057"></a>00057         
<a name="l00058"></a>00058         <span class="keyword">class </span><a class="code" href="classMTParser.html">MTParser</a> *m_pParser;                      
<a name="l00059"></a>00059         <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> m_description;
<a name="l00060"></a>00060         <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> m_helpString;
<a name="l00061"></a>00061         <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> m_symbol;
<a name="l00062"></a>00062         <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> m_macro;
<a name="l00063"></a>00063         <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> m_prototype;
<a name="l00064"></a>00064         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_nbArgs;  
<a name="l00065"></a>00065         <a class="code" href="MTParserPublic_8h.html#a8">MTDOUBLE</a> *m_pVars;
<a name="l00066"></a>00066         <span class="keywordtype">bool</span> m_isCreated;
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 };
<a name="l00069"></a>00069 
<a name="l00070"></a>00070 
<a name="l00071"></a>00071 <span class="preprocessor">#endif</span>
</pre></div><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