Commit 63a788b6 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Remove mathexpr test, not working and replaced by test_operator

parent dec4bc95
Pipeline #99134 passed with stages
in 12 minutes and 46 seconds
...@@ -13,6 +13,5 @@ add_subdirectory(TEST_SHADOK_LIST) ...@@ -13,6 +13,5 @@ add_subdirectory(TEST_SHADOK_LIST)
add_subdirectory(TEST_C_ENUM) add_subdirectory(TEST_C_ENUM)
add_subdirectory(TEST_VAR_DECL) add_subdirectory(TEST_VAR_DECL)
add_subdirectory(TEST_VAR_DECL_STRING) add_subdirectory(TEST_VAR_DECL_STRING)
add_subdirectory(TEST_MATH_EXPR)
add_subdirectory(TEST_OPERATOR) add_subdirectory(TEST_OPERATOR)
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
# compileLibTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser)
compileMainTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser main_test.cpp)
# Only when the test will be OK
# compileTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser main_test.cpp var_decl.txt)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
// For the option parsing
#include "OptionParser.h"
#include "string_utils.h"
// To get the generated parser
#include "PTestMathExprParserFull.h"
using namespace std;
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser createOptionParser(){
OptionParser parser(true, __PROGRAM_VERSION__);
parser.setExampleLongOption("use_parser --input=fileName.shadok");
parser.setExampleShortOption("use_parser -i fileName.shadok");
parser.addOption("input", "i", OptionType::FILENAME, true, "input shadok file name");
return parser;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAddToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
std::string exprStr = gExpr(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return true;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd2ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
PExpr_getVecOperand(exprAdd).push_back(varC);
std::string exprStr = gExpr(exprAdd);
std::cout << "testExprAdd2ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return true;
}
///Print the shadok file
/** @param fileName : file to be parsed
* @return true on success, false otherwise
*/
bool printVarDeclFile(const std::string & fileName){
//We create the parser
PTestMathExprParser parser;
if(!parser.load(fileName)){
cerr << "printVarDeclFile : can't load file '"<<fileName<<"'" << endl;
return false;
}
//We get the parsed internal representation
PExpr & source = parser.getPExprE();
std::string exprStr = gExpr(source);
std::cout << "printVarDeclFile : exprStr = '"<<exprStr<<"'" << std::endl;
return true;
}
int main(int argc, char** argv){
OptionParser optionParser = createOptionParser();
optionParser.parseArgument(argc, argv);
const OptionMode & defaultMode = optionParser.getDefaultMode();
std::string fileName("");
defaultMode.getValue(fileName, "input");
bool b(testExprAddToString());
b &= testExprAdd2ToString();
b &= printVarDeclFile(fileName);
if(b){return 0;}
else{return -1;}
}
///Type of the expression
Enum PExprType{
VAR
ADD
MULT
};
///Describes a simple mathematic expression
Class PExpr{
///Type of the expression
PExprType::PExprType type;
///Name of the variable
String varName[csVariableName];
///Vector of operand
Vector(PExpr) vecOperand;
}
Graph gExprVarName(PExpr e){
e.varName e.type=PExprType::VAR
}
///Parses a mathematic expression
Graph gExpr(PExpr e){
e.vecOperand.pushBack(gExprVarName())
REPEAT{
OR{
"*" e.vecOperand.pushBackFirst(e) e.type=PExprType::MULT e.varName="toto"
OR{
"(" e.vecOperand.pushBack(gExpr()) ")",
e.vecOperand.pushBack(gExpr())
},
"+" e.vecOperand.pushBackFirst(e) e.type=PExprType::ADD e.varName="toto"
OR{
"(" e.vecOperand.pushBack(gExpr()) ")",
e.vecOperand.pushBack(gExpr())
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment