#include #include #include #include "PFunctionHandler.h" //----------------------------------------------------- void syntax() { std::cout << std::endl << "spirit_fcn_test [--file [--debug]] | [--help]"; std::cout << std::endl << " without arguments: interactive mode"; std::cout << std::endl << " --file : 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(std::vector &lines) { 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 ... "; std::cout << std::endl << " Parameter block:"; std::cout << std::endl << " PAR ... "; std::cout << std::endl << " Function Block:"; std::cout << std::endl << " FUNCTION"; std::cout << std::endl << " fun1 = "; std::cout << std::endl << " fun2 = "; std::cout << std::endl << " ..."; std::cout << std::endl << " funX = "; 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 { std::cout << ">> "; std::cin.getline(str, sizeof(str)); if (!strcmp(str, ".q")) done = true; else lines.push_back(str); } while (!done); } //----------------------------------------------------- int main(int argc, char *argv[]) { bool inputFile = false; bool debug = false; if (argc > 4) { syntax(); return 0; } else if (argc == 2) { syntax(); return 0; } else if (argc >= 3) { if (strcmp(argv[1], "--file")) { syntax(); return 0; } else { inputFile = true; } if (argc == 4) { if (strcmp(argv[3], "--debug")) { syntax(); return 0; } else { debug = true; } } } std::unique_ptr fcnHandler; if (inputFile) { fcnHandler = std::make_unique(argv[2], debug); } else { std::vector lines; handle_input(lines); fcnHandler = std::make_unique(lines); } if (fcnHandler == 0) { std::cout << std::endl << "Couldn't invoke function handler, sorry ..." << std::endl; return 0; } bool go_on = fcnHandler->IsValid(); if (go_on) { std::cout << std::endl << "will do the parsing ..."; if (fcnHandler->DoParse()) { if (!debug) { std::cout << std::endl << "will do the evaluation ..."; for (unsigned int i=0; iGetNoOfFuncs(); i++) std::cout << std::endl << "FUN" << fcnHandler->GetFuncNo(i) << " = " << fcnHandler->Eval(fcnHandler->GetFuncNo(i)); } } } return 1; }