1 #ifndef _utl_ExpressionParser_h_
2 #define _utl_ExpressionParser_h_
12 #include <utl/SymbolTable.h>
14 #include <utl/ExpressionParser.h>
15 #include <utl/AugerUnits.h>
16 #include <utl/AugerException.h>
17 #include <utl/ErrorLogger.h>
21 #include <boost/version.hpp>
22 #if BOOST_VERSION >= 103800
23 # define BOOST_SPIRIT_USE_OLD_NAMESPACE
24 # include <boost/spirit/include/classic_parser.hpp>
25 # include <boost/spirit/include/classic.hpp>
26 # include <boost/spirit/include/phoenix1_binders.hpp>
27 # include <boost/spirit/include/phoenix1_functions.hpp>
29 # include <boost/spirit/core/parser.hpp>
30 # include <boost/spirit.hpp>
31 # include <boost/spirit/phoenix/binders.hpp>
32 # include <boost/spirit/phoenix/primitives.hpp>
33 # include <boost/spirit/phoenix/functions.hpp>
45 template<
class Grammar,
class Symbols>
53 Evaluate(
const std::string& expression_in)
58 std::string::iterator
firstChar = expression.begin();
59 const std::string::iterator
lastChar = expression.end();
60 boost::spirit::parse_info<std::string::iterator>
info;
66 Grammar(result, Symbols::GetSymbolMap()) :
67 Grammar(result, Symbols::GetSymbolMap(),
fVariables)),
68 boost::spirit::space_p
71 std::ostringstream err;
72 const int errPosition = info.stop -
firstChar;
73 const char errChar = expression[errPosition];
74 if (errChar ==
'-' || errChar ==
'+')
76 if (errChar ==
'(' || errChar ==
')')
79 err <<
"Parsing error";
80 err <<
" at location " << errPosition <<
" \'" << errChar <<
"\'";
83 firstChar = info.stop;
84 }
else if (!info.full) {
85 const std::string err =
"Parsing incomplete";
89 }
while(!info.full && info.hit);
boost::spirit::parse_info< std::string::iterator > info
std::string::iterator firstChar
Exception for errors encountered when parsing XML.
int GetNVariables() const
void SetVariable(const std::string &name, const double &v)
ExpressionParser()=default
std::map< std::string, double > SymbolTable
const SymbolTable & GetVariables() const
const std::string::iterator lastChar
ExpressionParser(utl::SymbolTable &variables)
utl::SymbolTable fVariables
double GetVariable(const std::string &name) const
#define ERROR(message)
Macro for logging error messages.
bool HasVariable(const std::string &name) const
SymbolTable & GetVariables()