28#include "../../kernel.hpp"
29#include "../utils/stringtools.hpp"
30#include "../structures.hpp"
72 std::vector<double>
real(
const std::vector<value_type>& vVec)
74 std::vector<double> vReal;
76 for (
const auto& val : vVec)
77 vReal.push_back(val.real());
83 std::vector<double>
imag(
const std::vector<value_type>& vVec)
85 std::vector<double> vImag;
87 for (
const auto& val : vVec)
88 vImag.push_back(val.imag());
111 std::vector<value_type> vIdx;
113 for (
int i = 0; i < n; i++)
138 return std::vector<value_type>(1, 0.0);
143 return std::vector<value_type>(1, 0.0);
145 std::vector<value_type> vLogical(maxIdx.real(), 0.0);
147 for (
int i = 0; i < n; i++)
150 vLogical[v[i].real()-1] = 1.0;
170 if (__x.imag() == 0.0)
171 return value_type(__y.real()*__x.real(), __y.imag()*__x.real());
172 else if (__y.imag() == 0.0)
173 return value_type(__x.real()*__y.real(), __x.imag()*__y.real());
192 if (__y.imag() == 0.0)
193 return value_type(__x.real() / __y.real(), __x.imag() / __y.real());
202 std::locale
ParserBase::s_locale = std::locale(std::locale::classic(),
new change_dec_sep<char_type>(
'.'));
242 , m_sInfixOprtChars()
243 , m_nIfElseCounter(0)
279 , m_sInfixOprtChars()
280 , m_nIfElseCounter(0)
327 if (&a_Parser ==
this)
365 char_type cThousandsSep = std::use_facet< change_dec_sep<char_type> >(
s_locale).thousands_sep();
379 char_type cDecSep = std::use_facet< change_dec_sep<char_type> >(
s_locale).decimal_point();
447 std::vector<mu::value_type> vVar;
449 if (
GetVar().find(pExpr->substr(nStart, nEnd - nStart)) !=
GetVar().end())
450 vVar.push_back(*(
GetVar().find(pExpr->substr(nStart, nEnd - nStart))->second));
454 SetVectorVar(pExpr->substr(nStart, nEnd - nStart), vVar);
480 ss <<
_nrT(
"; DEBUG");
482 ss <<
_nrT(
"; RELEASE");
486 ss <<
_nrT(
"; UNICODE");
489 ss <<
_nrT(
"; MBCS");
491 ss <<
_nrT(
"; ASCII");
496 ss <<
_nrT(
"; OPENMP");
501#if defined(MUP_MATH_EXCEPTIONS)
502 ss <<
_nrT(
"; MATHEXC");
560 CheckOprt(a_strName, a_Callback, a_szCharSet);
561 a_Storage[a_strName] = a_Callback;
574 if ( !a_sName.length() ||
575 (a_sName.find_first_not_of(a_szCharSet) != string_type::npos) ||
576 (a_sName[0] >=
'0' && a_sName[0] <=
'9'))
598 if ( !a_sName.length() ||
599 (a_sName.find_first_not_of(a_szCharSet) != string_type::npos) ||
600 (a_sName[0] >=
'0' && a_sName[0] <=
'9'))
666 std::vector<mu::value_type> vResults;
674 if (iter->second.size() == 1)
677 while ((match = sExpr.
find(iter->first, match)) != string::npos)
687 for (
size_t i = 0; i < sExpr.
length(); i++)
690 if (sExpr[i] ==
'{' && (!i ||
isDelimiter(sExpr[i-1])) && sExpr.
find(
'}', i) != string::npos)
700 if (j != std::string::npos)
705 else if (j != std::string::npos && sExpr.
subview(i, j - i).
find(
':') != std::string::npos)
714 sExpr.
replace(i, j + 1 - i, sVectorVarName +
" ");
718 if (j != std::string::npos)
726 && sExpr.
find(
'=', j) != std::string::npos
728 && sExpr.
find(
'!', j) != sExpr.
find(
'=', j) - 1
729 && sExpr.
find(
'<', j) != sExpr.
find(
'=', j) - 1
730 && sExpr.
find(
'>', j) != sExpr.
find(
'=', j) - 1
731 && sExpr[sExpr.
find(
'=', j) + 1] !=
'=')
737 vResults.insert(vResults.end(), v, v+nResults);
741 sExpr.
replace(i, j + 1 - i,
"_~TRGTVCT[~]");
753 sExpr.
replace(i, j + 1 - i, sVectorVarName +
" ");
759 if (sExpr.
subview(i, 9) ==
"logtoidx(" || sExpr.
subview(i, 9) ==
"idxtolog(")
784 std::vector<int> vComponentType;
785 std::string sCompiledExpression;
786 const int SINGLETON = 1;
789 for (
size_t n = 0; n < args.size(); n++)
791 if (args[n].find(
':') == std::string::npos)
793 vComponentType.push_back(SINGLETON);
795 if (sCompiledExpression.length())
796 sCompiledExpression +=
",";
798 sCompiledExpression += args[n].to_string();
802 int isExpansion = -1;
806 for (
size_t i = 0; i < sExpansion.
length(); i++)
808 if (sExpansion[i] ==
'(' || sExpansion[i] ==
'[' || sExpansion[i] ==
'{')
811 if (sExpansion[i] ==
':')
813 if (isExpansion == -1)
817 if (isExpansion == 0)
824 if (sExpansion[i] ==
'?')
826 if (isExpansion == -1)
829 if (isExpansion == 1)
834 if (sCompiledExpression.length())
835 sCompiledExpression +=
",";
837 sCompiledExpression += sExpansion.
to_string();
862 mu::value_type fact(d.real() >= 0.0 ? 1.0 : -1.0, d.imag() >= 0.0 ? 1.0 : -1.0);
864 return (current.real() * fact.real()) <= (
last.real() * fact.real())
865 && (current.imag() * fact.imag()) <= (
last.imag() * fact.imag());
885 if ((dFirst.real() < dLast.real() && dIncrement.real() < 0)
886 || (dFirst.imag() < dLast.imag() && dIncrement.imag() < 0)
887 || (dFirst.real() > dLast.real() && dIncrement.real() > 0)
888 || (dFirst.imag() > dLast.imag() && dIncrement.imag() > 0)
889 || dIncrement == 0.0)
891 vResults.push_back(dFirst);
896 vResults.push_back(dFirst);
901 dFirst += dIncrement;
902 vResults.push_back(dFirst);
920 string sMultiArgFunc;
924 if (nMultiArgParens != std::string::npos)
931 vector<mu::value_type> vResults;
934 SetExpr(sExpr.
subview(nMultiArgParens + 1, nClosingParens - nMultiArgParens - 1));
939 sExpr.
replace(nMultiArgParens - sMultiArgFunc.length(),
940 nClosingParens - nMultiArgParens + 1 + sMultiArgFunc.length(),
945 nPos = nMultiArgParens-sMultiArgFunc.
length();
970 for (
int i = nPos; i >= 2; i--)
973 if (sExpr[i] ==
'(' && isalpha(sExpr[i - 1]))
978 if (nParPos == string::npos)
979 return std::string::npos;
988 size_t nSep = sExpr.
find_last_of(
" +-*/(=:?&|<>!%{^", i - 1) + 1;
993 if (sFunc ==
"polynomial" || sFunc ==
"perlin")
995 else if (sFunc ==
"logtoidx" || sFunc ==
"idxtolog")
997 sMultArgFunc = sFunc;
1004 if (iter !=
m_FunDef.end() && iter->second.GetArgc() == -1)
1007 sMultArgFunc = sFunc;
1014 return std::string::npos;
1195 bool makeReInit =
false;
1358 iter->second[0] = *(
m_VarDef.find(iter->first)->second);
1380 const std::vector<token_type>& a_vArg)
const
1382 if (a_vArg.back().GetCode() !=
cmSTRING)
1399 a_vArg[0].GetVal()) );
1404 a_vArg[0].GetVal()) );
1430 int a_iArgCount)
const
1435 if (a_stOpt.
empty() || a_stOpt.
top().GetFuncAddr() == 0 )
1451 int iArgNumerical = iArgCount - ((funTok.
GetType() ==
tpSTR) ? 1 : 0);
1456 if (funTok.
GetArgCount() >= 0 && iArgCount > iArgRequired)
1467 std::vector<token_type> stArg;
1468 for (
int i = 0; i < iArgNumerical; ++i)
1470 stArg.push_back( a_stVal.
pop() );
1478 stArg.push_back(a_stVal.
pop());
1498 (funTok.
GetArgCount() == -1) ? -iArgNumerical : iArgNumerical,
1509 a_stVal.
push(token);
1533 a_stVal.
push( (vExpr.
GetVal() != 0.0) ? vVal1 : vVal2);
1559 valTok2 = a_stVal.
pop(),
1560 optTok = a_stOpt.
pop(),
1563 if ( valTok1.
GetType() != valTok2.GetType() ||
1569 if (valTok2.GetCode() !=
cmVAR)
1578 a_stVal.
push(resTok);
1590 while (stOpt.
size() &&
1591 stOpt.
top().GetCode() !=
cmBO &&
1592 stOpt.
top().GetCode() !=
cmIF)
1655 Stack = ((nOffset == 0) && (nThreadID == 0))
1669 Stack[sidx] = Stack[sidx].real() <= Stack[sidx + 1].real();
1673 Stack[sidx] = Stack[sidx].real() >= Stack[sidx + 1].real();
1677 Stack[sidx] = Stack[sidx] != Stack[sidx + 1];
1681 Stack[sidx] = Stack[sidx] == Stack[sidx + 1];
1685 Stack[sidx] = Stack[sidx].real() < Stack[sidx + 1].real();
1689 Stack[sidx] = Stack[sidx].real() > Stack[sidx + 1].real();
1693 Stack[sidx] += Stack[1 + sidx];
1697 Stack[sidx] -= Stack[1 + sidx];
1701 Stack[sidx] = Stack[sidx] * Stack[1 + sidx];
1705 Stack[sidx] = Stack[sidx] / Stack[1 + sidx];
1715 Stack[sidx] = Stack[sidx] != 0.0 && Stack[sidx + 1] != 0.0;
1719 Stack[sidx] = Stack[sidx] != 0.0 || Stack[sidx + 1] != 0.0;
1724 Stack[sidx] = *pTok->Oprt.ptr = Stack[sidx + 1];
1728 if (Stack[sidx--] == 0.0)
1729 pTok += pTok->Oprt.offset;
1733 pTok += pTok->Oprt.offset;
1741 Stack[++sidx] = pTok->Val.data2;
1745 Stack[++sidx] = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1749 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1750 Stack[++sidx] = buf * buf;
1754 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1755 Stack[++sidx] = buf * buf * buf;
1759 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1760 Stack[++sidx] = buf * buf * buf * buf;
1764 Stack[++sidx] =
intPower(*(pTok->Val.ptr + pTok->Val.isVect*nOffset), pTok->Val.data.real());
1768 Stack[++sidx] = *(pTok->Val.ptr + pTok->Val.isVect*nOffset) * pTok->Val.data + pTok->Val.data2;
1774 int iArgCount = pTok->Fun.argc;
1781 Stack[sidx] = (*(
fun_type0)pTok->Fun.ptr)();
1784 Stack[sidx] = (*(
fun_type1)pTok->Fun.ptr)(Stack[sidx]);
1788 Stack[sidx] = (*(
fun_type2)pTok->Fun.ptr)(Stack[sidx],
1793 Stack[sidx] = (*(
fun_type3)pTok->Fun.ptr)(Stack[sidx],
1799 Stack[sidx] = (*(
fun_type4)pTok->Fun.ptr)(Stack[sidx],
1806 Stack[sidx] = (*(
fun_type5)pTok->Fun.ptr)(Stack[sidx],
1814 Stack[sidx] = (*(
fun_type6)pTok->Fun.ptr)(Stack[sidx],
1823 Stack[sidx] = (*(
fun_type7)pTok->Fun.ptr)(Stack[sidx],
1833 Stack[sidx] = (*(
fun_type8)pTok->Fun.ptr)(Stack[sidx],
1844 Stack[sidx] = (*(
fun_type9)pTok->Fun.ptr)(Stack[sidx],
1856 Stack[sidx] = (*(
fun_type10)pTok->Fun.ptr)(Stack[sidx],
1871 sidx -= -iArgCount - 1;
1872 Stack[sidx] = (*(
multfun_type)pTok->Fun.ptr)(&Stack[sidx], -iArgCount);
1892 void ParserBase::ParseCmdCodeBulkParallel(
size_t nVectorLength)
1897 #pragma omp parallel for
1898 for (
size_t nOffset = 1; nOffset < nVectorLength; ++nOffset)
1900 int nThreadID = omp_get_thread_num();
1913 Stack[sidx] = Stack[sidx].real() <= Stack[sidx + 1].real();
1917 Stack[sidx] = Stack[sidx].real() >= Stack[sidx + 1].real();
1921 Stack[sidx] = Stack[sidx] != Stack[sidx + 1];
1925 Stack[sidx] = Stack[sidx] == Stack[sidx + 1];
1929 Stack[sidx] = Stack[sidx].real() < Stack[sidx + 1].real();
1933 Stack[sidx] = Stack[sidx].real() > Stack[sidx + 1].real();
1937 Stack[sidx] += Stack[1 + sidx];
1941 Stack[sidx] -= Stack[1 + sidx];
1945 Stack[sidx] = Stack[sidx] * Stack[1 + sidx];
1949 Stack[sidx] = Stack[sidx] / Stack[1 + sidx];
1959 Stack[sidx] = Stack[sidx] != 0.0 && Stack[sidx + 1] != 0.0;
1963 Stack[sidx] = Stack[sidx] != 0.0 || Stack[sidx + 1] != 0.0;
1968 Stack[sidx] = *pTok->Oprt.ptr = Stack[sidx + 1];
1972 if (Stack[sidx--] == 0.0)
1973 pTok += pTok->Oprt.offset;
1977 pTok += pTok->Oprt.offset;
1985 Stack[++sidx] = pTok->Val.data2;
1989 Stack[++sidx] = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1994 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
1995 Stack[++sidx] = buf * buf;
1999 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
2000 Stack[++sidx] = buf * buf * buf;
2004 buf = *(pTok->Val.ptr + pTok->Val.isVect*nOffset);
2005 Stack[++sidx] = buf * buf * buf * buf;
2009 Stack[++sidx] =
intPower(*(pTok->Val.ptr + pTok->Val.isVect*nOffset), pTok->Val.data.real());
2013 Stack[++sidx] = *(pTok->Val.ptr + pTok->Val.isVect*nOffset) * pTok->Val.data + pTok->Val.data2;
2019 int iArgCount = pTok->Fun.argc;
2026 Stack[sidx] = (*(
fun_type0)pTok->Fun.ptr)();
2029 Stack[sidx] = (*(
fun_type1)pTok->Fun.ptr)(Stack[sidx]);
2033 Stack[sidx] = (*(
fun_type2)pTok->Fun.ptr)(Stack[sidx],
2038 Stack[sidx] = (*(
fun_type3)pTok->Fun.ptr)(Stack[sidx],
2044 Stack[sidx] = (*(
fun_type4)pTok->Fun.ptr)(Stack[sidx],
2051 Stack[sidx] = (*(
fun_type5)pTok->Fun.ptr)(Stack[sidx],
2059 Stack[sidx] = (*(
fun_type6)pTok->Fun.ptr)(Stack[sidx],
2068 Stack[sidx] = (*(
fun_type7)pTok->Fun.ptr)(Stack[sidx],
2078 Stack[sidx] = (*(
fun_type8)pTok->Fun.ptr)(Stack[sidx],
2089 Stack[sidx] = (*(
fun_type9)pTok->Fun.ptr)(Stack[sidx],
2101 Stack[sidx] = (*(
fun_type10)pTok->Fun.ptr)(Stack[sidx],
2116 sidx -= -iArgCount - 1;
2117 Stack[sidx] = (*(
multfun_type)pTok->Fun.ptr)(&Stack[sidx], -iArgCount);
2128 for (
int j = 0; j < nStackSize; j++)
2184 std::vector<mu::value_type> vVar;
2185 vVar.push_back(*(opt.
GetVar()));
2209 if (stArgCount.
empty())
2231 if (stOpt.
size() && stOpt.
top().GetCode() ==
cmBO)
2239 assert(stArgCount.
size());
2240 int iArgCount = stArgCount.
pop();
2244 if (iArgCount > 1 && ( stOpt.
size() == 0 ||
2255 stOpt.
top().GetFuncAddr() != 0)
2290 while ( stOpt.
size() &&
2291 stOpt.
top().GetCode() !=
cmBO &&
2293 stOpt.
top().GetCode() !=
cmIF)
2303 if ( (eOprtAsct ==
oaRIGHT && (nPrec1 <= nPrec2)) ||
2304 (eOprtAsct ==
oaLEFT && (nPrec1 < nPrec2)) )
2309 else if (nPrec1 < nPrec2)
2382 if (stVal.
size() == 0)
2385 if (stVal.
top().GetType() !=
tpDBL)
2475 varmap_type::iterator item =
m_VarDef.find(a_strVarName);
2484 if (item->second == *iter)
2636 while ( !stVal.
empty() )
2649 while ( !stOprt.empty() )
2651 if (stOprt.top().GetCode() <=
cmASSIGN)
2657 switch (stOprt.top().GetCode())
2725 int nParenthesis = 0;
2726 int nVektorbrace = 0;
2727 unsigned int nPos = 0;
2731 for (
unsigned int i = 0; i < sArgList.length(); i++)
2733 if (sArgList[i] ==
'(')
2736 if (sArgList[i] ==
')')
2739 if (sArgList[i] ==
'{')
2745 if (sArgList[i] ==
'}')
2751 if (sArgList[i] ==
',' && !nParenthesis && !nVektorbrace)
2759 if (!nPos && sArgList[0] !=
',')
2760 nPos = sArgList.length();
2766 if (bCut && sArgList[0] ==
',')
2767 sArgList.erase(0, 1);
2773 std::string sArg = sArgList.substr(0, nPos);
2776 while (sArg.front() ==
' ' || sArg.front() ==
'\t')
2779 while (sArg.back() ==
' ' || sArg.back() ==
'\t')
2780 sArg.erase(sArg.length() - 1);
2784 if (bCut && sArgList.length() > nPos + 1)
2785 sArgList = sArgList.substr(nPos + 1);
2851 diff.real(diff.real() > 0.0 ? 1.0 : (diff.real() < 0.0 ? -1.0 : 0.0));
2852 diff.imag(diff.imag() > 0.0 ? 1.0 : (diff.imag() < 0.0 ? -1.0 : 0.0));
2855 else if (nComps == 3)
2904 for (
int i = 0; i < nElems; i++)
2939 std::vector<std::vector<value_type>*> vUsedVectorVars;
2940 std::vector<value_type*> vUsedVectorVarAddresses;
2942 size_t nVectorLength = 0;
2946 auto iterVar = vars.begin();
2948 for ( ; iterVector !=
mVectorVars.end() && iterVar != vars.end(); )
2950 if (iterVector->first == iterVar->first)
2952 if (iterVector->second.size() > 1 && iterVector->first !=
"_~TRGTVCT[~]")
2954 vUsedVectorVarAddresses.push_back(iterVar->second);
2955 vUsedVectorVars.push_back(&(iterVector->second));
2956 nVectorLength =
std::max(nVectorLength, iterVector->second.size());
2964 if (iterVector->first < iterVar->first)
2972 if (vUsedVectorVarAddresses.size())
2975 for (
size_t i = 0; i < vUsedVectorVarAddresses.size(); i++)
2977 vUsedVectorVars[i]->resize(nVectorLength);
2982 m_buffer.resize(nStackSize * nVectorLength);
2984 if (nVectorLength < 500)
2987 for (
size_t i = 1; i < nVectorLength; ++i)
2991 for (
int j = 0; j < nStackSize; j++)
3022 nStackSize *= nVectorLength;
3025 for (
size_t i = 0; i < vUsedVectorVarAddresses.size(); i++)
3342 return m_stateStacks(_nthLoopElement, _nthPartEquation).m_valid;
3431 sNewEquation.
strip();
3433 if (sNewEquation == sCurrentEquation
3471#ifdef MUP_USE_OPENMP
3473#ifdef DEBUG_OMP_STUFF
3474 int* pThread =
new int[nBulkSize];
3475 int* pIdx =
new int[nBulkSize];
3479 int nThreadID, ct = 0;
3482 #pragma omp parallel for schedule(static, nBulkSize/nMaxThreads) private(nThreadID)
3483 for (
int i = 0; i < nBulkSize; ++i)
3485 nThreadID = omp_get_thread_num();
3488#ifdef DEBUG_OMP_STUFF
3489 #pragma omp critical
3491 pThread[ct] = nThreadID;
3498#ifdef DEBUG_OMP_STUFF
3499 FILE* pFile = fopen(
"bulk_dbg.txt",
"w");
3500 for (
int i = 0; i < nBulkSize; ++i)
3502 fprintf(pFile,
"idx: %d thread: %d \n", pIdx[i], pThread[i]);
3529 SetVectorVar(sTempVarName, std::vector<mu::value_type>(1, 0.0),
false);
3533 return sTempVarName;
3568 *(
m_VarDef.find(sVarName)->second) = vVar[0];
3628 string siter = iter->first;
3630 if ((iter->first).find(
'[') != string::npos && (iter->first).find(
']') != string::npos)
3632 if (bIgnoreProcedureVects && (iter->first).substr(0, 8) ==
"_~PROC~[")
3645 if (!bIgnoreProcedureVects || !
mVectorVars.size())
3667 if (ignoreSingletons && iter->second.size() == 1)
3670 size_t nPos = sExpr.
find(iter->first);
3672 if (nPos != string::npos && (!nPos ||
checkDelimiter(sExpr.
subview(nPos-1, iter->first.length()+2))))
3676 static std::vector<std::string> vNDVECTFUNCS = {
"logtoidx",
"idxtolog"};
3678 for (
const auto&
func : vNDVECTFUNCS)
3693 return c >= 32 && c <= 126 && c != 36 && c != 39 && c != 46 && (c < 48 || c > 57) && (c < 64 || c > 90) && (c < 95 || c > 122);
3729 for (
unsigned int i = 0; i < sLine.length(); i++)
3731 if (sLine.substr(i, (iter->first).length()) == iter->first)
3733 if ((i &&
checkDelimiter(sLine.substr(i - 1, (iter->first).length() + 2)))
3734 || (!i &&
checkDelimiter(
" " + sLine.substr(i, (iter->first).length() + 1))))
3736 sLine.replace(i, (iter->first).length(), iter->second);
This class extends the std::vector for endlessness.
This class is a mutable version of a string view. It can be used to replace single characters or enti...
MutableStringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new MutableStringView class instance using the selected position and l...
MutableStringView & replace(size_t pos, size_t len, const std::string &s)
This member function replaces a range in the internal viewed string with the passed string.
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...
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
void strip()
This member function shrinks the viewed section to remove all leading or trailing whitespace characte...
size_t find_first_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_of()
const char & back() const
This member function provides a const char reference to the last character in the viewed section.
size_t find_last_of(const std::string &findstr, size_t pos=std::string::npos) const
Wrapper member function for std::string::find_last_of()
const char & front() const
This member function provides a const char reference to the first character in the viewed section.
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
size_t find(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find()
size_t length() const
This member function simply returns the length of the viewed section.
size_t find_first_not_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_not_of()
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
A facet class used to change decimal and thousands separator.
Mathematical expressions parser (base parser engine).
varmap_type m_VarDef
user defind variables.
ParserTokenReader token_reader_type
Typedef for the token reader.
const string_type & GetExpr() const
Retrieve the formula.
const char_type * ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
bool checkDelimiter(StringView sLine)
This member function checks, whether the passed string is delimited on both sides.
void CacheCurrentAccess(const CachedDataAccess &_access)
Store the passed data access for this position internally.
void StackDump(const ParserStack< token_type > &a_stVal, const ParserStack< token_type > &a_stOprt) const
Dump stack content.
void Assign(const ParserBase &a_Parser)
Copy state of a parser object to this.
void AddValIdent(identfun_type a_pCallback)
Add a value parsing function.
static const char_type * c_DefaultOprt[]
Identifiers for built in binary operators.
void CheckOprt(const string_type &a_sName, const ParserCallback &a_Callback, const string_type &a_szCharSet) const
Check if a name contains invalid characters.
ParseFunction m_pParseFormula
Pointer to the parser function.
void SetDecSep(char_type cDecSep)
Set the decimal separator.
size_t FindMultiArgFunc(StringView sExpr, size_t nPos, std::string &sMultArgFunc)
This function searches for the first multi-argument function found in the passed expression.
unsigned int nthLoopPartEquation
void ApplyBinOprt(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
Performs the necessary steps to write code for the execution of binary operators into the bytecode.
MutableStringView compileVectors(MutableStringView sExpr)
This function pre-evaluates all vectors, which are contained in the expression passed through sExpr.
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.
void CheckName(const string_type &a_strName, const string_type &a_CharSet) const
Check if a name contains invalid characters.
const varmap_type & GetVar() const
Return a map containing the used variables only.
void CacheCurrentTarget(const std::string &sEquation)
Caches the passed target equation for this position.
void Init()
Initialize user defined functions.
stringbuf_type m_vStringBuf
String buffer, used for storing string function arguments.
void AddCallback(const string_type &a_strName, const ParserCallback &a_Callback, funmap_type &a_Storage, const char_type *a_szCharSet)
Add a function or operator callback to the parser.
void ApplyIfElse(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
const CachedDataAccess & GetCachedAccess(size_t nthAccess)
Returns the cached data access for the passed position.
int IsValidByteCode(unsigned int _nthLoopElement=-1, unsigned int _nthPartEquation=0)
This member function returns, whether the current equation is already parsed and there's a valid byte...
static bool g_DbgDumpStack
bool HasBuiltInOprt() const
Query status of built in variables.
void ResetLocale()
Resets the locale.
const std::string & GetCachedEquation() const
Returns the stored equation for this position.
const char_type ** GetOprtDef() const
Get the default symbols used for the built in operators.
void SetIndex(unsigned int _nLoopElement)
Activates the selected position in the internally stored bytecode.
void ParseCmdCodeBulkParallel(size_t nVectorLength)
OpenMP optimized parallel bytecode executor.
StateStacks m_stateStacks
string_type GetVersion(EParserVersionInfo eInfo=pviFULL) const
Returns the version of muparser.
void PauseLoopMode(bool _bPause=true)
This member function pauses the loop mode, so that the new assigned equation does not invalidate alre...
virtual void InitCharSets()=0
bool IsLockedPause() const
Check, whether the pause mode is locked.
void Error(EErrorCodes a_iErrc, int a_iPos=(int) mu::string_type::npos, const string_type &a_strTok=string_type()) const
Create an error containing the parse error position.
void EnableOptimizer(bool a_bIsOn=true)
Enable or disable the formula optimization feature.
vectormap_type mVectorVars
Maximum number of threads spawned by OpenMP when using the bulk mode.
funmap_type m_InfixOprtDef
unary infix operator.
void ApplyFunc(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal, int iArgCount) const
Apply a function token.
const std::string & GetCachedTarget() const
Returns the stored target equation for this position.
unsigned int nCurrVectorIndex
virtual void InitOprt()=0
const valmap_type & GetConst() const
Return a map containing all parser constants.
void DeactivateLoopMode()
Deactivates the loop mode and resets the internal arrays.
void ClearVectorVars(bool bIgnoreProcedureVects=false)
This member function cleares the internal vector storage.
const std::map< std::string, std::vector< mu::value_type > > & GetVectors() const
int m_nIfElseCounter
Internal counter for keeping track of nested if-then-else clauses.
const varmap_type & GetUsedVar()
Return a map containing the used variables only.
void DefineStrConst(const string_type &a_sName, const string_type &a_strVal)
Define a new string constant.
valmap_type m_ConstDef
user constants.
bool compileVectorsInMultiArgFunc(MutableStringView &sExpr, size_t &nPos)
This private function will try to find a surrounding multi-argument function, resolve the arguments,...
bool ActiveLoopMode() const
Check, whether the loop mode is active. This function returns true even if the loop mode is paused.
void SetVarFactory(facfun_type a_pFactory, void *pUserData=NULL)
Set a function that can create variable pointer for unknown expression variables.
const funmap_type & GetFunDef() const
Return prototypes of all parser functions.
void ClearInfixOprt()
Clear the user defined Prefix operators.
std::vector< mu::value_type > * GetVectorVar(const std::string &sVarName)
This member function returns a pointer to the vector stored internally.
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
void ParseString()
One of the two main parse functions.
void DefineVar(const string_type &a_sName, value_type *a_fVar)
Add a user defined variable.
void evaluateTemporaryVectors(const VectorEvaluation &vectEval, int nStackSize)
This member function evaluates the temporary vector expressions and assigns their results to their co...
void DefineConst(const string_type &a_sName, value_type a_fVal)
Add a user defined constant.
void RemoveVar(const string_type &a_strVarName)
Remove a variable from internal storage.
funmap_type m_FunDef
Map of function names and pointers.
void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool optimizeAway=true)
Add a user defined operator.
funmap_type m_PostOprtDef
Postfix operator callbacks.
bool CanCacheAccess()
Check, whether the current position can cache any data accesses.
funmap_type m_OprtDef
Binary operator callbacks.
void ApplyRemainingOprt(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
Apply a binary operator.
bool IsAlreadyParsed(StringView sNewEquation)
This member function checks, whether the passed expression is already parsed, so that the parsing ste...
void ClearOprt()
Clear all user defined binary operators.
int GetOprtPrecedence(const token_type &a_Tok) const
Get operator priority.
virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd)
void replaceLocalVars(std::string &sLine)
This member function replaces var occurences with the names of local variables.
void compileVectorExpansion(MutableStringView sSubExpr, const std::string &sVectorVarName)
This function evaluates the vector expansion, e.g. "{1:4}" = {1, 2, 3, 4}.
bool IsCompiling()
Returns true, if the parser is currently in compiling step.
bool IsNotLastStackItem() const
Check, whether there are more elements on the parsing stack remaining.
virtual void InitConst()=0
string_type m_sInfixOprtChars
Charset for infix operator tokens.
void DefineOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of binary operators and postfix operators.
void LockPause(bool _bLock=true)
This member function locks the pause mode so that it cannot be accidentally activated.
void ActivateLoopMode(unsigned int _nLoopLength)
Activates the loop mode and prepares the internal arrays for storing the necessary data.
ExpressionTarget m_compilingTarget
void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool optimizeAway=true)
Add a user defined operator.
ParserError exception_type
Type of the error class.
void SetThousandsSep(char_type cThousandsSep=0)
Sets the thousands operator.
EOprtAssociativity GetOprtAssociativity(const token_type &a_Tok) const
Get operator priority.
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
void ClearPostfixOprt()
Clear all user defined postfix operators.
void CacheCurrentEquation(const std::string &sEquation)
Caches the passed equation for this position.
void ClearFun()
Clear all functions.
void ParseCmdCode()
Parse the command code.
token_type ApplyStrFunc(const token_type &a_FunTok, const std::vector< token_type > &a_vArg) const
Execute a function that takes a single string argument.
static bool g_DbgDumpCmdCode
void ReInit()
Reset parser to string parsing mode and clear internal buffers.
void DefineInfixOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of infix operators.
ParserBase & operator=(const ParserBase &a_Parser)
Assignement operator.
void UpdateVectorVar(const std::string &sVarName)
This member function updates the corresponding variable of a vector with the previously newly assigne...
size_t HasCachedAccess()
Evaluate, whether there are any cached data accesses for this position.
std::map< std::string, std::string > * mVarMapPntr
void ParseCmdCodeBulk(int nOffset, int nThreadID)
Evaluate the RPN.
void DisableAccessCaching()
Disable the data access caching for this position.
static std::locale s_locale
The locale used by the parser.
const std::string EMPTYSTRING
bool ContainsVectorVars(StringView sExpr, bool ignoreSingletons)
This member function checks, whether the passed expression contains a vector.
unsigned int nthLoopElement
void ClearConst()
Clear all user defined constants.
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
void ClearVar()
Clear all user defined variables.
void expandVector(mu::value_type dFirst, const mu::value_type &dLast, const mu::value_type &dIncrement, std::vector< mu::value_type > &vResults)
This function expands the vector. Private member used by ParserBase::compileVectorExpansion().
void SetArgSep(char_type cArgSep)
Set argument separator.
std::unique_ptr< token_reader_type > m_pTokenReader
Managed pointer to the token reader object.
void DefineNameChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of functions, variables, constants.
void EnableBuiltInOprt(bool a_bIsOn=true)
Enable or disable the built in binary operators.
void SetCompiling(bool _bCompiling=true)
Activate the compiling step for the parser.
strmap_type m_StrVarDef
user defined string constants
static void EnableDebugDump(bool bDumpCmd, bool bDumpStack)
Enable the dumping of bytecode amd stack content on the console.
string_type getNextVectorVarIndex()
This member function returns the next free vector index, which can be used to create a new temporary ...
void InitTokenReader()
Initialize the token reader.
char_type GetArgSep() const
Get the argument separator character.
ExpressionTarget & getTarget() const
Simple state-considering wrapper around the ExpressionTarget structure.
string_type m_sNameChars
Charset for names.
bool m_bBuiltInOp
Flag that can be used for switching built in operators on and off.
string_type getNextVarObject(std::string &sArgList, bool bCut)
This member function returns the next comma-separated expression object from the passed argument list...
string_type m_sOprtChars
Charset for postfix/ binary operator tokens.
stringbuf_type m_vStringVarBuf
std::list< mu::value_type * > m_lDataStorage
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
void DefineOprt(const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool optimizeAway=true)
Define a binary operator.
void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx)
Add Strung function entry to the parser bytecode.
void EnableOptimizer(bool bStat)
std::size_t GetMaxStackSize() const
void AddOp(ECmdCode a_Oprt)
Add an operator identifier to bytecode.
const SToken * GetBase() const
void ChangeVar(value_type *a_pOldVar, value_type *a_pNewVar, bool isVect)
Changes all old variable pointers to the new addresses. Will be used to compensate for different loca...
void AddVal(value_type a_fVal)
Add a Variable pointer to bytecode.
void AddBulkFun(generic_fun_type a_pFun, int a_iArgc)
Add a bulk function to bytecode.
void AddFun(generic_fun_type a_pFun, int a_iArgc, bool optimizeAway)
Add a function to the bytecode.
void AsciiDump()
Dump bytecode (for debugging only!).
void AddVar(value_type *a_pVar)
Add a Variable pointer to bytecode.
void Finalize()
Add end marker to bytecode.
void AddAssignOp(value_type *a_pVar)
Add an assignement operator.
void AddIfElse(ECmdCode a_Oprt)
Encapsulation of prototypes for a numerical parser function.
void * GetAddr() const
Get the callback address for the parser function.
ECmdCode GetCode() const
Return the callback code.
Error class of the parser.
Parser stack implementation.
TValueType & top()
Return reference to the top object in the stack.
void push(const TValueType &a_Val)
Push an object into the stack.
TValueType pop()
Pop a value from the stack.
unsigned size() const
Return the number of stored elements.
bool empty() const
Returns true if stack is empty false otherwise.
ECmdCode GetCode() const
Return the token type.
bool IsOptimizable() const
TBase * GetVar() const
Get address of a variable token.
int GetArgCount() const
Return the number of function arguments.
generic_fun_type GetFuncAddr() const
Return the address of the callback function assoziated with function and operator tokens.
ParserToken & SetVal(TBase a_fVal, const TString &a_strTok=TString())
Make this token a value token.
ETypeCode GetType() const
void SetIdx(int a_iIdx)
Set an index associated with the token related data.
const TString & GetAsString() const
Return the token identifier.
EOprtAssociativity GetAssociativity() const
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
mu::value_type parser_Sum(const mu::value_type *, int)
This function summarizes all elements in the passed array.
mu::value_type parser_Med(const mu::value_type *, int)
This function calculates the median of the elements in the passed array.
mu::value_type parser_Std(const mu::value_type *, int)
This function calculates the standard deviation of the elements in the passed array.
mu::value_type parser_compare(const mu::value_type *, int)
This function searches for elements of a specified type in the passed array.
mu::value_type parser_product(const mu::value_type *, int)
This function calculates the product of all elements in the passed array.
mu::value_type parser_Pct(const mu::value_type *, int)
This function calculates the selected percentile of the passed array.
mu::value_type parser_Norm(const mu::value_type *, int)
This function calculates the vector norm of the elements in the passed array.
mu::value_type parser_or(const mu::value_type *, int)
This function calculates the logical OR operation between all elements in the passed array.
mu::value_type parser_Max(const mu::value_type *, int)
This function calculates the maximal value of all elements in the passed array.
mu::value_type parser_Cnt(const mu::value_type *, int)
This functioon simply returns the number of elements in its array (even the invalid ones).
mu::value_type parser_Min(const mu::value_type *, int)
This function calculates the minimal value of all elements in the passed array.
mu::value_type parser_and(const mu::value_type *, int)
This function calculates the logical AND operation between all elements in the passed array.
mu::value_type parser_Num(const mu::value_type *, int)
This function returns the number of valid elements in its array.
mu::value_type parser_Avg(const mu::value_type *, int)
This function calculates the average of all elements in passed array.
This file contains the class definition of the muparser engine.
#define _nrT(x)
Activate this option in order to compile with OpenMP support.
std::complex< double > intPower(const std::complex< double > &, int)
This function calculates the power of a value with the specialization that the exponent is an integer...
CONSTDATA date::last_spec last
CONSTDATA date::month dec
Namespace for mathematical applications.
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
value_type(* fun_type9)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
int(* identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal)
Callback used for functions that identify values in a string.
value_type(* fun_type6)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
value_type(* strfun_type2)(const char_type *, value_type)
Callback type used for functions taking a string and a value as arguments.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
value_type(* strfun_type3)(const char_type *, value_type, value_type)
Callback type used for functions taking a string and two values as arguments.
value_type *(* facfun_type)(const char_type *, void *)
Callback used for variable creation factory functions.
bool isnan(const value_type &v)
std::vector< value_type > parser_logtoidx(const value_type *v, int n)
Adaption of the logtoidx() function for 1D data arrays.
value_type operator/(const value_type &__x, const value_type &__y)
Custom implementation for the complex division operator with a scalar optimization.
value_type(* fun_type10)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
static std::string printVector(const valbuf_type &buffer, int nElems)
Simple helper function to print the buffer's contents.
value_type(* strfun_type1)(const char_type *)
Callback type used for functions taking a string as an argument.
std::map< string_type, value_type > valmap_type
Type used for storing constants.
std::vector< double > real(const std::vector< value_type > &vVec)
static bool isDelim(char c)
value_type(* fun_type2)(const value_type &, const value_type &)
Callback type used for functions with two arguments.
string_type::value_type char_type
The character type used by the parser.
std::vector< double > imag(const std::vector< value_type > &vVec)
static bool stepIsStillPossible(const mu::value_type ¤t, const mu::value_type &last, const mu::value_type &d)
Determines, whether the passed step is still in valid range and therefore can be done to expand the v...
value_type(* fun_type7)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
std::vector< value_type > valbuf_type
Type used for storing an array of values.
value_type(* fun_type5)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
std::map< string_type, ParserCallback > funmap_type
Container for Callback objects.
value_type(* fun_type1)(const value_type &)
Callback type used for functions with a single arguments.
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
@ cmADD
Operator item: add.
@ cmGE
Operator item: greater or equal.
@ cmLT
Operator item: less than.
@ cmPOW
Operator item: y to the power of ...
@ cmASSIGN
Operator item: Assignment operator.
@ cmARG_SEP
function argument separator
@ cmLE
Operator item: less or equal.
@ cmBO
Operator item: opening bracket.
@ cmMUL
Operator item: multiply.
@ cmSTRING
Code for a string token.
@ cmDIV
Operator item: division.
@ cmENDIF
For use in the ternary if-then-else operator.
@ cmOPRT_INFIX
code for infix operators
@ cmBC
Operator item: closing bracket.
@ cmOPRT_BIN
user defined binary operator
@ cmIF
For use in the ternary if-then-else operator.
@ cmUNKNOWN
uninitialized item
@ cmNEQ
Operator item: not equal.
@ cmGT
Operator item: greater than.
@ cmEQ
Operator item: equals.
@ cmSUB
Operator item: subtract.
@ cmFUNC_STR
Code for a function with a string parameter.
@ cmFUNC
Code for a generic function item.
@ cmOPRT_POSTFIX
code for postfix operators
@ cmELSE
For use in the ternary if-then-else operator.
value_type operator*(const value_type &__x, const value_type &__y)
Custom implementation for the complex multiplication operator with a scalar optimization.
value_type rint(value_type v)
@ tpDBL
Floating point variables.
@ tpSTR
String type (Function arguments and constants only, no string variables)
@ ecINVALID_NAME
Invalid function, variable or constant name.
@ ecMISSING_PARENS
Missing parens. (Example: "3*sin(3")
@ ecBUILTIN_OVERLOAD
Trying to overload builtin operator.
@ ecUNEXPECTED_EOF
Unexpected end of formula. (Example: "2+sin(")
@ ecNAME_CONFLICT
Name conflict.
@ ecSTRING_EXPECTED
A string function has been called with a different type of argument.
@ ecTOO_MANY_PARAMS
Too many function parameters.
@ ecVAL_EXPECTED
A numerical function has been called with a non value type of argument.
@ ecSTR_RESULT
result is a string
@ ecUNEXPECTED_ARG
An unexpected argument has been found.
@ ecUNEXPECTED_OPERATOR
Unexpected binary operator found.
@ ecINVALID_INFIX_IDENT
Invalid function, variable or constant name.
@ ecOPRT_TYPE_CONFLICT
binary operators may only be applied to value items of the same type
@ ecINTERNAL_ERROR
Internal error of any kind.
@ ecINVALID_VAR_PTR
Invalid variable pointer.
@ ecUNEXPECTED_ARG_SEP
An unexpected comma has been found. (Example: "1,23")
@ ecUNEXPECTED_CONDITIONAL
@ ecINVALID_FUN_PTR
Invalid callback function pointer.
@ ecTOO_FEW_PARAMS
Too few function parameters. (Example: "ite(1<2,2)")
@ ecINVALID_POSTFIX_IDENT
Invalid function, variable or constant name.
@ ecEMPTY_EXPRESSION
The Expression is empty.
value_type(* fun_type8)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
std::vector< value_type > parser_idxtolog(const value_type *v, int n)
Adaption of the idxtolog() function for 1D data arrays.
value_type(* generic_fun_type)()
Callback type used for functions without arguments.
std::string string_type
The stringtype used by the parser.
value_type(* fun_type4)(const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with four arguments.
@ prPOSTFIX
Postfix operator priority (currently unused)
@ prCMP
comparsion operators
@ prPOW
power operator priority (highest)
@ prMUL_DIV
multiplication/division
value_type(* fun_type0)()
Callback type used for functions without arguments.
value_type(* fun_type3)(const value_type &, const value_type &, const value_type &)
Callback type used for functions with three arguments.
EOprtAssociativity
Parser operator precedence values.
Resample_Real(* func)(Resample_Real t)
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
Describes an already evaluated data access, which can be reconstructed from the current parser state.
This structure defines the overall expression target, if it is composed out of a temporary vector lik...
void create(StringView sTargets, const varmap_type &usedVars)
Create a expression target made up from multiple variables.
void assign(const valbuf_type &buffer, int nResults)
Assign the calculated values to the target vector components.
static T Pow(const T &v1, const T &v2)
Defines a single parser state, which contains all necessary information for evaluating a single expre...
VectorEvaluation m_vectEval
ParserByteCode m_byteCode
valbuf_type m_stackBuffer
This structure contains the necessary data to resolve all preevaluated vectors.
void create(const std::string &sTargetVect)
Create a standard vector pre- evaluation.
@ EVALTYPE_VECTOR_EXPANSION
std::vector< int > m_componentDefs
std::string toString(int)
Converts an integer to a string without the Settings bloat.