From 260c14a3f69329a2cdfd4ea1d74f61e8438540a7 Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Wed, 30 Sep 2020 13:54:18 +0200 Subject: [PATCH] ExpressionParser: Allow sequences of unary operators, like '!!x=0' (fixes #89) --- src/storm-parsers/parser/ExpressionCreator.cpp | 14 +++++++------- src/storm-parsers/parser/ExpressionCreator.h | 2 +- src/storm-parsers/parser/ExpressionParser.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/storm-parsers/parser/ExpressionCreator.cpp b/src/storm-parsers/parser/ExpressionCreator.cpp index f9a8ad0c2..f8cc19ea6 100644 --- a/src/storm-parsers/parser/ExpressionCreator.cpp +++ b/src/storm-parsers/parser/ExpressionCreator.cpp @@ -141,18 +141,18 @@ namespace storm { return manager.boolean(false); } - storm::expressions::Expression ExpressionCreator::createUnaryExpression(boost::optional const& operatorType, storm::expressions::Expression const& e1, bool& pass) const { + storm::expressions::Expression ExpressionCreator::createUnaryExpression(std::vector 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; } diff --git a/src/storm-parsers/parser/ExpressionCreator.h b/src/storm-parsers/parser/ExpressionCreator.h index fb034c95e..8115856de 100644 --- a/src/storm-parsers/parser/ExpressionCreator.h +++ b/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 const& operatorType, storm::expressions::Expression const& e1, bool& pass) const; + storm::expressions::Expression createUnaryExpression(std::vector 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; diff --git a/src/storm-parsers/parser/ExpressionParser.cpp b/src/storm-parsers/parser/ExpressionParser.cpp index 9c371e4ac..4c8e0b676 100644 --- a/src/storm-parsers/parser/ExpressionParser.cpp +++ b/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) {