Browse Source

ExpressionParser: Allow sequences of unary operators, like '!!x=0' (fixes #89)

tempestpy_adaptions
Tim Quatmann 4 years ago
parent
commit
260c14a3f6
  1. 14
      src/storm-parsers/parser/ExpressionCreator.cpp
  2. 2
      src/storm-parsers/parser/ExpressionCreator.h
  3. 2
      src/storm-parsers/parser/ExpressionParser.cpp

14
src/storm-parsers/parser/ExpressionCreator.cpp

@ -141,18 +141,18 @@ namespace storm {
return manager.boolean(false);
}
storm::expressions::Expression ExpressionCreator::createUnaryExpression(boost::optional<storm::expressions::OperatorType> const& operatorType, storm::expressions::Expression const& e1, bool& pass) const {
storm::expressions::Expression ExpressionCreator::createUnaryExpression(std::vector<storm::expressions::OperatorType> const& operatorTypes, storm::expressions::Expression const& e1, bool& pass) const {
if (this->createExpressions) {
try {
if (operatorType) {
switch (operatorType.get()) {
case storm::expressions::OperatorType::Not: return !e1; break;
case storm::expressions::OperatorType::Minus: return -e1; break;
storm::expressions::Expression result = e1;
for (auto const& op : operatorTypes) {
switch (op) {
case storm::expressions::OperatorType::Not: result = !result; break;
case storm::expressions::OperatorType::Minus: result = -result; break;
default: STORM_LOG_ASSERT(false, "Invalid operation."); break;
}
} else {
return e1;
}
return result;
} catch (storm::exceptions::InvalidTypeException const& e) {
pass = false;
}

2
src/storm-parsers/parser/ExpressionCreator.h

@ -64,7 +64,7 @@ namespace storm {
storm::expressions::Expression createPlusExpression(storm::expressions::Expression const& e1, storm::expressions::OperatorType const& operatorType, storm::expressions::Expression const& e2, bool& pass) const;
storm::expressions::Expression createMultExpression(storm::expressions::Expression const& e1, storm::expressions::OperatorType const& operatorType, storm::expressions::Expression const& e2, bool& pass) const;
storm::expressions::Expression createPowerModuloExpression(storm::expressions::Expression const& e1, storm::expressions::OperatorType const& operatorType, storm::expressions::Expression const& e2, bool& pass) const;
storm::expressions::Expression createUnaryExpression(boost::optional<storm::expressions::OperatorType> const& operatorType, storm::expressions::Expression const& e1, bool& pass) const;
storm::expressions::Expression createUnaryExpression(std::vector<storm::expressions::OperatorType> const& operatorType, storm::expressions::Expression const& e1, bool& pass) const;
storm::expressions::Expression createRationalLiteralExpression(storm::RationalNumber const& value, bool& pass) const;
storm::expressions::Expression createIntegerLiteralExpression(int value, bool& pass) const;
storm::expressions::Expression createBooleanLiteralExpression(bool value, bool& pass) const;

2
src/storm-parsers/parser/ExpressionParser.cpp

@ -87,7 +87,7 @@ namespace storm {
atomicExpression = floorCeilExpression | roundExpression | prefixPowerModuloExpression | minMaxExpression | (qi::lit("(") >> expression >> qi::lit(")")) | identifierExpression | literalExpression;
atomicExpression.name("atomic expression");
unaryExpression = (-unaryOperator_ >> atomicExpression)[qi::_val = phoenix::bind(&ExpressionCreator::createUnaryExpression, phoenix::ref(*expressionCreator), qi::_1, qi::_2, qi::_pass)];
unaryExpression = (*unaryOperator_ >> atomicExpression)[qi::_val = phoenix::bind(&ExpressionCreator::createUnaryExpression, phoenix::ref(*expressionCreator), qi::_1, qi::_2, qi::_pass)];
unaryExpression.name("unary expression");
if (allowBacktracking) {

Loading…
Cancel
Save