diff --git a/src/parser/PgclParser.cpp b/src/parser/PgclParser.cpp index 7ca50095e..bfa708207 100755 --- a/src/parser/PgclParser.cpp +++ b/src/parser/PgclParser.cpp @@ -70,19 +70,22 @@ namespace storm { */ // Rough program structure program = (qi::lit("function ") >> programName >> qi::lit("(") >> -(doubleDeclaration % qi::lit(",")) >> qi::lit(")") >> qi::lit("{") >> + variableDeclarations >> sequenceOfStatements >> - qi::lit("}")) - [qi::_val = phoenix::bind(&PgclParser::createProgram, phoenix::ref(*this), qi::_1, qi::_2, qi::_3)]; + qi::lit("}"))[qi::_val = phoenix::bind(&PgclParser::createProgram, phoenix::ref(*this), qi::_1, qi::_2, qi::_3, qi::_4)]; sequenceOfStatements %= +(statement); + variableDeclarations %= qi::lit("var") >> qi::lit("{") >> +integerDeclaration >> qi::lit("}"); + variableDeclarations.name("variable declarations"); + // Statements statement %= simpleStatement | compoundStatement; - simpleStatement %= assignmentStatement | integerDeclarationStatement | observeStatement; + simpleStatement %= assignmentStatement | observeStatement; compoundStatement %= ifElseStatement | loopStatement | branchStatement; // Simple statements doubleDeclaration = (qi::lit("double ") >> variableName)[qi::_val = phoenix::bind(&PgclParser::declareDoubleVariable, phoenix::ref(*this), qi::_1)]; - integerDeclarationStatement = (qi::lit("int ") >> variableName >> qi::lit(":=") >> expression >> qi::lit(";"))[qi::_val = phoenix::bind(&PgclParser::createIntegerDeclarationStatement, phoenix::ref(*this), qi::_1, qi::_2)]; + integerDeclaration = (qi::lit("int ") >> variableName >> qi::lit(":=") >> expression >> qi::lit(";"))[qi::_val = phoenix::bind(&PgclParser::createIntegerDeclarationStatement, phoenix::ref(*this), qi::_1, qi::_2)]; assignmentStatement = (variableName >> qi::lit(":=") >> (expression | uniformExpression) >> qi::lit(";"))[qi::_val = phoenix::bind(&PgclParser::createAssignmentStatement, phoenix::ref(*this), qi::_1, qi::_2)]; observeStatement = (qi::lit("observe") >> qi::lit("(") >> booleanCondition >> qi::lit(")") >> qi::lit(";"))[qi::_val = phoenix::bind(&PgclParser::createObserveStatement, phoenix::ref(*this), qi::_1)]; @@ -117,7 +120,7 @@ namespace storm { qi::on_success(probabilisticBranch, setLocationInfoFunction); qi::on_success(loopStatement, setLocationInfoFunction); qi::on_success(ifElseStatement, setLocationInfoFunction); - qi::on_success(integerDeclarationStatement, setLocationInfoFunction); + qi::on_success(integerDeclaration, setLocationInfoFunction); // Adds dummy to the 0-th location. std::shared_ptr dummy(new storm::pgcl::AssignmentStatement()); @@ -135,7 +138,7 @@ namespace storm { * throw excpetions in case something unexpected was parsed, e.g. * (x+5) as a boolean expression, or types of assignments don't match. */ - storm::pgcl::PgclProgram PgclParser::createProgram(std::string const& programName, boost::optional > parameters, std::vector > statements) { + storm::pgcl::PgclProgram PgclParser::createProgram(std::string const& programName, boost::optional> parameters, std::vector> const& variableDeclarations, std::vector> statements) { // Creates an empty paramter list in case no parameters were given. std::vector params; if(parameters != boost::none) { diff --git a/src/parser/PgclParser.h b/src/parser/PgclParser.h index 23da1d2e9..7fd3ded71 100755 --- a/src/parser/PgclParser.h +++ b/src/parser/PgclParser.h @@ -67,8 +67,6 @@ namespace storm { qi::rule(), Skipper> probabilisticBranch; qi::rule(), Skipper> assignmentStatement; qi::rule declaration; - qi::rule doubleDeclaration; - qi::rule(), Skipper> integerDeclarationStatement; qi::rule(), Skipper> observeStatement; qi::rule expression; qi::rule booleanCondition; @@ -76,6 +74,10 @@ namespace storm { qi::rule variableName; qi::rule programName; + qi::rule>(), Skipper> variableDeclarations; + qi::rule(), Skipper> integerDeclaration; + qi::rule doubleDeclaration; + /// Denotes the invalid identifiers, which are later passed to the expression parser. struct keywordsStruct : qi::symbols { keywordsStruct() { @@ -135,7 +137,7 @@ namespace storm { void enableExpressions(); // 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 > statements); + storm::pgcl::PgclProgram createProgram(std::string const& programName, boost::optional > parameters, std::vector> const& variableDeclarations, std::vector > statements); 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);