test spirit parser moved from classic to X3.
All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 19s

This commit is contained in:
2025-12-27 12:32:01 +01:00
parent 3442ca7b62
commit 5d3981d8b2
11 changed files with 1072 additions and 1296 deletions

View File

@@ -2,44 +2,43 @@
#include <iostream>
#include <string>
using namespace std;
#include "PFunctionHandler.h"
//-----------------------------------------------------
void syntax()
{
cout << endl << "spirit_fcn_test [--file <filename> [--debug]] | [--help]";
cout << endl << " without arguments: interactive mode";
cout << endl << " --file <filename>: function block etc. from file";
cout << endl << " --help: this help";
cout << endl << " --debug: will print the ast tree only (no evaluatio)";
cout << endl << endl;
std::cout << std::endl << "spirit_fcn_test [--file <filename> [--debug]] | [--help]";
std::cout << std::endl << " without arguments: interactive mode";
std::cout << std::endl << " --file <filename>: function block etc. from file";
std::cout << std::endl << " --help: this help";
std::cout << std::endl << " --debug: will print the ast tree only (no evaluation)";
std::cout << std::endl << std::endl;
}
//-----------------------------------------------------
void handle_input(vector<string> &lines)
void handle_input(std::vector<std::string> &lines)
{
cout << endl << "will handle input ...";
cout << endl << "you should provide a PAR, a MAP, and a FUNCTION block";
cout << endl << " Map block:";
cout << endl << " MAP <map1> <map2> ... <mapM>";
cout << endl << " Parameter block:";
cout << endl << " PAR <par1> <par2> ... <parN>";
cout << endl << " Function Block:";
cout << endl << " FUNCTION";
cout << endl << " fun1 = <function1>";
cout << endl << " fun2 = <function2>";
cout << endl << " ...";
cout << endl << " funX = <functionX>";
cout << endl << " END";
cout << endl << "to get out of the input handle type '.q'";
cout << endl;
std::cout << std::endl << "will handle input ...";
std::cout << std::endl << "you should provide a PAR, a MAP, and a FUNCTION block";
std::cout << std::endl << " Map block:";
std::cout << std::endl << " MAP <map1> <map2> ... <mapM>";
std::cout << std::endl << " Parameter block:";
std::cout << std::endl << " PAR <par1> <par2> ... <parN>";
std::cout << std::endl << " Function Block:";
std::cout << std::endl << " FUNCTION";
std::cout << std::endl << " fun1 = <function1>";
std::cout << std::endl << " fun2 = <function2>";
std::cout << std::endl << " ...";
std::cout << std::endl << " funX = <functionX>";
std::cout << std::endl << " END";
std::cout << std::endl << "to get out of the input handle type '.q'";
std::cout << std::endl;
bool done = false;
char str[128];
do {
cout << ">> ";
cin.getline(str, sizeof(str));
std::cout << ">> ";
std::cin.getline(str, sizeof(str));
if (!strcmp(str, ".q"))
done = true;
else
@@ -76,39 +75,33 @@ int main(int argc, char *argv[])
}
}
PFunctionHandler *fcnHandler = 0;
std::unique_ptr<PFunctionHandler> fcnHandler;
if (inputFile) {
fcnHandler = new PFunctionHandler(argv[2], debug);
fcnHandler = std::make_unique<PFunctionHandler>(argv[2], debug);
} else {
vector<string> lines;
std::vector<std::string> lines;
handle_input(lines);
fcnHandler = new PFunctionHandler(lines);
fcnHandler = std::make_unique<PFunctionHandler>(lines);
}
if (fcnHandler == 0) {
cout << endl << "Couldn't invoke function handler, sorry ..." << endl;
std::cout << std::endl << "Couldn't invoke function handler, sorry ..." << std::endl;
return 0;
}
bool go_on = fcnHandler->IsValid();
if (go_on) {
cout << endl << "will do the parsing ...";
std::cout << std::endl << "will do the parsing ...";
if (fcnHandler->DoParse()) {
if (!debug) {
cout << endl << "will do the evaluation ...";
std::cout << std::endl << "will do the evaluation ...";
for (unsigned int i=0; i<fcnHandler->GetNoOfFuncs(); i++)
cout << endl << "FUN" << fcnHandler->GetFuncNo(i) << " = " << fcnHandler->Eval(fcnHandler->GetFuncNo(i));
std::cout << std::endl << "FUN" << fcnHandler->GetFuncNo(i) << " = " << fcnHandler->Eval(fcnHandler->GetFuncNo(i));
}
}
}
// clean up
if (fcnHandler) {
delete fcnHandler;
fcnHandler = 0;
}
return 1;
}