21#include "../../kernel.hpp"
44 size_t nMatch = nPosStart;
45 const static std::string sOperators =
"+-*/,^!%&|?:#<>='; ";
46 const static std::string sDelimiterLeft = sOperators +
"([{";
47#warning TODO (numere#1#12/05/21): Cannot detect variables with methods (if that is needed)
48 const static std::string sDelimiterRight = sOperators +
")]}";
52 while ((nMatch = sExpr.find(sVarName, nMatch)) != string::npos)
54 if ((!nMatch || sDelimiterLeft.find(sExpr[nMatch-1]) != string::npos)
55 && (nMatch + sVarName.length() >= sExpr.length() || sDelimiterRight.find(sExpr[nMatch+sVarName.length()]) != string::npos)
64 return std::string::npos;
84 vector<string> vVectors(1,
"");
85 vector<string> vScalars(1,
"");
88 string sDelim =
"+-*/^&|!%";
91 unsigned int nPos = 0;
103 while (sLine.length())
110 sBuffer += sTemp +
",";
113 sLine = sBuffer.substr(0, sBuffer.length()-1);
122 for (nPos = 0; nPos < sTemp.length(); nPos++)
126 if (sTemp[nPos] ==
'"')
128 if (!nPos || (nPos && sTemp[nPos - 1] !=
'\\'))
133 if (sTemp[nPos] !=
'{' || (nQuotes % 2))
139 if (nPos && (isalnum(sTemp[nPos-1]) || sTemp[nPos-1] ==
'_'))
160 if (sTemp.find(
'{', nPos) != 0)
161 vScalars.back() += sTemp.substr(0, sTemp.find(
'{', nPos));
164 if (vVectors.back()[0] ==
'{')
166 vVectors.back().erase(0, 1);
168 if (vVectors.back().back() ==
'}')
169 vVectors.back().pop_back();
175 vScalars.back() += vVectors.back();
185 if (vVectors.back().length())
187 string sTempCopy = vVectors.back();
189 while (sTempCopy.length())
202 vVectors.push_back(
"");
203 vScalars.push_back(
"");
214 vScalars.back() += sTemp;
215 vScalars.push_back(
"");
227 for (
size_t i = 0; i < vScalars.size(); i++)
228 sLine += vScalars[i];
233 for (
int i = 0; i < nDim; i++)
236 for (
size_t j = 0; j < vVectors.size()-1; j++)
239 sLine += vScalars[j];
243 if (vVectors[j].length())
251 if (!bIsStringExpression)
255 for (
unsigned int n = 0; n < sDelim.length(); n++)
259 if (sTemp.find(sDelim[n]) != string::npos)
261 sTemp =
"(" + sTemp +
")";
272 if (vScalars.size() > vVectors.size())
273 sLine += vScalars[vScalars.size()-2];
302 bool bOneLeft =
false;
303 bool bOneRight =
false;
306 if (sVectorComponent.length())
310 return sVectorComponent;
312 else if (bAddStrings)
319 else if (!sLeft.length() && !sRight.length())
333 for (
int i = sLeft.length() - 1; i >= 0; i--)
339 for (
int j = i - 1; j >= 0; j--)
350 else if (sLeft[i] ==
'/')
358 for (
unsigned int i = 0; i < sRight.length(); i++)
360 if (sRight[i] !=
' ')
362 if (sRight[i] ==
')')
364 for (
unsigned int j = i + 1; j < sRight.length(); j++)
366 if (sRight[j] ==
')')
379 if ((bOneLeft && bOneRight))
398 static string sDelimiter =
"+-*/ =^&|!<>,\n";
401 for (
unsigned int i = 0; i < sLine.length(); i++)
404 if (sLine[i] ==
'(' || sLine[i] ==
'{')
409 if (sDelimiter.find(sLine[i]) != string::npos)
433 bool bHasDefaultValue =
false;
434 unsigned int nPos = 0;
436 if (__sCommand.find(
"??") == string::npos)
438 sReturn = __sCommand;
447 bHasDefaultValue =
false;
450 nPos = sReturn.find(
"??");
453 if (sReturn.find(
"[", nPos) != string::npos)
456 if (sReturn.find(
"??", nPos + 2) != string::npos && sReturn.find(
"[", nPos) < sReturn.find(
"??", nPos + 2))
457 bHasDefaultValue =
true;
458 else if (sReturn.find(
"??", nPos + 2) == string::npos)
459 bHasDefaultValue =
true;
461 bHasDefaultValue =
false;
469 string sComp = sReturn.substr(0, nPos);
474 if (sComp.length() && sInput.find(sComp) != string::npos)
475 sInput.erase(0, sInput.find(sComp) + sComp.length());
478 while (!bHasDefaultValue && !sInput.length());
481 if (bHasDefaultValue && !sInput.length())
483 sReturn = sReturn.substr(0, nPos) + sReturn.substr(sReturn.find(
"[", nPos) + 1, sReturn.find(
"]", nPos) - sReturn.find(
"[", nPos) - 1) + sReturn.substr(sReturn.find(
"]", nPos) + 1);
485 else if (bHasDefaultValue && sInput.length())
487 sReturn = sReturn.substr(0, nPos) + sInput + sReturn.substr(sReturn.find(
"]", nPos) + 1);
491 sReturn = sReturn.substr(0, nPos) + sInput + sReturn.substr(nPos + 2);
494 while (sReturn.find(
"??") != string::npos);
496 GetAsyncKeyState(VK_ESCAPE);
517 auto iter = Vars.find(sVarName);
518 if (iter != Vars.end())
543 for (
int i = nNumber - 1; i > 0; i--)
577 if (!_data.
isTable(sTargetTable.substr(0, sTargetTable.find(
'(')) +
"()"))
578 _data.
addTable(sTargetTable.substr(0, sTargetTable.find(
'(')), _option);
581 getIndices(sTargetTable, _idx, _parser, _data, _option);
582 sTargetTable.erase(sTargetTable.find(
'('));
589 sCmd.erase(sCmd.find(
getArgAtPos(sCmd,
findParameter(sCmd,
"target",
'=') + 6),
findParameter(sCmd,
"target",
'=') - 1),
getArgAtPos(sCmd,
findParameter(sCmd,
"target",
'=') + 6).length());
592 else if (sDefaultTarget.length())
599 if (_data.
isTable(sDefaultTarget +
"()"))
602 _data.
addTable(sDefaultTarget, _option);
605 sTargetTable = sDefaultTarget;
657static void readAndParseLegacyIntervals(
string& sExpr,
const string& sLegacyIntervalIdentifier,
Parser& _parser, vector<double>& vInterval,
size_t nMinSize,
bool bEraseInterval)
665 sExpr.erase(sExpr.find(sInterval), sInterval.length());
666 size_t pos = sExpr.rfind(sLegacyIntervalIdentifier,
findParameter(sExpr, sLegacyIntervalIdentifier,
'='));
667 sExpr.erase(pos,
findParameter(sExpr, sLegacyIntervalIdentifier,
'=') + 1 - pos);
671 if (sInterval.find(
':') != string::npos)
674 indices.push_back(sInterval);
676 while (vInterval.size() < nMinSize)
677 vInterval.push_back(NAN);
679 for (
size_t i = 0; i < 2; i++)
684 vInterval.push_back(_parser.
Eval().real());
687 vInterval.push_back(NAN);
708 vector<double> vInterval;
711 if (!_functions.
call(sExpr))
731 if (sExpr.find(
'[') != string::npos
732 && sExpr.find(
']', sExpr.find(
'[')) != string::npos
733 && sExpr.find(
':', sExpr.find(
'[')) != string::npos)
736 size_t nMatchingParens = 0;
741 nPos = sExpr.find(
'[', nPos);
743 if (nPos == string::npos || (nMatchingParens =
getMatchingParenthesis(sExpr.substr(nPos))) == string::npos)
746 nMatchingParens += nPos;
749 while (
isInQuotes(sExpr, nPos) || sExpr.substr(nPos, nMatchingParens - nPos).find(
':') == string::npos);
752 if (nPos != string::npos && nMatchingParens != string::npos)
754 string sRanges = sExpr.substr(nPos, nMatchingParens - nPos);
758 sExpr.erase(nPos - 1, nMatchingParens - nPos + 2);
764 for (
size_t i = 0; i < args.size(); i++)
766 if (args[i].find(
':') == string::npos)
772 for (
size_t j = 0; j < 2; j++)
777 vInterval.push_back(_parser.
Eval().real());
780 vInterval.push_back(NAN);
This class extends the std::vector for endlessness.
This class implements the function definition managing instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
This class represents the central memory managing instance. It will handle all tables and clusters,...
int getLines(StringView sTable, bool _bFull=false) const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
bool addTable(const std::string &sCache, const Settings &_option)
This member function creates a new table. It is checked, whether its name is valid and not already us...
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
int getCols(StringView sTable, bool _bFull=false) const
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
This class manages the setting values of the internal (kernel) settings of this application.
Common exception class for all exceptions thrown in NumeRe.
@ INCOMPLETE_VECTOR_SYNTAX
static size_t invalid_position
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
int & back()
This member function returns a reference to the final index value stored internally.
int & front()
This member function returns a reference to the first index value stored internally.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const varmap_type & GetVar() const
Return a map containing the used variables only.
Mathematical expressions parser.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
bool isNotEmptyExpression(const string &sExpr)
This function checks, whether the passed expression is non-empty (i.e. it contains more than white sp...
bool parser_CheckMultArgFunc(const string &sLeft, const string &sRight)
This function checks, whether the argument located between sLeft and sRight is part of a multi-argume...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
bool isValidIndexSet(const Indices &_idx)
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
unsigned int getPositionOfFirstDelimiter(const string &sLine)
This function returns the position of the first delimiter in the passed string, but it jumps over par...
string addMissingVectorComponent(const string &sVectorComponent, const string &sLeft, const string &sRight, bool bAddStrings)
This function determines the value of missing vector components (i.e. a vector contains not enough el...
string promptForUserInput(const string &__sCommand)
This function is invoked, if a prompt operator ("??") was found in a string.
bool evaluateIndices(const string &sCache, Indices &_idx, MemoryManager &_data)
This function will evaluate the passed indices, so that they match the dimensions of the passed cache...
size_t findVariableInExpression(const std::string &sExpr, const std::string &sVarName, size_t nPosStart)
This function searches for the selected variable in the passed string and returns the position of the...
string evaluateTargetOptionInCommand(string &sCmd, const string &sDefaultTarget, Indices &_idx, Parser &_parser, MemoryManager &_data, const Settings &_option)
This function evaluates the "target=TABLE()" expression and creates the target table,...
void convertVectorToExpression(string &sLine, const Settings &_option)
This function replaces vector expressions with their corresponding multi- expression equation.
int integralFactorial(int nNumber)
This function returns the factorial of the passed integral value.
vector< double > readAndParseIntervals(string &sExpr, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option, bool bEraseInterval)
This function will read the interval syntax in commands and return their values in a single vector.
static void readAndParseLegacyIntervals(string &sExpr, const string &sLegacyIntervalIdentifier, Parser &_parser, vector< double > &vInterval, size_t nMinSize, bool bEraseInterval)
This static function handles a single legacy interval. It's a helper for readAndParseIntervals().
mu::value_type * getPointerToVariable(const string &sVarName, Parser &_parser)
This function returns the pointer to the passed variable.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
This structure is central for managing the indices of a table or cluster read or write data access....