Hello, today I found a great mathematical expression parser at http://www.yann-ollivier.org/mathlib/mathexpr.php
But there is a problem, it is written in C. I know C can be used in C++ but I do not understand the code in C. I'm wondering if there is a program that can convert c to c++ or if anyone would be willing to do it?
The total amount of code that needs to be converted is about 1400 lines so changing it by hand might be tough.
#include <stdio.h>
#include "mathexpr.h"
#include <iostream>
usingnamespace std;
int main()
{
// The number that the variable "x" will point to
double x;
// Creates a variable named "x" and which value will be x
RVar xvar ( "x" , &x );
// Asks for a fomula depending on the variable x, e.g. "sin 2x"
char s[500]="";
cout << "Enter a formula depending on the variable x:\n";
gets(s);
// Creates an operation with this formula. The operation depends on one
// variable, which is xvar; the third argument is an array of pointers
// to variables; the previous argument is its size
RVar* vararray[1]; vararray[0]=&xvar;
ROperation op ( s, 1, vararray );
// Affects (indirectly) a value to xvar
x=3;
// Printfs the value of the formula for x=3;
printf("%s = %G for x=3\n\n", op.Expr(), op.Val() );
cin.get();
return 0;
}
double x; // this is your variable for your equation.
RVar xvar ( "x" , &x ); // RVar seems to be keeping a reference to your variable for the engine
// vararray seems to be an array of variables to be operated on
RVar* vararray[1];
// In this example kust one variable is being put in the array
vararray[0]=&xvar;
// The list of variables is now being sent to the expression processing engine.
// The s is a string expression in x such as "x^2-x*4+2"
ROperation op ( s, 1, vararray );
// No the op object can be queried for the input expression(op.Expr())
and the output value (op.Val()) that will depend on the input value of x
x=3;
printf("%s = %G for x=3\n\n", op.Expr(), op.Val() );
// the printf() statement is the equivalent of this:
std::cout << op.Expr() << " = " << op.Val() << " for x=" << x << "\n\n";