Browse Source

moved integer declarations in pgcl programs to separate variable declaration section

Former-commit-id: 0d6b5532ae [formerly 9c894fa4d6]
Former-commit-id: 9ff8c45a66
tempestpy_adaptions
dehnert 8 years ago
parent
commit
f1616ac1cc
  1. 15
      src/parser/PgclParser.cpp
  2. 8
      src/parser/PgclParser.h

15
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<storm::pgcl::AssignmentStatement> 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<std::vector<storm::expressions::Variable> > parameters, std::vector<std::shared_ptr<storm::pgcl::Statement> > statements) {
storm::pgcl::PgclProgram PgclParser::createProgram(std::string const& programName, boost::optional<std::vector<storm::expressions::Variable>> parameters, std::vector<std::shared_ptr<storm::pgcl::AssignmentStatement>> const& variableDeclarations, std::vector<std::shared_ptr<storm::pgcl::Statement>> statements) {
// Creates an empty paramter list in case no parameters were given.
std::vector<storm::expressions::Variable> params;
if(parameters != boost::none) {

8
src/parser/PgclParser.h

@ -67,8 +67,6 @@ namespace storm {
qi::rule<Iterator, std::shared_ptr<storm::pgcl::ProbabilisticBranch>(), Skipper> probabilisticBranch;
qi::rule<Iterator, std::shared_ptr<storm::pgcl::AssignmentStatement>(), Skipper> assignmentStatement;
qi::rule<Iterator, storm::expressions::Variable(), Skipper> declaration;
qi::rule<Iterator, storm::expressions::Variable(), Skipper> doubleDeclaration;
qi::rule<Iterator, std::shared_ptr<storm::pgcl::AssignmentStatement>(), Skipper> integerDeclarationStatement;
qi::rule<Iterator, std::shared_ptr<storm::pgcl::ObserveStatement>(), Skipper> observeStatement;
qi::rule<Iterator, storm::expressions::Expression(), Skipper> expression;
qi::rule<Iterator, storm::pgcl::BooleanExpression(), Skipper> booleanCondition;
@ -76,6 +74,10 @@ namespace storm {
qi::rule<Iterator, std::string(), Skipper> variableName;
qi::rule<Iterator, std::string(), Skipper> programName;
qi::rule<Iterator, std::vector<std::shared_ptr<storm::pgcl::AssignmentStatement>>(), Skipper> variableDeclarations;
qi::rule<Iterator, std::shared_ptr<storm::pgcl::AssignmentStatement>(), Skipper> integerDeclaration;
qi::rule<Iterator, storm::expressions::Variable(), Skipper> doubleDeclaration;
/// Denotes the invalid identifiers, which are later passed to the expression parser.
struct keywordsStruct : qi::symbols<char, uint_fast64_t> {
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<std::vector<storm::expressions::Variable> > parameters, std::vector<std::shared_ptr<storm::pgcl::Statement> > statements);
storm::pgcl::PgclProgram createProgram(std::string const& programName, boost::optional<std::vector<storm::expressions::Variable> > parameters, std::vector<std::shared_ptr<storm::pgcl::AssignmentStatement>> const& variableDeclarations, std::vector<std::shared_ptr<storm::pgcl::Statement> > statements);
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::AssignmentStatement> createIntegerDeclarationStatement(std::string const& variableName, storm::expressions::Expression const& assignedExpression);

Loading…
Cancel
Save