From a829c52a0d8df2c12d054d2a5c80a411f11f99dd Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Fri, 10 May 2019 13:08:16 +0200 Subject: [PATCH] ExpressionParser can now parse round expressions. --- src/storm-parsers/parser/ExpressionCreator.cpp | 11 +++++++++++ src/storm-parsers/parser/ExpressionCreator.h | 1 + src/storm-parsers/parser/ExpressionParser.cpp | 10 +++++++++- src/storm-parsers/parser/ExpressionParser.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/storm-parsers/parser/ExpressionCreator.cpp b/src/storm-parsers/parser/ExpressionCreator.cpp index 682342e29..f9a8ad0c2 100644 --- a/src/storm-parsers/parser/ExpressionCreator.cpp +++ b/src/storm-parsers/parser/ExpressionCreator.cpp @@ -220,6 +220,17 @@ namespace storm { return manager.boolean(false); } + storm::expressions::Expression ExpressionCreator::createRoundExpression(storm::expressions::Expression const& e1, bool& pass) const { + if (this->createExpressions) { + try { + return storm::expressions::round(e1); + } catch (storm::exceptions::InvalidTypeException const& e) { + pass = false; + } + } + return manager.boolean(false); + } + storm::expressions::Expression ExpressionCreator::getIdentifierExpression(std::string const& identifier, bool& pass) const { if (this->createExpressions) { STORM_LOG_THROW(this->identifiers != nullptr, storm::exceptions::WrongFormatException, "Unable to substitute identifier expressions without given mapping."); diff --git a/src/storm-parsers/parser/ExpressionCreator.h b/src/storm-parsers/parser/ExpressionCreator.h index 4c137325b..fb034c95e 100644 --- a/src/storm-parsers/parser/ExpressionCreator.h +++ b/src/storm-parsers/parser/ExpressionCreator.h @@ -70,6 +70,7 @@ namespace storm { storm::expressions::Expression createBooleanLiteralExpression(bool value, bool& pass) const; storm::expressions::Expression createMinimumMaximumExpression(storm::expressions::Expression const& e1, storm::expressions::OperatorType const& operatorType, storm::expressions::Expression const& e2, bool& pass) const; storm::expressions::Expression createFloorCeilExpression(storm::expressions::OperatorType const& operatorType, storm::expressions::Expression const& e1, bool& pass) const; + storm::expressions::Expression createRoundExpression(storm::expressions::Expression const& e1, bool& pass) const; storm::expressions::Expression getIdentifierExpression(std::string const& identifier, bool& pass) const; diff --git a/src/storm-parsers/parser/ExpressionParser.cpp b/src/storm-parsers/parser/ExpressionParser.cpp index deaaa93bc..0596b1b4e 100644 --- a/src/storm-parsers/parser/ExpressionParser.cpp +++ b/src/storm-parsers/parser/ExpressionParser.cpp @@ -50,6 +50,13 @@ namespace storm { } floorCeilExpression.name("floor/ceil expression"); + if (allowBacktracking) { + roundExpression = ((qi::lit("round") >> qi::lit("(")) >> expression >> qi::lit(")"))[qi::_val = phoenix::bind(&ExpressionCreator::createRoundExpression, phoenix::ref(*expressionCreator), qi::_1, qi::_pass)]; + } else { + roundExpression = ((qi::lit("round") >> qi::lit("(")) > expression > qi::lit(")"))[qi::_val = phoenix::bind(&ExpressionCreator::createRoundExpression, phoenix::ref(*expressionCreator), qi::_1, qi::_pass)]; + } + roundExpression.name("round expression"); + if (allowBacktracking) { minMaxExpression = ((minMaxOperator_[qi::_a = qi::_1] >> qi::lit("(")) >> expression[qi::_val = qi::_1] >> +(qi::lit(",") >> expression)[qi::_val = phoenix::bind(&ExpressionCreator::createMinimumMaximumExpression, phoenix::ref(*expressionCreator), qi::_val, qi::_a, qi::_1, qi::_pass)]) >> qi::lit(")"); } else { @@ -75,7 +82,7 @@ namespace storm { | qi::int_[qi::_val = phoenix::bind(&ExpressionCreator::createIntegerLiteralExpression, phoenix::ref(*expressionCreator), qi::_1, qi::_pass)]; literalExpression.name("literal expression"); - atomicExpression = floorCeilExpression | prefixPowerModuloExpression | minMaxExpression | (qi::lit("(") >> expression >> qi::lit(")")) | identifierExpression | literalExpression; + 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)]; @@ -173,6 +180,7 @@ namespace storm { qi::on_error(identifierExpression, handler(qi::_1, qi::_2, qi::_3, qi::_4)); qi::on_error(minMaxExpression, handler(qi::_1, qi::_2, qi::_3, qi::_4)); qi::on_error(floorCeilExpression, handler(qi::_1, qi::_2, qi::_3, qi::_4)); + qi::on_error(roundExpression, handler(qi::_1, qi::_2, qi::_3, qi::_4)); } } diff --git a/src/storm-parsers/parser/ExpressionParser.h b/src/storm-parsers/parser/ExpressionParser.h index 4bd3cfaab..7a4b91a39 100644 --- a/src/storm-parsers/parser/ExpressionParser.h +++ b/src/storm-parsers/parser/ExpressionParser.h @@ -232,6 +232,7 @@ namespace storm { qi::rule identifierExpression; qi::rule, Skipper> minMaxExpression; qi::rule, Skipper> floorCeilExpression; + qi::rule roundExpression; qi::rule identifier; // Parser that is used to recognize doubles only (as opposed to Spirit's double_ parser).