Skip to content

Commit

Permalink
Support for scanning things like Ln now added
Browse files Browse the repository at this point in the history
-Now uses switch statement for adding operators from buffer
-Failing to condense inner formulas that have more than one operation right now with cannot dereference value-initialized deque iterator exception
  • Loading branch information
BlazesRus committed Nov 11, 2020
1 parent 87df2cf commit 364839e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 51 deletions.
21 changes: 21 additions & 0 deletions ExprFormulaTester/ExprFormulaTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,25 @@ int main()
std::cout << " = " << AltFormTest.ToString() << std::endl;
AltFormTest.EvaluateOperations();
std::cout << " = " << AltFormTest.ToString() << std::endl;

AltFormTest = "9.0 thBaseLog 4";
std::cout << "(MediumDecFormula) " << AltFormTest.ToString() << std::endl;
AltFormTest.ReplaceVariablesWithValues(ValueDefinitions);
std::cout << " = " << AltFormTest.ToString() << std::endl;
AltFormTest.EvaluateOperations();
std::cout << " = " << AltFormTest.ToString() << std::endl;

AltFormTest = "(x+1)^(5+4/0.5-2)";
std::cout << "(MediumDecFormula) " << AltFormTest.ToString() << std::endl;
AltFormTest.ReplaceVariablesWithValues(ValueDefinitions);
std::cout << " = " << AltFormTest.ToString() << std::endl;
AltFormTest.EvaluateOperations();
std::cout << " = " << AltFormTest.ToString() << std::endl;

