Browse Source

PgclParser: Do not reject variable names with a keyword as proper prefix. (fixes GitHub issue #84)

tempestpy_adaptions
Tim Quatmann 4 years ago
parent
commit
6f6773f8ca
  1. 7
      src/storm-pgcl/parser/PgclParser.cpp
  2. 1
      src/storm-pgcl/parser/PgclParser.h

7
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());

1
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<std::vector<storm::expressions::Variable> > parameters, std::vector<std::shared_ptr<storm::pgcl::VariableDeclaration>> const& variableDeclarations, std::vector<std::shared_ptr<storm::pgcl::Statement> > const& statements);
bool isValidIdentifier(std::string const& identifier);
storm::expressions::Variable declareDoubleVariable(std::string const& variableName);
std::shared_ptr<storm::pgcl::AssignmentStatement> createAssignmentStatement(std::string const& variableName, boost::variant<storm::expressions::Expression, storm::pgcl::UniformExpression> const& assignedExpression);
std::shared_ptr<storm::pgcl::VariableDeclaration> createIntegerDeclarationStatement(std::string const& variableName, storm::expressions::Expression const& assignedExpression);

Loading…
Cancel
Save