improved bracket handling in function string generation.
This commit is contained in:
parent
c7b0d2b40f
commit
65066596e8
@ -597,6 +597,7 @@ void PFunction::EvalTreeForString(tree_parse_info<> info)
|
|||||||
void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
||||||
{
|
{
|
||||||
static Int_t termOp = 0;
|
static Int_t termOp = 0;
|
||||||
|
static bool funcFlag = false;
|
||||||
|
|
||||||
if (i->value.id() == PFunctionGrammar::realID) {
|
if (i->value.id() == PFunctionGrammar::realID) {
|
||||||
assert(i->children.size() == 0);
|
assert(i->children.size() == 0);
|
||||||
@ -627,7 +628,8 @@ void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
|||||||
assert(i->children.size() == 0);
|
assert(i->children.size() == 0);
|
||||||
fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
|
fFuncString += boost::algorithm::trim_copy(std::string(i->value.begin(), i->value.end())).c_str();
|
||||||
} else if (i->value.id() == PFunctionGrammar::functionID) {
|
} else if (i->value.id() == PFunctionGrammar::functionID) {
|
||||||
assert(i->children.size() == 3);
|
assert(i->children.size() == 3);
|
||||||
|
funcFlag = true;
|
||||||
fFuncString += std::string(i->value.begin(), i->value.end()).c_str(); // keep function name
|
fFuncString += std::string(i->value.begin(), i->value.end()).c_str(); // keep function name
|
||||||
fFuncString += "(";
|
fFuncString += "(";
|
||||||
// '(', expression, ')'
|
// '(', expression, ')'
|
||||||
@ -635,6 +637,7 @@ void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
|||||||
fFuncString += ")";
|
fFuncString += ")";
|
||||||
} else if (i->value.id() == PFunctionGrammar::powerID) {
|
} else if (i->value.id() == PFunctionGrammar::powerID) {
|
||||||
assert(i->children.size() == 5);
|
assert(i->children.size() == 5);
|
||||||
|
funcFlag = true;
|
||||||
fFuncString += std::string(i->value.begin(), i->value.end()).c_str(); // keep function name
|
fFuncString += std::string(i->value.begin(), i->value.end()).c_str(); // keep function name
|
||||||
fFuncString += "(";
|
fFuncString += "(";
|
||||||
// '(', expression, ',' expression, ')'
|
// '(', expression, ',' expression, ')'
|
||||||
@ -655,15 +658,21 @@ void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
|||||||
assert(i->children.size() == 2);
|
assert(i->children.size() == 2);
|
||||||
EvalTreeForStringExpression(i->children.begin());
|
EvalTreeForStringExpression(i->children.begin());
|
||||||
fFuncString += " / ";
|
fFuncString += " / ";
|
||||||
fFuncString += "(";
|
if (((i->children.begin()+1)->children.size()>1) &&
|
||||||
|
((i->children.begin()+1)->value.id() != PFunctionGrammar::functionID) &&
|
||||||
|
(i->children.begin()+1)->value.id() != PFunctionGrammar::powerID) // check if denominator is non-trivial and not a function
|
||||||
|
fFuncString += "(";
|
||||||
EvalTreeForStringExpression(i->children.begin()+1);
|
EvalTreeForStringExpression(i->children.begin()+1);
|
||||||
fFuncString += ")";
|
if (((i->children.begin()+1)->children.size()>1) &&
|
||||||
|
((i->children.begin()+1)->value.id() != PFunctionGrammar::functionID) &&
|
||||||
|
(i->children.begin()+1)->value.id() != PFunctionGrammar::powerID) // check if denominator is non-trivial and not a function
|
||||||
|
fFuncString += ")";
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
termOp--;
|
termOp--;
|
||||||
} else if (i->value.id() == PFunctionGrammar::expressionID) {
|
} else if (i->value.id() == PFunctionGrammar::expressionID) {
|
||||||
if (termOp > 0)
|
if ((termOp > 0) && !funcFlag)
|
||||||
fFuncString += "(";
|
fFuncString += "(";
|
||||||
if (*i->value.begin() == '+') {
|
if (*i->value.begin() == '+') {
|
||||||
assert(i->children.size() == 2);
|
assert(i->children.size() == 2);
|
||||||
@ -678,8 +687,9 @@ void PFunction::EvalTreeForStringExpression(iter_t const& i)
|
|||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
if (termOp > 0)
|
if ((termOp > 0) && !funcFlag)
|
||||||
fFuncString += ")";
|
fFuncString += ")";
|
||||||
|
funcFlag = false;
|
||||||
} else if (i->value.id() == PFunctionGrammar::assignmentID) {
|
} else if (i->value.id() == PFunctionGrammar::assignmentID) {
|
||||||
assert(i->children.size() == 3);
|
assert(i->children.size() == 3);
|
||||||
EvalTreeForStringExpression(i->children.begin());
|
EvalTreeForStringExpression(i->children.begin());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user