-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Carlo Bernaschina edited this page May 10, 2014
·
7 revisions
Welcome to the MathParseKit wiki!
With MathParseKit is easy to parametrize part of you application.
A simple example:
#include <iostream>
#include <MParser.h>
using namespace mpk;
int wmain(int argc, wchar_t* argv[])
{
//Check if parameter is present
if (argc < 2) return 0;
//Initialize praser
MParser parser;
//Parse Parameter
MFunction *f = parser.ParseFunction(argv[1]);
if (f == NULL)
{
std::wcout << "Error " << parser.GetLastError() << " at Position " << parser.GetErrorPosition();
return 0;
}
//Get Variables inside the function
MVariablesList list;
f->GetVariablesList(&list);
//Ask for Variables values
for (int i = 0; i<list.Count(); i++)
{
std::wcout << L"Variable " << list.GetItem(i)->GetName() << " = ";
double value;
std::wcin >> value;
list.GetItem(i)->SetValue(value);
}
//Solve
MFunction *ret = f->Solve(&list);
//Check solution type
if (ret->GetType() == MF_CONST)
{
std::cout << "Result = " << ((MFConst*)ret)->GetValue();
}
//Release objects
f->Release();
ret->Release();
return 0;
}
Execution:
>>MPKExample.exe 5*2
Result = 10
Other Execution:
>>MPKExample.exe 2*x+y
Variable x = 5
Variable y = 1
Result = 11
Here is the list of all supported operators, functions, and constants.