Click here to Skip to main content
15,891,136 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.
// MTPluginIDL.idl : IDL source for MTPluginIDL.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (MTPluginIDL.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
	[
		object,
		uuid(C4DAF5B0-EE0F-4014-89E6-948FB9F79B85),
		dual,
		helpstring("IMTPlugin Interface"),
		pointer_default(unique)
	]
	interface IMTPlugin : IDispatch
	{
		[id(1), helpstring("method getNbConsts")] HRESULT getNbConsts([out] int *pNbConsts);
		[id(2), helpstring("method getConst")] HRESULT getConst([in] int id, [out] BSTR *name, [out] double *pVal);
		[id(3), helpstring("method getNbFuncs")] HRESULT getNbFuncs([out] int *pNbFuncs);
		[id(4), helpstring("method getFuncSymbol")] HRESULT getFuncSymbol([in] int id, [out] BSTR *symbol);
		[id(5), helpstring("method getFuncHelpString")] HRESULT getFuncHelpString([in] int id, [out] BSTR *helpString);
		[id(6), helpstring("method getFuncDescription")] HRESULT getFuncDescription([in] int id, [out] BSTR *description);
		[id(7), helpstring("method isFuncConstant")] HRESULT isFuncConstant([in] int id, [out] int *pConstant);
		[id(8), helpstring("method getFuncNbArgs")] HRESULT getFuncNbArgs([in] int id, [out] int *pNbArgs);
		[id(9), helpstring("method evaluateFunc")] HRESULT evaluateFunc([in] int id, [in] int nbArgs, [in, size_is (nbArgs)] const double *pArg, [out] double *pResult);
		[id(10), helpstring("method getNbOps")] HRESULT getNbOps([out] int *pNbOps);
		[id(11), helpstring("method getOpPrecedence")] HRESULT getOpPrecedence([in] int id, [out] int *pPrecedence);
		[id(12), helpstring("method isOpConstant")] HRESULT isOpConstant([in] int id, [out] int *pConstant);
		[id(13), helpstring("method getOpSymbol")] HRESULT getOpSymbol([in] int id, [out] BSTR *symbol);
		[id(14), helpstring("method getOpHelpString")] HRESULT getOpHelpString([in] int id, [out] BSTR *helpString);
		[id(15), helpstring("method getOpDescription")] HRESULT getOpDescription([in] int id, [out] BSTR *description);		
		[id(16), helpstring("method isOneArgOp")] HRESULT isOneArgOp([in] int id, [out] int *pOneArg);
		[id(17), helpstring("method evaluateOp")] HRESULT evaluateOp([in] int id, [in] int nbArgs, [in, size_is (nbArgs)] const double *pArg, [out] double *pResult);
	};

[
	uuid(5291C973-5DC2-4D1D-B980-4C6A3A94433D),
	version(1.0),
	helpstring("MTPluginIDL 1.0 Type Library")
]
library MTPLUGINIDLLib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb");

	[
		uuid(E58C85C4-DF60-49B4-AB82-B44CE7E9C348),
		helpstring("MTPlugin Class")
	]
	coclass MTPlugin
	{
		[default] interface IMTPlugin;
	};
};

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