C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2016-10-18 13:17:34 +11:00
parent 061d61ecc9
commit d96275b5d0
3 changed files with 26 additions and 7 deletions

View File

@ -2436,9 +2436,10 @@ namespace exprtk
/* /*
Permit symbols that contain a 'dot' Permit symbols that contain a 'dot'
Allowed : abc.xyz, a123.xyz, abc.123, abc_.xyz a123_.xyz abc._123 Allowed : abc.xyz, a123.xyz, abc.123, abc_.xyz a123_.xyz abc._123
Disallowed: abc.<white-space>, abc.<eof>, abc.<operator +,-,*,/...> Disallowed: .abc, abc.<white-space>, abc.<eof>, abc.<operator +,-,*,/...>
*/ */
if ( if (
(s_itr_ != initial_itr) &&
!is_end(s_itr_ + 1) && !is_end(s_itr_ + 1) &&
details::is_letter_or_digit(*s_itr_ + 1) && details::is_letter_or_digit(*s_itr_ + 1) &&
('_' != (*s_itr_ + 1)) ('_' != (*s_itr_ + 1))
@ -17071,11 +17072,13 @@ namespace exprtk
for (std::size_t i = 1; i < symbol.size(); ++i) for (std::size_t i = 1; i < symbol.size(); ++i)
{ {
if ( if (
(!details::is_letter(symbol[i])) && !details::is_letter_or_digit(symbol[i]) &&
(!details:: is_digit(symbol[i])) &&
('_' != symbol[i]) ('_' != symbol[i])
) )
{ {
if (('.' == symbol[i]) && (i < (symbol.size() - 1)))
continue;
else
return false; return false;
} }
} }
@ -17095,11 +17098,13 @@ namespace exprtk
for (std::size_t i = 1; i < symbol.size(); ++i) for (std::size_t i = 1; i < symbol.size(); ++i)
{ {
if ( if (
(!details::is_letter(symbol[i])) && !details::is_letter_or_digit(symbol[i]) &&
(!details:: is_digit(symbol[i])) &&
('_' != symbol[i]) ('_' != symbol[i])
) )
{ {
if (('.' == symbol[i]) && (i < (symbol.size() - 1)))
continue;
else
return false; return false;
} }
} }
@ -17518,8 +17523,19 @@ namespace exprtk
{ {
return details::is_function(expr.control_block_->expr); return details::is_function(expr.control_block_->expr);
} }
static inline bool is_null(const expression<T>& expr)
{
return details::is_null_node(expr.control_block_->expr);
}
}; };
template <typename T>
inline bool is_valid(const expression<T>& expr)
{
return !expression_helper<T>::is_null(expr);
}
namespace parser_error namespace parser_error
{ {
enum error_mode enum error_mode

View File

@ -65,6 +65,7 @@ void composite()
for (std::size_t i = 0; i < parser.error_count(); ++i) for (std::size_t i = 0; i < parser.error_count(); ++i)
{ {
error_t error = parser.get_error(i); error_t error = parser.get_error(i);
printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n", printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
static_cast<unsigned int>(i), static_cast<unsigned int>(i),
static_cast<unsigned int>(error.token.position), static_cast<unsigned int>(error.token.position),

View File

@ -291,6 +291,8 @@ of C++ compilers:
+----------+---------------------------------------------------------+ +----------+---------------------------------------------------------+
| nequal | Not-equal test between x and y using normalized epsilon | | nequal | Not-equal test between x and y using normalized epsilon |
+----------+---------------------------------------------------------+ +----------+---------------------------------------------------------+
| pow | x to the power of y. (eg: pow(x,y) == x ^ y) |
+----------+---------------------------------------------------------+
| root | Nth-Root of x. where n is a positive integer. | | root | Nth-Root of x. where n is a positive integer. |
| | (eg: root(x,3) == x^(1/3)) | | | (eg: root(x,3) == x^(1/3)) |
+----------+---------------------------------------------------------+ +----------+---------------------------------------------------------+