From 6f6773f8ca47978ad97bcd425076afedbe6d2eb1 Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Wed, 19 Aug 2020 12:05:21 +0200 Subject: [PATCH] PgclParser: Do not reject variable names with a keyword as proper prefix. (fixes GitHub issue #84) --- src/storm-pgcl/parser/PgclParser.cpp | 7 ++++++- src/storm-pgcl/parser/PgclParser.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/storm-pgcl/parser/PgclParser.cpp b/src/storm-pgcl/parser/PgclParser.cpp index 2d8fff4a1..143073f6d 100755 --- a/src/storm-pgcl/parser/PgclParser.cpp +++ b/src/storm-pgcl/parser/PgclParser.cpp @@ -111,7 +111,8 @@ namespace storm { expression.name("expression"); booleanCondition = expressionParser[qi::_val = phoenix::bind(&PgclParser::createBooleanExpression, phoenix::ref(*this), qi::_1)]; uniformExpression = (qi::lit("unif") >> qi::lit("(") >> qi::int_ >> qi::lit(",") >> qi::int_ >> qi::lit(")"))[qi::_val = phoenix::bind(&PgclParser::createUniformExpression, phoenix::ref(*this), qi::_1, qi::_2)]; - variableName %= (+(qi::alnum | qi::lit("_"))) - invalidIdentifiers; + variableName %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]][qi::_pass = phoenix::bind(&PgclParser::isValidIdentifier, phoenix::ref(*this), qi::_1)]; + variableName.name("variable name"); programName %= +(qi::alnum | qi::lit("_")); programName.name("program name"); @@ -181,6 +182,10 @@ namespace storm { return *result; } + bool PgclParser::isValidIdentifier(std::string const& identifier) { + return this->invalidIdentifiers.find(identifier) == nullptr; + } + storm::expressions::Variable PgclParser::declareDoubleVariable(std::string const& variableName) { storm::expressions::Variable variable = expressionManager->declareRationalVariable(variableName); this->identifiers_.add(variableName, variable.getExpression()); diff --git a/src/storm-pgcl/parser/PgclParser.h b/src/storm-pgcl/parser/PgclParser.h index 0e31094b9..e1196b0c3 100755 --- a/src/storm-pgcl/parser/PgclParser.h +++ b/src/storm-pgcl/parser/PgclParser.h @@ -140,6 +140,7 @@ namespace storm { // Constructors for the single program parts. They just wrap the statement constructors and throw exceptions in case something unexpected was parsed. storm::pgcl::PgclProgram createProgram(std::string const& programName, boost::optional > parameters, std::vector> const& variableDeclarations, std::vector > const& statements); + bool isValidIdentifier(std::string const& identifier); storm::expressions::Variable declareDoubleVariable(std::string const& variableName); std::shared_ptr createAssignmentStatement(std::string const& variableName, boost::variant const& assignedExpression); std::shared_ptr createIntegerDeclarationStatement(std::string const& variableName, storm::expressions::Expression const& assignedExpression);