1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-18 23:37:05 +01:00

general cleaning/consolidation of the math interpreter

This commit is contained in:
2014-02-06 18:07:27 +00:00
parent 50d21ae904
commit ce6469cdd7
14 changed files with 1067 additions and 57 deletions

View File

@ -14,11 +14,16 @@ if CXX_INTEL
endif
endif
noinst_PROGRAMS = \
exMathCompiler
noinst_PROGRAMS = \
exMathInterpreter \
exCompiledDoubleFunction
exMathCompiler_SOURCES = exMathCompiler.cpp
exMathCompiler_CFLAGS = -g -O2
exMathCompiler_LDFLAGS = -L../latan/.libs -llatan
exMathInterpreter_SOURCES = exMathInterpreter.cpp
exMathInterpreter_CFLAGS = -g -O2
exMathInterpreter_LDFLAGS = -L../latan/.libs -llatan
exCompiledDoubleFunction_SOURCES = exCompiledDoubleFunction.cpp
exCompiledDoubleFunction_CFLAGS = -g -O2
exCompiledDoubleFunction_LDFLAGS = -L../latan/.libs -llatan
ACLOCAL_AMFLAGS = -I .buildutils/m4

View File

@ -0,0 +1,31 @@
#include <iostream>
#include <iomanip>
#include <latan/CompiledFunction.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char* argv[])
{
string source;
if (argc != 2)
{
cerr << "usage: " << argv[0] << " <function>" << endl;
return EXIT_FAILURE;
}
source = argv[1];
CompiledDoubleFunction f(1, source);
cout << "-- Program:" << endl << f << endl;
cout << "-- Values:" << endl;
for (double x = 0.0; x < 10.0; x += 0.5)
{
cout << "f(" << right << setw(6) << strFrom<double>(x) << ")= "
<< f(x) << endl;
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,75 @@
#include <iostream>
#include <latan/Math.hpp>
#include <latan/MathInterpreter.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char* argv[])
{
string source;
if (argc != 2)
{
cerr << "usage: " << argv[0] << " <program>" << endl;
return EXIT_FAILURE;
}
source = argv[1];
MathInterpreter interpreter(source);
RunContext context;
cout << "-- Source code:" << endl << source << endl << endl;
interpreter.compile();
cout << "-- Abstract Syntax Tree:" << endl;
if (interpreter.getAST())
{
cout << *interpreter.getAST() << endl;
}
else
{
cout << "<null>" << endl << endl;
}
cout << "-- Program:" << endl << interpreter << endl;
StdMath::addStdMathFunc(context.fTable);
interpreter(context);
if (!context.dStack.empty())
{
cout << "-- Result: " << context.dStack.top() << endl;
}
return EXIT_SUCCESS;
}
/*int main(void)
{
ASCIIFile F;
DMat A,B;
F.Open("foo.boot",FileMode::Read);
A = F.Read<DMat>("bla");
B = F.Read<DMat>("bli");
cout << A << endl;
cout << B << endl;
cout << A*B << endl;
return EXIT_SUCCESS;
}*/
/*
int main(void)
{
DMat m(2,2);
m(0,6) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
cout << "Here is the matrix m:\n" << m << endl;
DVec v(2);
v(0) = 4;
v(1) = v(0) - 1;
cout << "Here is the vector v:\n" << v << endl;
}
*/