AltFormTest = "(x+1)^(5+4*0.5-2)";
std::cout << "(MediumDecFormula) " << AltFormTest.ToString() << std::endl;
AltFormTest.ReplaceVariablesWithValues(ValueDefinitions);
std::cout << " = " << AltFormTest.ToString() << std::endl;
AltFormTest.EvaluateOperations();
std::cout << " = " << AltFormTest.ToString() << std::endl;
}
3 changes: 2 additions & 1 deletion GlobalCode/Databases/ElementType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace BlazesRusCode
OR,
LN,
LOGTEN,
BaseNLog
BaseNLog,
BuildInVariable
};
}
62 changes: 35 additions & 27 deletions GlobalCode/Databases/MediumDecFormula.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
$ = XOR (bitwise XOR operation)(Not fully supported by MediumDec yet)
++Prefix; --Prefix;
(Bitwise operators--Not fully supported by MediumDec yet)&, |
SqrtOf = Square Root of (applied to right value) (Not scanned yet but application code inside)
thRootOf = Nth Root of (left value is equal to N; applied to right value) (Not scanned yet but application code inside)
SqrtOf = Square Root of (applied to right value)
thRootOf = Nth Root of (left value is equal to N; applied to right value)
PowerOf = Power of
Ln = Natural log function
thBaseLog = Base N Log function of right value
LogTen = Log base 10 function of right value
*/
//Unsupported Operators/Functions(for later)
/*
++Postfix; --Postfix (Need to update to code changes)
PowerOf = (for scanning PowerOf instead of ^)
? = TernaryOperator(Not stored/evaluated yet)
Assignment operators not supported
*/
Expand Down Expand Up @@ -363,10 +365,10 @@ namespace BlazesRusCode
targetResult = KeyedElemVal.value();
FormDRef.NumMap.insert_or_assign(CurrentVal->first, targetResult);//ElementValues.at(CurString));
}
else
{
std::cout << "Failed to replace variable named " << CurString << " with value data" << std::endl;
}
//else
//{
// std::cout << "Failed to replace variable named " << CurString << " with value data" << std::endl;
//}
}
}
}
Expand Down Expand Up @@ -400,18 +402,6 @@ namespace BlazesRusCode
if (CurrentVal->second.ElementCat == FormulaElementType::Formula)//FormulaDetected
{
ReplaceVariablesWithValues(ElementValues, CurrentVal->second.Index);
//if (Data.at(CurrentVal->second.Index).size() == 1)
//{
// FormData& ContainedFormulaElement = Data.at(CurrentVal->first);
// auto FirstElement = ContainedFormulaElement.front();
// /*
// if(ContainedFormulaElement.ElementCat == FormulaElementType::Num)
// {
// }
// */
// //targetResult = ContainedFormulaElement.;
// //FormDRef.ReplaceFormVal(CurrentVal->first, targetResult);
//}
}
else if (CurrentVal->second.ElementCat == FormulaElementType::Variable)//Swap Variable with values
{
Expand All @@ -423,10 +413,10 @@ namespace BlazesRusCode
targetResult = KeyedElemVal.value();
FormDRef.NumMap.insert_or_assign(CurrentVal->first, targetResult);//ElementValues.at(CurString));
}
else
{
std::cout << "Failed to replace variable named " << CurString << " with value data" << std::endl;
}
//else
//{
// std::cout << "Failed to replace variable named " << CurString << " with value data" << std::endl;
//}
}
}
}
Expand Down Expand Up @@ -522,11 +512,20 @@ namespace BlazesRusCode
strBuffer += "^";
break;
case FormulaElementType::Sqrt:
strBuffer += " SqrtOf";
strBuffer += "SqrtOf";
break;
case FormulaElementType::NthRoot:
strBuffer += "thRootOf";
break;
case FormulaElementType::LOGTEN:
strBuffer += "LogTen";
break;
case FormulaElementType::LN:
strBuffer += "Ln";
break;
case FormulaElementType::BaseNLog:
strBuffer += "thBaseLog";
break;
case FormulaElementType::Rem:
strBuffer += "%";
break;
Expand Down Expand Up @@ -575,7 +574,7 @@ namespace BlazesRusCode
case FormulaElementType::Formula:
strBuffer += "(";
indexBuffer = CurrentVal->second.Index;
RecursivelyAddToString(strBuffer, indexBuffer);//CurrentVal->second.Index);
RecursivelyAddToString(strBuffer, indexBuffer);
strBuffer += ")";
break;
case FormulaElementType::Num:
Expand Down Expand Up @@ -636,11 +635,20 @@ namespace BlazesRusCode
strBuffer += "^";
break;
case FormulaElementType::Sqrt:
strBuffer += " SqrtOf";
strBuffer += "SqrtOf";
break;
case FormulaElementType::NthRoot:
strBuffer += "thRootOf";
break;
case FormulaElementType::LOGTEN :
strBuffer += "LogTen";
break;
case FormulaElementType::LN:
strBuffer += "Ln";
break;
case FormulaElementType::BaseNLog :
strBuffer += "thBaseLog";
break;
case FormulaElementType::Rem:
strBuffer += "%";
break;
Expand Down
57 changes: 34 additions & 23 deletions GlobalCode/Databases/VariableFormula.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ namespace BlazesRusCode
public:
class DLL_API FormElement
{
protected:

public:
//0 = Num; 1 = Variable; 2 = Formula; 3 = true; 4 = false ; 5 >= Op;
FormulaElementType ElementCat;
Expand Down Expand Up @@ -512,6 +510,15 @@ namespace BlazesRusCode
case FormulaElementType::NthRoot:
strBuffer += "thRootOf";
break;
case FormulaElementType::LOGTEN:
strBuffer += "LogTen";
break;
case FormulaElementType::LN:
strBuffer += "Ln";
break;
case FormulaElementType::BaseNLog:
strBuffer += "thBaseLog";
break;
case FormulaElementType::Rem:
strBuffer += "%";
break;
Expand Down Expand Up @@ -586,34 +593,38 @@ namespace BlazesRusCode
}
else if (ScanType == 3)
{
this->AddVariable(strBuffer, targetFormSegment);
if (strBuffer == "Ln") { targetFormSegment.AddOp(FormulaElementType::LN); }
else if (strBuffer == "LogTen") { targetFormSegment.AddOp(FormulaElementType::LOGTEN); }
else if (strBuffer == "thBaseLog") { targetFormSegment.AddOp(FormulaElementType::BaseNLog); }
else if (strBuffer == "SqrtOf") { targetFormSegment.AddOp(FormulaElementType::Sqrt); }
else if (strBuffer == "thRootOf") { targetFormSegment.AddOp(FormulaElementType::NthRoot); }
else if (strBuffer == "PowerOf") { targetFormSegment.AddOp(FormulaElementType::Pow); }
//BuildInVariable detection here as well(for derived formula class)
else
this->AddVariable(strBuffer, targetFormSegment);
}
else if (ScanType == 4)
{
targetFormSegment.AddNum(strBuffer);
}
else if (ScanType == 1)
{
if (strBuffer == "+") { targetFormSegment.AddOp(FormulaElementType::Add); }
else if (strBuffer == "-") { targetFormSegment.AddOp(FormulaElementType::Sub); }
else if (strBuffer == "*") { targetFormSegment.AddOp(FormulaElementType::Mult); }
else if (strBuffer == "/") { targetFormSegment.AddOp(FormulaElementType::Div); }
else if (strBuffer == "%") { targetFormSegment.AddOp(FormulaElementType::Rem); }
else if (strBuffer == "^") { targetFormSegment.AddOp(FormulaElementType::Pow); }
else if (strBuffer == "SqrtOf") { targetFormSegment.AddOp(FormulaElementType::Sqrt); }
else if (strBuffer == "==") { targetFormSegment.AddOp(FormulaElementType::Equal); }
else if (strBuffer == "!=") { targetFormSegment.AddOp(FormulaElementType::NotEqual); }
else if (strBuffer == "<") { targetFormSegment.AddOp(FormulaElementType::LessThan); }
else if (strBuffer == "<=") { targetFormSegment.AddOp(FormulaElementType::LessOrEqual); }
else if (strBuffer == ">") { targetFormSegment.AddOp(FormulaElementType::GreaterThan); }
else if (strBuffer == ">=") { targetFormSegment.AddOp(FormulaElementType::GreaterOrEqual); }
else if (strBuffer == "&&") { targetFormSegment.AddOp(FormulaElementType::AND); }
else if (strBuffer == "||") { targetFormSegment.AddOp(FormulaElementType::OR); }
else if (strBuffer == "thRootOf") { targetFormSegment.AddOp(FormulaElementType::NthRoot); }
else if (strBuffer == "PowerOf") { targetFormSegment.AddOp(FormulaElementType::Pow); }
else if (strBuffer == "&") { targetFormSegment.AddOp(FormulaElementType::BitwiseAND); }
else if (strBuffer == "|") { targetFormSegment.AddOp(FormulaElementType::BitwiseOr); }
else if (strBuffer == "$") { targetFormSegment.AddOp(FormulaElementType::XOR); }
switch (strBuffer.front())
{
case '+': targetFormSegment.AddOp(FormulaElementType::Add); break;
case '-': targetFormSegment.AddOp(FormulaElementType::Sub); break;
case '*': targetFormSegment.AddOp(FormulaElementType::Mult); break;
case '/': targetFormSegment.AddOp(FormulaElementType::Div); break;
case '%': targetFormSegment.AddOp(FormulaElementType::Rem); break;
case '^': targetFormSegment.AddOp(FormulaElementType::Pow); break;
case '<': targetFormSegment.AddOp(strBuffer.size() == 2 ? FormulaElementType::LessOrEqual : FormulaElementType::LessThan); break;
case '>': targetFormSegment.AddOp(strBuffer.size() == 2 ? FormulaElementType::GreaterOrEqual : FormulaElementType::GreaterThan); break;
case '=': targetFormSegment.AddOp(FormulaElementType::Equal); break;//== detected
case '&': targetFormSegment.AddOp(strBuffer.size() == 2 ? FormulaElementType::AND : FormulaElementType::BitwiseAND); break;
case '|': targetFormSegment.AddOp(strBuffer.size() == 2 ? FormulaElementType::OR : FormulaElementType::BitwiseOr); break;
case '!': targetFormSegment.AddOp(strBuffer.size() == 2 ? FormulaElementType::NotEqual : FormulaElementType::Negative); break;
case '$': targetFormSegment.AddOp(FormulaElementType::XOR); break;//XOR
}
}
else if (ScanType == 11)//Prefix ++ or --
{
Expand Down

0 comments on commit 364839e

Please sign in to comment.