17 #include <boost/algorithm/string.hpp>
58 m_vm =
new VirtualMachine();
63 std::string trimmedExpression = boost::algorithm::trim_copy_if(
expression, boost::is_any_of(
"\""));
68 Grammar<std::string::const_iterator>
grammar;
71 std::string::const_iterator expressionIter = trimmedExpression.begin();
72 std::string::const_iterator expressionEnd = trimmedExpression.end();
73 using boost::spirit::ascii::space_type;
74 bool r = phrase_parse(expressionIter, expressionEnd,
grammar, space_type(), expr);
75 std::string remainingExpression(expressionIter, expressionEnd);
77 if (remainingExpression.length() > 0) {
78 throw std::runtime_error(
"Did you forget an operator? This was not parsed: '" + remainingExpression +
"'");
90 std::vector<std::string> vars;
92 if (element.isProxy() &&
std::find(vars.begin(),vars.end(),element.proxyVarName()) == vars.end() ) {
93 vars.push_back( element.proxyVarName() );
108 else throw std::runtime_error(
"Unable to evaluate vector quantity as a boolean");
114 if (
result.isScalar())
return result.scalarValue<
double>();
115 else throw std::runtime_error(
"Unable to evaluate vector quantity as a double");
121 if (
result.isVector())
return result.vectorValue<
int>();
122 else throw std::runtime_error(
"Unable to evaluate scalar quantity as a vector");