Browse Source
Removed superfluous grammars and started working on making one PRISM grammar to rule them all.
Removed superfluous grammars and started working on making one PRISM grammar to rule them all.
Former-commit-id: 375acb4699
main
43 changed files with 384 additions and 1479 deletions
-
60src/parser/PrismParser.h
-
253src/parser/prismparser/BaseGrammar.h
-
42src/parser/prismparser/BooleanExpressionGrammar.cpp
-
54src/parser/prismparser/BooleanExpressionGrammar.h
-
38src/parser/prismparser/ConstBooleanExpressionGrammar.cpp
-
47src/parser/prismparser/ConstBooleanExpressionGrammar.h
-
34src/parser/prismparser/ConstDoubleExpressionGrammar.cpp
-
41src/parser/prismparser/ConstDoubleExpressionGrammar.h
-
41src/parser/prismparser/ConstIntegerExpressionGrammar.cpp
-
42src/parser/prismparser/ConstIntegerExpressionGrammar.h
-
23src/parser/prismparser/IdentifierGrammars.cpp
-
42src/parser/prismparser/IdentifierGrammars.h
-
39src/parser/prismparser/Includes.h
-
42src/parser/prismparser/IntegerExpressionGrammar.cpp
-
50src/parser/prismparser/IntegerExpressionGrammar.h
-
123src/parser/prismparser/PrismGrammar.h
-
129src/parser/prismparser/Tokens.h
-
191src/parser/prismparser/VariableState.cpp
-
207src/parser/prismparser/VariableState.h
-
4src/storage/prism/Assignment.cpp
-
19src/storage/prism/Assignment.h
-
6src/storage/prism/BooleanVariable.cpp
-
26src/storage/prism/BooleanVariable.h
-
6src/storage/prism/Command.cpp
-
18src/storage/prism/Command.h
-
6src/storage/prism/IntegerVariable.cpp
-
20src/storage/prism/IntegerVariable.h
-
17src/storage/prism/LocatedInformation.cpp
-
48src/storage/prism/LocatedInformation.h
-
8src/storage/prism/Module.cpp
-
20src/storage/prism/Module.h
-
16src/storage/prism/Program.cpp
-
53src/storage/prism/Program.h
-
2src/storage/prism/RewardModel.cpp
-
14src/storage/prism/RewardModel.h
-
2src/storage/prism/StateReward.cpp
-
15src/storage/prism/StateReward.h
-
2src/storage/prism/TransitionReward.cpp
-
15src/storage/prism/TransitionReward.h
-
12src/storage/prism/Update.cpp
-
21src/storage/prism/Update.h
-
4src/storage/prism/Variable.cpp
-
11src/storage/prism/Variable.h
@ -1,49 +1,35 @@ |
|||
/* * PrismParser.h |
|||
* |
|||
* Created on: Jan 3, 2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_PARSER_PRISMPARSER_H_ |
|||
#define STORM_PARSER_PRISMPARSER_H_ |
|||
|
|||
// All classes of the intermediate representation are used. |
|||
#include "src/ir/IR.h" |
|||
#include "src/storage/prism/Program.h" |
|||
|
|||
// Used for file input. |
|||
#include <istream> |
|||
#include <memory> |
|||
|
|||
namespace storm { |
|||
|
|||
namespace parser { |
|||
|
|||
using namespace storm::ir; |
|||
using namespace storm::ir::expressions; |
|||
|
|||
/* |
|||
* This functions parse the format of the PRISM model checker into an intermediate representation. |
|||
*/ |
|||
|
|||
/*! |
|||
* Parses the given file into the intermediate representation assuming it complies with the |
|||
* PRISM syntax. |
|||
* @param filename the name of the file to parse. |
|||
* @return a shared pointer to the intermediate representation of the PRISM file. |
|||
*/ |
|||
storm::ir::Program PrismParserFromFile(std::string const& filename); |
|||
|
|||
/*! |
|||
* Parses the given input stream into the intermediate representation assuming it complies with |
|||
* the PRISM syntax. |
|||
* @param inputStream the input stream to parse. |
|||
* @param filename the name of the file the input stream belongs to. Used for diagnostics. |
|||
* @return a shared pointer to the intermediate representation of the PRISM file. |
|||
*/ |
|||
storm::ir::Program PrismParser(std::istream& inputStream, std::string const& filename); |
|||
|
|||
} // namespace parser |
|||
|
|||
namespace parser { |
|||
using namespace storm::prism; |
|||
using namespace storm::expressions; |
|||
|
|||
/*! |
|||
* Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax. |
|||
* |
|||
* @param filename the name of the file to parse. |
|||
* @return The resulting PRISM program. |
|||
*/ |
|||
storm::prism::Program PrismParserFromFile(std::string const& filename); |
|||
|
|||
/*! |
|||
* Parses the given input stream into the PRISM storage classes assuming it complies with the PRISM syntax. |
|||
* |
|||
* @param inputStream The input stream to parse. |
|||
* @param filename The name of the file the input stream belongs to. |
|||
* @return The resulting PRISM program. |
|||
*/ |
|||
storm::prism::Program PrismParser(std::istream& inputStream, std::string const& filename); |
|||
|
|||
} // namespace parser |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_PARSER_PRISMPARSER_H_ */ |
@ -1,253 +0,0 @@ |
|||
/* |
|||
* File: Keywords.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 6:03 PM |
|||
*/ |
|||
|
|||
#ifndef BASEGRAMMAR_H |
|||
#define BASEGRAMMAR_H |
|||
|
|||
#include "Includes.h" |
|||
|
|||
#include "VariableState.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This is the base class for all expression grammars. |
|||
* It takes care of implementing a singleton, stores a VariableState and implements some common helper routines. |
|||
*/ |
|||
template <typename T> |
|||
class BaseGrammar { |
|||
public: |
|||
/*! |
|||
* Constructor. |
|||
*/ |
|||
BaseGrammar(std::shared_ptr<VariableState> const& state) : state(state) {} |
|||
|
|||
/*! |
|||
* Create and return a new instance of class T, usually the subclass. |
|||
* @param state VariableState to be given to the constructor. |
|||
* @returns Instance of class T. |
|||
*/ |
|||
static T& instance(std::shared_ptr<VariableState> const& state = nullptr) { |
|||
if (BaseGrammar::instanceObject == nullptr) { |
|||
BaseGrammar::instanceObject = std::shared_ptr<T>(new T(state)); |
|||
if (!state->firstRun) BaseGrammar::instanceObject->secondRun(); |
|||
} |
|||
return *BaseGrammar::instanceObject; |
|||
} |
|||
|
|||
/*! |
|||
* Clear the cached instance. |
|||
*/ |
|||
static void resetInstance() { |
|||
BaseGrammar::instanceObject = nullptr; |
|||
} |
|||
|
|||
/*! |
|||
* Notify the cached object, that we will begin with the second parsing run. |
|||
*/ |
|||
static void secondRun() { |
|||
if (BaseGrammar::instanceObject != nullptr) { |
|||
BaseGrammar::instanceObject->prepareSecondRun(); |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* Create a new boolean literal with the given value. |
|||
* @param value Value of the literal. |
|||
* @returns Boolean literal. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createBoolLiteral(bool value) { |
|||
return std::shared_ptr<BaseExpression>(new BooleanLiteralExpression(value)); |
|||
} |
|||
/*! |
|||
* Create a new double literal with the given value. |
|||
* @param value Value of the literal. |
|||
* @returns Double literal. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createDoubleLiteral(double value) { |
|||
return std::shared_ptr<BaseExpression>(new DoubleLiteralExpression(value)); |
|||
} |
|||
/*! |
|||
* Create a new integer literal with the given value. |
|||
* @param value Value of the literal. |
|||
* @returns Integer literal. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createIntLiteral(int_fast64_t value) { |
|||
return std::shared_ptr<BaseExpression>(new IntegerLiteralExpression(value)); |
|||
} |
|||
|
|||
/*! |
|||
* Create a new plus expression. If addition is true, it will be an addition, otherwise a subtraction. |
|||
* @param left Left operand. |
|||
* @param addition Flag for addition or subtraction. |
|||
* @param right Right operand. |
|||
* @param type Return type. |
|||
* @returns Plus expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createPlus(std::shared_ptr<BaseExpression> const& left, bool addition, std::shared_ptr<BaseExpression> const& right, BaseExpression::ReturnType type) { |
|||
if (addition) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(type, left->clone(), right->clone(), BinaryNumericalFunctionExpression::PLUS)); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(type, left->clone(), right->clone(), BinaryNumericalFunctionExpression::MINUS)); |
|||
} |
|||
} |
|||
/*! |
|||
* Create a new double plus expression. If addition is true, it will be an addition, otherwise a subtraction. |
|||
* @param left Left operand. |
|||
* @param addition Flag for addition or subtraction. |
|||
* @param right Right operand. |
|||
* @returns Double plus expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createDoublePlus(std::shared_ptr<BaseExpression> const& left, bool addition, std::shared_ptr<BaseExpression> const& right) { |
|||
return this->createPlus(left, addition, right, BaseExpression::double_); |
|||
} |
|||
/*! |
|||
* Create a new integer plus expression. If addition is true, it will be an addition, otherwise a subtraction. |
|||
* @param left Left operand. |
|||
* @param addition Flag for addition or subtraction. |
|||
* @param right Right operand. |
|||
* @returns Integer plus expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createIntPlus(std::shared_ptr<BaseExpression> const& left, bool addition, std::shared_ptr<BaseExpression> const& right) { |
|||
return this->createPlus(left, addition, right, BaseExpression::int_); |
|||
} |
|||
|
|||
/*! |
|||
* Create a new integer multiplication expression. |
|||
* @param left Left operand. |
|||
* @param right Right operand. |
|||
* @returns Integer multiplication expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createIntMult(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(BaseExpression::int_, left->clone(), right->clone(), BinaryNumericalFunctionExpression::TIMES)); |
|||
} |
|||
|
|||
/*! |
|||
* Create a new integer multiplication expression. If multiplication is true, it will be an multiplication, otherwise a division. |
|||
* @param left Left operand. |
|||
* @param addition Flag for multiplication or division. |
|||
* @param right Right operand. |
|||
* @returns Integer multiplication expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createDoubleMult(std::shared_ptr<BaseExpression> const& left, bool multiplication, std::shared_ptr<BaseExpression> const& right) { |
|||
if (multiplication) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left->clone(), right->clone(), BinaryNumericalFunctionExpression::TIMES)); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left->clone(), right->clone(), BinaryNumericalFunctionExpression::DIVIDE)); |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* Creates an integer min/max expression. |
|||
* |
|||
* @param min Indicates whether the expression is min or max. |
|||
* @param left The left operand. |
|||
* @param right The right operand. |
|||
* @return An integer min/max expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createIntMinMax(bool min, std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right) { |
|||
if (min) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(BaseExpression::int_, left->clone(), right->clone(), BinaryNumericalFunctionExpression::MIN)); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(BaseExpression::int_, left->clone(), right->clone(), BinaryNumericalFunctionExpression::MAX)); |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* Creates an integer floor/ceil expression. |
|||
* |
|||
* @param floor Indicates whether the expression is a floor expression. |
|||
* @param operand The argument of the floor/ceil operation. |
|||
* @return An integer floor/ceil expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createIntFloorCeil(bool floor, std::shared_ptr<BaseExpression> const& operand) { |
|||
if (floor) { |
|||
return std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(BaseExpression::int_, operand->clone(), UnaryNumericalFunctionExpression::FLOOR)); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(BaseExpression::int_, operand->clone(), UnaryNumericalFunctionExpression::CEIL)); |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* Create a new binary relation expression. |
|||
* @param left Left operand. |
|||
* @param relationType Type of binary relation. |
|||
* @param right Right operand. |
|||
* @returns Binary relation expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createRelation(std::shared_ptr<BaseExpression> const& left, BinaryRelationExpression::RelationType relationType, std::shared_ptr<BaseExpression> const& right) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryRelationExpression(left->clone(), right->clone(), relationType)); |
|||
} |
|||
/*! |
|||
* Create a new negation expression. |
|||
* @param child Expression to be negated. |
|||
* @returns Negation expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createNot(std::shared_ptr<BaseExpression> const& child) { |
|||
return std::shared_ptr<UnaryBooleanFunctionExpression>(new UnaryBooleanFunctionExpression(child->clone(), UnaryBooleanFunctionExpression::NOT)); |
|||
} |
|||
/*! |
|||
* Create a new And expression. |
|||
* @param left Left operand. |
|||
* @param right Right operand. |
|||
* @returns And expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createAnd(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right) { |
|||
return std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(left->clone(), right->clone(), BinaryBooleanFunctionExpression::AND)); |
|||
} |
|||
/*! |
|||
* Create a new Or expression. |
|||
* @param left Left operand. |
|||
* @param right Right operand. |
|||
* @returns Or expression. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> createOr(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right) { |
|||
return std::shared_ptr<BinaryBooleanFunctionExpression>(new BinaryBooleanFunctionExpression(left->clone(), right->clone(), BinaryBooleanFunctionExpression::OR)); |
|||
} |
|||
/*! |
|||
* Retrieve boolean variable by name. |
|||
* @param name Variable name. |
|||
* @returns Boolean variable. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> getBoolVariable(std::string const& name) { |
|||
return std::shared_ptr<BaseExpression>(new VariableExpression(*state->getBooleanVariableExpression(name))); |
|||
} |
|||
/*! |
|||
* Retrieve integer variable by name. |
|||
* @param name Variable name. |
|||
* @returns Integer variable. |
|||
*/ |
|||
std::shared_ptr<BaseExpression> getIntVariable(std::string const& name) { |
|||
return std::shared_ptr<BaseExpression>(new VariableExpression(*state->getIntegerVariableExpression(name))); |
|||
} |
|||
|
|||
/*! |
|||
* Base method to switch to second run. This does nothing. |
|||
* Any subclass that needs to do something in order to proceed to the second run should override this method. |
|||
*/ |
|||
virtual void prepareSecondRun() {} |
|||
|
|||
protected: |
|||
/*! |
|||
* Pointer to variable state. |
|||
*/ |
|||
std::shared_ptr<VariableState> state; |
|||
|
|||
private: |
|||
static std::shared_ptr<T> instanceObject; |
|||
static bool inSecondRun; |
|||
}; |
|||
|
|||
template <typename T> |
|||
std::shared_ptr<T> BaseGrammar<T>::instanceObject; |
|||
} |
|||
} |
|||
} |
|||
#endif /* BASEGRAMMAR_H */ |
|||
|
@ -1,42 +0,0 @@ |
|||
#include "BooleanExpressionGrammar.h"
|
|||
|
|||
#include "IntegerExpressionGrammar.h"
|
|||
#include "ConstBooleanExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
BooleanExpressionGrammar::BooleanExpressionGrammar(std::shared_ptr<VariableState> const& state) |
|||
: BooleanExpressionGrammar::base_type(booleanExpression), BaseGrammar(state) { |
|||
|
|||
booleanExpression %= orExpression; |
|||
booleanExpression.name("boolean expression"); |
|||
|
|||
orExpression = andExpression[qi::_val = qi::_1] >> *(qi::lit("|") >> andExpression)[qi::_val = phoenix::bind(&BaseGrammar::createOr, this, qi::_val, qi::_1)]; |
|||
orExpression.name("boolean expression"); |
|||
|
|||
andExpression = notExpression[qi::_val = qi::_1] >> *(qi::lit("&") >> notExpression)[qi::_val = phoenix::bind(&BaseGrammar::createAnd, this, qi::_val, qi::_1)]; |
|||
andExpression.name("boolean expression"); |
|||
|
|||
notExpression = atomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> atomicBooleanExpression)[qi::_val = phoenix::bind(&BaseGrammar::createNot, this, qi::_1)]; |
|||
notExpression.name("boolean expression"); |
|||
|
|||
atomicBooleanExpression %= (relativeExpression | booleanVariableExpression | this->state->constantBooleanFormulas_ | this->state->booleanFormulas_ | qi::lit("(") >> booleanExpression >> qi::lit(")") | ConstBooleanExpressionGrammar::instance(this->state)); |
|||
atomicBooleanExpression.name("boolean expression"); |
|||
|
|||
relativeExpression = (IntegerExpressionGrammar::instance(this->state) >> relations_ >> IntegerExpressionGrammar::instance(this->state))[qi::_val = phoenix::bind(&BaseGrammar::createRelation, this, qi::_1, qi::_2, qi::_3)]; |
|||
relativeExpression.name("relative expression"); |
|||
|
|||
booleanVariableExpression = IdentifierGrammar::instance(this->state)[qi::_val = phoenix::bind(&BaseGrammar::getBoolVariable, this, qi::_1)]; |
|||
booleanVariableExpression.name("boolean variable"); |
|||
} |
|||
|
|||
void BooleanExpressionGrammar::prepareSecondRun() { |
|||
booleanVariableExpression %= this->state->booleanVariables_; |
|||
booleanVariableExpression.name("boolean variable"); |
|||
} |
|||
|
|||
} // namespace prism
|
|||
} // namespace parser
|
|||
} // namespace storm
|
@ -1,54 +0,0 @@ |
|||
/* |
|||
* File: BooleanExpressionGrammar.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 6:27 PM |
|||
*/ |
|||
|
|||
#ifndef BOOLEANEXPRESSIONGRAMMAR_H |
|||
#define BOOLEANEXPRESSIONGRAMMAR_H |
|||
|
|||
#include "Includes.h" |
|||
#include "VariableState.h" |
|||
#include "IdentifierGrammars.h" |
|||
#include "Tokens.h" |
|||
|
|||
#include <iostream> |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses (non constant) boolean expressions as used in prism models. |
|||
*/ |
|||
class BooleanExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<BooleanExpressionGrammar> { |
|||
public: |
|||
BooleanExpressionGrammar(std::shared_ptr<VariableState> const& state); |
|||
/*! |
|||
* Switch to second run. |
|||
* Variable names may be any valid identifier in the first run, but only defined variables in the second run. |
|||
*/ |
|||
virtual void prepareSecondRun(); |
|||
|
|||
private: |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused> booleanExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> orExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> andExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> notExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> atomicBooleanExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> relativeExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> booleanVariableExpression; |
|||
|
|||
/*! |
|||
* Parser relation operators. |
|||
*/ |
|||
storm::parser::prism::relationalOperatorStruct relations_; |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* BOOLEANEXPRESSIONGRAMMAR_H */ |
@ -1,38 +0,0 @@ |
|||
#include "ConstBooleanExpressionGrammar.h"
|
|||
|
|||
#include "ConstIntegerExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
ConstBooleanExpressionGrammar::ConstBooleanExpressionGrammar(std::shared_ptr<VariableState> const& state) |
|||
: ConstBooleanExpressionGrammar::base_type(constantBooleanExpression), BaseGrammar(state) { |
|||
|
|||
constantBooleanExpression %= constantOrExpression; |
|||
constantBooleanExpression.name("constant boolean expression"); |
|||
|
|||
constantOrExpression = constantAndExpression[qi::_val = qi::_1] >> *(qi::lit("|") >> constantAndExpression)[qi::_val = phoenix::bind(&BaseGrammar::createOr, this, qi::_val, qi::_1)]; |
|||
constantOrExpression.name("constant boolean expression"); |
|||
|
|||
constantAndExpression = constantNotExpression[qi::_val = qi::_1] >> *(qi::lit("&") >> constantNotExpression)[qi::_val = phoenix::bind(&BaseGrammar::createAnd, this, qi::_val, qi::_1)]; |
|||
constantAndExpression.name("constant boolean expression"); |
|||
|
|||
constantNotExpression = constantAtomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> constantAtomicBooleanExpression)[qi::_val = phoenix::bind(&BaseGrammar::createNot, this, qi::_1)]; |
|||
constantNotExpression.name("constant boolean expression"); |
|||
|
|||
constantAtomicBooleanExpression %= (constantRelativeExpression | this->state->constantBooleanFormulas_ | qi::lit("(") >> constantBooleanExpression >> qi::lit(")") | booleanLiteralExpression | booleanConstantExpression); |
|||
constantAtomicBooleanExpression.name("constant boolean expression"); |
|||
|
|||
constantRelativeExpression = (ConstIntegerExpressionGrammar::instance(this->state) >> relations_ >> ConstIntegerExpressionGrammar::instance(this->state))[qi::_val = phoenix::bind(&BaseGrammar::createRelation, this, qi::_1, qi::_2, qi::_3)]; |
|||
constantRelativeExpression.name("constant boolean expression"); |
|||
|
|||
booleanConstantExpression %= (this->state->booleanConstants_ | booleanLiteralExpression); |
|||
booleanConstantExpression.name("boolean constant or literal"); |
|||
|
|||
booleanLiteralExpression = qi::bool_[qi::_val = phoenix::bind(&BaseGrammar::createBoolLiteral, this, qi::_1)]; |
|||
booleanLiteralExpression.name("boolean literal"); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,47 +0,0 @@ |
|||
/* |
|||
* File: ConstBooleanExpressionGrammar.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 6:34 PM |
|||
*/ |
|||
|
|||
#ifndef CONSTBOOLEANEXPRESSIONGRAMMAR_H |
|||
#define CONSTBOOLEANEXPRESSIONGRAMMAR_H |
|||
|
|||
#include "Includes.h" |
|||
#include "VariableState.h" |
|||
#include "IdentifierGrammars.h" |
|||
#include "Tokens.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses constant boolean expression as used in prism models. |
|||
*/ |
|||
class ConstBooleanExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<ConstBooleanExpressionGrammar> { |
|||
public: |
|||
ConstBooleanExpressionGrammar(std::shared_ptr<VariableState> const& state); |
|||
|
|||
|
|||
private: |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused> constantBooleanExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantOrExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantAndExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantNotExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantAtomicBooleanExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantRelativeExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> booleanConstantExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> booleanLiteralExpression; |
|||
|
|||
storm::parser::prism::relationalOperatorStruct relations_; |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* CONSTBOOLEANEXPRESSIONGRAMMAR_H */ |
|||
|
@ -1,34 +0,0 @@ |
|||
#include "ConstDoubleExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
ConstDoubleExpressionGrammar::ConstDoubleExpressionGrammar(std::shared_ptr<VariableState> const& state) |
|||
: ConstDoubleExpressionGrammar::base_type(constantDoubleExpression), BaseGrammar(state) { |
|||
|
|||
constantDoubleExpression %= constantDoublePlusExpression; |
|||
constantDoubleExpression.name("constant double expression"); |
|||
|
|||
constantDoublePlusExpression %= constantDoubleMultExpression[qi::_val = qi::_1] >> *((qi::lit("+")[qi::_a = true] | qi::lit("-")[qi::_a = false]) >> constantDoubleMultExpression) |
|||
[qi::_val = phoenix::bind(&BaseGrammar::createDoublePlus, this, qi::_val, qi::_a, qi::_1)]; |
|||
constantDoublePlusExpression.name("constant double expression"); |
|||
|
|||
constantDoubleMultExpression %= constantAtomicDoubleExpression[qi::_val = qi::_1] >> *((qi::lit("*")[qi::_a = true] | qi::lit("/")[qi::_a = false]) >> constantAtomicDoubleExpression) |
|||
[qi::_val = phoenix::bind(&BaseGrammar::createDoubleMult, this, qi::_val, qi::_a, qi::_1)]; |
|||
constantDoubleMultExpression.name("constant double expression"); |
|||
|
|||
constantAtomicDoubleExpression %= (qi::lit("(") >> constantDoubleExpression >> qi::lit(")") | this->state->constantDoubleFormulas_ | this->state->constantIntegerFormulas_ | doubleConstantExpression); |
|||
constantAtomicDoubleExpression.name("constant double expression"); |
|||
|
|||
doubleConstantExpression %= (this->state->doubleConstants_ | this->state->integerConstants_ | doubleLiteralExpression); |
|||
doubleConstantExpression.name("double constant or literal"); |
|||
|
|||
doubleLiteralExpression = qi::double_[qi::_val = phoenix::bind(&BaseGrammar::createDoubleLiteral, this, qi::_1)]; |
|||
doubleLiteralExpression.name("double literal"); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
@ -1,41 +0,0 @@ |
|||
/* |
|||
* File: ConstDoubleExpressionGrammar.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 7:04 PM |
|||
*/ |
|||
|
|||
#ifndef CONSTDOUBLEEXPRESSIONGRAMMAR_H |
|||
#define CONSTDOUBLEEXPRESSIONGRAMMAR_H |
|||
|
|||
#include "Includes.h" |
|||
#include "VariableState.h" |
|||
#include "IdentifierGrammars.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses constant double expressions as used in prism models. |
|||
*/ |
|||
class ConstDoubleExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<ConstDoubleExpressionGrammar> { |
|||
public: |
|||
ConstDoubleExpressionGrammar(std::shared_ptr<VariableState> const& state); |
|||
|
|||
private: |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused> constantDoubleExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> constantDoublePlusExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> constantDoubleMultExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantAtomicDoubleExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> doubleConstantExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> doubleLiteralExpression; |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* CONSTDOUBLEEXPRESSIONGRAMMAR_H */ |
|||
|
@ -1,41 +0,0 @@ |
|||
#include "ConstIntegerExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
|
|||
ConstIntegerExpressionGrammar::ConstIntegerExpressionGrammar(std::shared_ptr<VariableState> const& state) |
|||
: ConstIntegerExpressionGrammar::base_type(constantIntegerExpression), BaseGrammar(state) { |
|||
|
|||
constantIntegerExpression %= constantIntegerPlusExpression; |
|||
constantIntegerExpression.name("constant integer expression"); |
|||
|
|||
constantIntegerPlusExpression = constantIntegerMultExpression[qi::_val = qi::_1] >> *((qi::lit("+")[qi::_a = true] | qi::lit("-")[qi::_a = false]) >> constantIntegerMultExpression) |
|||
[qi::_val = phoenix::bind(&BaseGrammar::createIntPlus, this, qi::_val, qi::_a, qi::_1)]; |
|||
constantIntegerPlusExpression.name("constant integer expression"); |
|||
|
|||
constantIntegerMultExpression %= constantAtomicIntegerExpression[qi::_val = qi::_1] >> *(qi::lit("*") >> constantAtomicIntegerExpression) |
|||
[qi::_val = phoenix::bind(&BaseGrammar::createIntMult, this, qi::_val, qi::_1)]; |
|||
constantIntegerMultExpression.name("constant integer expression"); |
|||
|
|||
constantAtomicIntegerExpression %= (constantIntegerMinMaxExpression | constantIntegerFloorCeilExpression | this->state->constantIntegerFormulas_ | qi::lit("(") >> constantIntegerExpression >> qi::lit(")") | integerConstantExpression); |
|||
constantAtomicIntegerExpression.name("constant integer expression"); |
|||
|
|||
constantIntegerMinMaxExpression = ((qi::lit("min")[qi::_a = true] | qi::lit("max")[qi::_a = false]) >> qi::lit("(") >> constantIntegerExpression >> qi::lit(",") >> constantIntegerExpression >> qi::lit(")"))[qi::_val = phoenix::bind(&BaseGrammar::createIntMinMax, this, qi::_a, qi::_1, qi::_2)]; |
|||
constantIntegerMinMaxExpression.name("integer min/max expression"); |
|||
|
|||
constantIntegerFloorCeilExpression = ((qi::lit("floor")[qi::_a = true] | qi::lit("ceil")[qi::_a = false]) >> qi::lit("(") >> constantIntegerExpression >> qi::lit(")"))[qi::_val = phoenix::bind(&BaseGrammar::createIntFloorCeil, this, qi::_a, qi::_1)]; |
|||
constantIntegerFloorCeilExpression.name("integer floor/ceil expression"); |
|||
|
|||
integerConstantExpression %= (this->state->integerConstants_ | integerLiteralExpression); |
|||
integerConstantExpression.name("integer constant or literal"); |
|||
|
|||
integerLiteralExpression = qi::int_[qi::_val = phoenix::bind(&BaseGrammar::createIntLiteral, this, qi::_1)]; |
|||
integerLiteralExpression.name("integer literal"); |
|||
|
|||
} |
|||
|
|||
} // namespace prism
|
|||
} // namespace parser
|
|||
} // namespace storm
|
@ -1,42 +0,0 @@ |
|||
/* |
|||
* File: ConstIntegerExpressionGrammar.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 6:02 PM |
|||
*/ |
|||
|
|||
#ifndef CONSTINTEGEREXPRESSIONGRAMMAR_H |
|||
#define CONSTINTEGEREXPRESSIONGRAMMAR_H |
|||
|
|||
#include "Includes.h" |
|||
#include "VariableState.h" |
|||
#include "IdentifierGrammars.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses constant integer expressions as used in prism models. |
|||
*/ |
|||
class ConstIntegerExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<ConstIntegerExpressionGrammar> { |
|||
public: |
|||
ConstIntegerExpressionGrammar(std::shared_ptr<VariableState> const& state); |
|||
|
|||
private: |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused> constantIntegerExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> constantIntegerPlusExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantIntegerMultExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> constantAtomicIntegerExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> integerConstantExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> integerLiteralExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> constantIntegerMinMaxExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> constantIntegerFloorCeilExpression; |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* CONSTINTEGEREXPRESSIONGRAMMAR_H */ |
@ -1,23 +0,0 @@ |
|||
#include "IdentifierGrammars.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
IdentifierGrammar::IdentifierGrammar(std::shared_ptr<VariableState> const& state) |
|||
: IdentifierGrammar::base_type(identifierName), BaseGrammar(state) { |
|||
|
|||
identifierName %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]][ qi::_pass = phoenix::bind(&VariableState::isIdentifier, this->state.get(), qi::_1) ]; |
|||
identifierName.name("identifier"); |
|||
} |
|||
|
|||
FreeIdentifierGrammar::FreeIdentifierGrammar(std::shared_ptr<VariableState> const& state) |
|||
: FreeIdentifierGrammar::base_type(freeIdentifierName), BaseGrammar(state) { |
|||
|
|||
freeIdentifierName %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]][ qi::_pass = phoenix::bind(&VariableState::isFreeIdentifier, this->state.get(), qi::_1) ]; |
|||
freeIdentifierName.name("identifier"); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -1,42 +0,0 @@ |
|||
/* |
|||
* File: Keywords.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 6:03 PM |
|||
*/ |
|||
|
|||
#ifndef IDENTIFIERGRAMMARS_H |
|||
#define IDENTIFIERGRAMMARS_H |
|||
|
|||
#include "Includes.h" |
|||
#include "BaseGrammar.h" |
|||
#include "VariableState.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses a (possibly used) identifier as used in a prism models. |
|||
*/ |
|||
class IdentifierGrammar : public qi::grammar<Iterator, std::string(), Skipper, Unused>, public BaseGrammar<IdentifierGrammar> { |
|||
public: |
|||
IdentifierGrammar(std::shared_ptr<VariableState> const& state); |
|||
private: |
|||
qi::rule<Iterator, std::string(), Skipper> identifierName; |
|||
}; |
|||
|
|||
/*! |
|||
* This grammar parses an used identifier as used in a prism models. |
|||
*/ |
|||
class FreeIdentifierGrammar : public qi::grammar<Iterator, std::string(), Skipper, Unused>, public BaseGrammar<IdentifierGrammar> { |
|||
public: |
|||
FreeIdentifierGrammar(std::shared_ptr<VariableState> const& state); |
|||
private: |
|||
qi::rule<Iterator, std::string(), Skipper> freeIdentifierName; |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
#endif /* IDENTIFIERGRAMMARS_H */ |
|||
|
@ -1,39 +0,0 @@ |
|||
/* |
|||
* File: Includes |
|||
* Author: Gereon Kremer |
|||
* |
|||
* Created on April 10, 2013, 4:46 PM |
|||
*/ |
|||
|
|||
#ifndef BOOSTINCLUDES_H |
|||
#define BOOSTINCLUDES_H |
|||
|
|||
// Used for Boost spirit. |
|||
#include <boost/typeof/typeof.hpp> |
|||
#include <boost/spirit/include/qi.hpp> |
|||
#include <boost/spirit/include/phoenix.hpp> |
|||
|
|||
// Include headers for spirit iterators. Needed for diagnostics and input stream iteration. |
|||
#include <boost/spirit/include/classic_position_iterator.hpp> |
|||
#include <boost/spirit/include/support_multi_pass.hpp> |
|||
|
|||
namespace qi = boost::spirit::qi; |
|||
namespace phoenix = boost::phoenix; |
|||
|
|||
typedef std::string::const_iterator BaseIteratorType; |
|||
typedef boost::spirit::classic::position_iterator2<BaseIteratorType> PositionIteratorType; |
|||
typedef PositionIteratorType Iterator; |
|||
typedef BOOST_TYPEOF(boost::spirit::ascii::space | qi::lit("//") >> *(qi::char_ - qi::eol) >> qi::eol) Skipper; |
|||
typedef BOOST_TYPEOF(qi::lit("//") >> *(qi::char_ - qi::eol) >> qi::eol | boost::spirit::ascii::space) Skipper2; |
|||
typedef boost::spirit::unused_type Unused; |
|||
|
|||
#include "src/ir/IR.h" |
|||
using namespace storm::ir; |
|||
using namespace storm::ir::expressions; |
|||
|
|||
#include "log4cplus/logger.h" |
|||
#include "log4cplus/loggingmacros.h" |
|||
extern log4cplus::Logger logger; |
|||
|
|||
#endif /* BOOSTINCLUDES_H */ |
|||
|
@ -1,42 +0,0 @@ |
|||
#include "IntegerExpressionGrammar.h"
|
|||
|
|||
#include "IdentifierGrammars.h"
|
|||
#include "ConstIntegerExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
IntegerExpressionGrammar::IntegerExpressionGrammar(std::shared_ptr<VariableState> const& state) |
|||
: IntegerExpressionGrammar::base_type(integerExpression), BaseGrammar(state) { |
|||
|
|||
integerExpression %= integerPlusExpression; |
|||
integerExpression.name("integer expression"); |
|||
|
|||
integerPlusExpression = integerMultExpression[qi::_val = qi::_1] >> *((qi::lit("+")[qi::_a = true] | qi::lit("-")[qi::_a = false]) >> integerMultExpression)[qi::_val = phoenix::bind(&BaseGrammar::createIntPlus, this, qi::_val, qi::_a, qi::_1)]; |
|||
integerPlusExpression.name("integer expression"); |
|||
|
|||
integerMultExpression %= atomicIntegerExpression[qi::_val = qi::_1] >> *(qi::lit("*") >> atomicIntegerExpression[qi::_val = phoenix::bind(&BaseGrammar::createIntMult, this, qi::_val, qi::_1)]); |
|||
integerMultExpression.name("integer expression"); |
|||
|
|||
atomicIntegerExpression %= (integerMinMaxExpression | integerFloorCeilExpression | this->state->constantIntegerFormulas_ | this->state->integerFormulas_ | qi::lit("(") >> integerExpression >> qi::lit(")") | integerVariableExpression | ConstIntegerExpressionGrammar::instance(this->state)); |
|||
atomicIntegerExpression.name("integer expression"); |
|||
|
|||
integerMinMaxExpression = ((qi::lit("min")[qi::_a = true] | qi::lit("max")[qi::_a = false]) >> qi::lit("(") >> integerExpression >> qi::lit(",") >> integerExpression >> qi::lit(")"))[qi::_val = phoenix::bind(&BaseGrammar::createIntMinMax, this, qi::_a, qi::_1, qi::_2)]; |
|||
integerMinMaxExpression.name("integer min/max expression"); |
|||
|
|||
integerFloorCeilExpression = ((qi::lit("floor")[qi::_a = true] | qi::lit("ceil")[qi::_a = false]) >> qi::lit("(") >> integerExpression >> qi::lit(")"))[qi::_val = phoenix::bind(&BaseGrammar::createIntFloorCeil, this, qi::_a, qi::_1)]; |
|||
integerFloorCeilExpression.name("integer floor/ceil expression"); |
|||
|
|||
integerVariableExpression = IdentifierGrammar::instance(this->state)[qi::_val = phoenix::bind(&BaseGrammar::getIntVariable, this, qi::_1)]; |
|||
integerVariableExpression.name("integer variable"); |
|||
} |
|||
|
|||
void IntegerExpressionGrammar::prepareSecondRun() { |
|||
integerVariableExpression %= this->state->integerVariables_; |
|||
integerVariableExpression.name("integer variable"); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -1,50 +0,0 @@ |
|||
/* |
|||
* File: IntegerExpressionGrammar.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 4:39 PM |
|||
*/ |
|||
|
|||
#ifndef INTEGEREXPRESSIONGRAMMAR_H |
|||
#define INTEGEREXPRESSIONGRAMMAR_H |
|||
|
|||
#include "src/ir/IR.h" |
|||
#include "VariableState.h" |
|||
#include "Includes.h" |
|||
#include "IdentifierGrammars.h" |
|||
|
|||
#include <memory> |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* This grammar parses a (non constant) integer expressions as used in prism models. |
|||
*/ |
|||
class IntegerExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<IntegerExpressionGrammar> { |
|||
public: |
|||
IntegerExpressionGrammar(std::shared_ptr<VariableState> const& state); |
|||
|
|||
/*! |
|||
* Switch to second run. |
|||
* Variable names may be any valid identifier in the first run, but only defined variables in the second run. |
|||
*/ |
|||
virtual void prepareSecondRun(); |
|||
|
|||
private: |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused> integerExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> integerPlusExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> integerMultExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> atomicIntegerExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), Skipper> integerVariableExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> integerMinMaxExpression; |
|||
qi::rule<Iterator, std::shared_ptr<BaseExpression>(), qi::locals<bool>, Skipper> integerFloorCeilExpression; |
|||
}; |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* INTEGEREXPRESSIONGRAMMAR_H */ |
|||
|
@ -1,75 +1,66 @@ |
|||
/* |
|||
* File: Tokens.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 19, 2013, 11:17 PM |
|||
*/ |
|||
#ifndef STORM_PARSER_PRISMPARSER_TOKENS_H_ |
|||
#define STORM_PARSER_PRISMPARSER_TOKENS_H_ |
|||
|
|||
#ifndef TOKENS_H |
|||
#define TOKENS_H |
|||
#include "src/storage/expressions/Expression.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of a model type to the model type |
|||
* representation of the intermediate representation. |
|||
*/ |
|||
struct modelTypeStruct : qi::symbols<char, Program::ModelType> { |
|||
modelTypeStruct() { |
|||
add |
|||
("dtmc", Program::ModelType::DTMC) |
|||
("ctmc", Program::ModelType::CTMC) |
|||
("mdp", Program::ModelType::MDP) |
|||
("ctmdp", Program::ModelType::CTMDP) |
|||
; |
|||
} |
|||
}; |
|||
|
|||
|
|||
/*! |
|||
* A structure defining the keywords that are not allowed to be chosen as identifiers. |
|||
*/ |
|||
struct keywordsStruct : qi::symbols<char, unsigned> { |
|||
keywordsStruct() { |
|||
add |
|||
("dtmc", 1) |
|||
("ctmc", 2) |
|||
("mdp", 3) |
|||
("ctmdp", 4) |
|||
("const", 5) |
|||
("int", 6) |
|||
("bool", 7) |
|||
("module", 8) |
|||
("endmodule", 9) |
|||
("rewards", 10) |
|||
("endrewards", 11) |
|||
("true", 12) |
|||
("false", 13) |
|||
; |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of a binary relation to the representation |
|||
* of the intermediate representation. |
|||
*/ |
|||
struct relationalOperatorStruct : qi::symbols<char, BinaryRelationExpression::RelationType> { |
|||
relationalOperatorStruct() { |
|||
add |
|||
("=", BinaryRelationExpression::EQUAL) |
|||
("!=", BinaryRelationExpression::NOT_EQUAL) |
|||
("<", BinaryRelationExpression::LESS) |
|||
("<=", BinaryRelationExpression::LESS_OR_EQUAL) |
|||
(">", BinaryRelationExpression::GREATER) |
|||
(">=", BinaryRelationExpression::GREATER_OR_EQUAL) |
|||
; |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
namespace parser { |
|||
namespace prism { |
|||
/*! |
|||
* A structure mapping the textual representation of a model type to the model type |
|||
* representation of the intermediate representation. |
|||
*/ |
|||
struct modelTypeStruct : qi::symbols<char, Program::ModelType> { |
|||
modelTypeStruct() { |
|||
add |
|||
("dtmc", Program::ModelType::DTMC) |
|||
("ctmc", Program::ModelType::CTMC) |
|||
("mdp", Program::ModelType::MDP) |
|||
("ctmdp", Program::ModelType::CTMDP) |
|||
("ma", Program::ModelType::MA); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure defining the keywords that are not allowed to be chosen as identifiers. |
|||
*/ |
|||
struct keywordsStruct : qi::symbols<char, unsigned> { |
|||
keywordsStruct() { |
|||
add |
|||
("dtmc", 1) |
|||
("ctmc", 2) |
|||
("mdp", 3) |
|||
("ctmdp", 4) |
|||
("ma", 5) |
|||
("const", 6) |
|||
("int", 7) |
|||
("bool", 8) |
|||
("module", 9) |
|||
("endmodule", 10) |
|||
("rewards", 11) |
|||
("endrewards", 12) |
|||
("true", 13) |
|||
("false", 14); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of a binary relation. |
|||
*/ |
|||
struct relationalOperatorStruct : qi::symbols<char, BinaryRelationExpression::RelationType> { |
|||
relationalOperatorStruct() { |
|||
add |
|||
("=", BinaryRelationExpression::RelationType::EQUAL) |
|||
("!=", BinaryRelationExpression::RelationType::NOT_EQUAL) |
|||
("<", BinaryRelationExpression::RelationType::LESS) |
|||
("<=", BinaryRelationExpression::RelationType::LESS_OR_EQUAL) |
|||
(">", BinaryRelationExpression::RelationType::GREATER) |
|||
(">=", BinaryRelationExpression::RelationType::GREATER_OR_EQUAL); |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* TOKENS_H */ |
|||
#endif /* STORM_PARSER_PRISMPARSER_TOKENS_H_ */ |
|||
|
@ -1,191 +0,0 @@ |
|||
#include "VariableState.h"
|
|||
#include "src/exceptions/InvalidArgumentException.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
using namespace storm::ir; |
|||
using namespace storm::ir::expressions; |
|||
|
|||
template<typename T> |
|||
struct SymbolDump { |
|||
SymbolDump(std::ostream& out) : out(out) {} |
|||
void operator() (std::basic_string<char> s, T elem) { |
|||
this->out << "\t" << s << " -> " << elem << std::endl; |
|||
} |
|||
private: |
|||
std::ostream& out; |
|||
}; |
|||
template<typename T> |
|||
std::ostream& operator<<(std::ostream& out, qi::symbols<char, T>& symbols) { |
|||
out << "Dumping symbol table" << std::endl; |
|||
SymbolDump<T> dump(out); |
|||
symbols.for_each(dump); |
|||
return out; |
|||
} |
|||
std::ostream& operator<<(std::ostream& out, VariableState::variableNamesStruct& symbols) { |
|||
SymbolDump<std::string> dump(out); |
|||
symbols.for_each(dump); |
|||
return out; |
|||
} |
|||
|
|||
|
|||
VariableState::VariableState(bool firstRun) : firstRun(firstRun), keywords(), nextLocalBooleanVariableIndex(0), nextLocalIntegerVariableIndex(0), nextGlobalBooleanVariableIndex(0), nextGlobalIntegerVariableIndex(0), nextGlobalCommandIndex(0), nextGlobalUpdateIndex(0) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextLocalBooleanVariableIndex() const { |
|||
return this->nextLocalBooleanVariableIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextLocalIntegerVariableIndex() const { |
|||
return this->nextLocalIntegerVariableIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextGlobalBooleanVariableIndex() const { |
|||
return this->nextGlobalBooleanVariableIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextGlobalIntegerVariableIndex() const { |
|||
return this->nextGlobalIntegerVariableIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextGlobalCommandIndex() const { |
|||
return this->nextGlobalCommandIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::getNextGlobalUpdateIndex() const { |
|||
return this->nextGlobalUpdateIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableState::addBooleanVariable(std::string const& name) { |
|||
if (firstRun) { |
|||
LOG4CPLUS_TRACE(logger, "Adding boolean variable " << name << " with new id " << this->nextGlobalBooleanVariableIndex << "."); |
|||
this->booleanVariables_.add(name, std::shared_ptr<VariableExpression>(new VariableExpression(storm::ir::expressions::BaseExpression::bool_, this->nextGlobalBooleanVariableIndex, name))); |
|||
this->booleanVariableNames_.add(name, name); |
|||
++this->nextGlobalBooleanVariableIndex; |
|||
++this->nextLocalBooleanVariableIndex; |
|||
return this->nextGlobalBooleanVariableIndex - 1; |
|||
} else { |
|||
std::shared_ptr<VariableExpression> variableExpression = this->booleanVariables_.at(name); |
|||
if (variableExpression != nullptr) { |
|||
return variableExpression->getGlobalVariableIndex(); |
|||
} else { |
|||
LOG4CPLUS_ERROR(logger, "Boolean variable " << name << " does not exist."); |
|||
throw storm::exceptions::InvalidArgumentException() << "Boolean variable " << name << " does not exist."; |
|||
} |
|||
} |
|||
} |
|||
|
|||
uint_fast64_t VariableState::addIntegerVariable(std::string const& name) { |
|||
if (firstRun) { |
|||
LOG4CPLUS_TRACE(logger, "Adding integer variable " << name << " with new id " << this->nextGlobalIntegerVariableIndex << "."); |
|||
this->integerVariables_.add(name, std::shared_ptr<VariableExpression>(new VariableExpression(storm::ir::expressions::BaseExpression::int_, this->nextGlobalIntegerVariableIndex, name))); |
|||
this->integerVariableNames_.add(name, name); |
|||
++this->nextGlobalIntegerVariableIndex; |
|||
++this->nextLocalIntegerVariableIndex; |
|||
return this->nextGlobalIntegerVariableIndex - 1; |
|||
} else { |
|||
std::shared_ptr<VariableExpression> variableExpression = this->integerVariables_.at(name); |
|||
if (variableExpression != nullptr) { |
|||
return variableExpression->getGlobalVariableIndex(); |
|||
} else { |
|||
LOG4CPLUS_ERROR(logger, "Integer variable " << name << " does not exist."); |
|||
throw storm::exceptions::InvalidArgumentException() << "Integer variable " << name << " does not exist."; |
|||
} |
|||
} |
|||
} |
|||
|
|||
std::shared_ptr<VariableExpression> VariableState::getBooleanVariableExpression(std::string const& name) const { |
|||
std::shared_ptr<VariableExpression> const* variableExpression = this->booleanVariables_.find(name); |
|||
if (variableExpression != nullptr) { |
|||
return *variableExpression; |
|||
} else { |
|||
if (firstRun) { |
|||
LOG4CPLUS_TRACE(logger, "Trying to retrieve boolean variable " << name << " that was not yet created; returning dummy instead."); |
|||
return std::shared_ptr<VariableExpression>(new VariableExpression(BaseExpression::bool_, name)); |
|||
} else { |
|||
LOG4CPLUS_ERROR(logger, "Boolean variable " << name << " does not exist."); |
|||
throw storm::exceptions::InvalidArgumentException() << "Boolean variable " << name << " does not exist."; |
|||
} |
|||
} |
|||
} |
|||
|
|||
std::shared_ptr<VariableExpression> VariableState::getIntegerVariableExpression(std::string const& name) const { |
|||
std::shared_ptr<VariableExpression> const* variableExpression = this->integerVariables_.find(name); |
|||
if (variableExpression != nullptr) { |
|||
return *variableExpression; |
|||
} else { |
|||
if (firstRun) { |
|||
LOG4CPLUS_TRACE(logger, "Trying to retrieve integer variable " << name << " that was not yet created; returning dummy instead."); |
|||
return std::shared_ptr<VariableExpression>(new VariableExpression(BaseExpression::int_, name)); |
|||
} else { |
|||
LOG4CPLUS_ERROR(logger, "Integer variable " << name << " does not exist."); |
|||
throw storm::exceptions::InvalidArgumentException() << "Integer variable " << name << " does not exist."; |
|||
} |
|||
} |
|||
} |
|||
|
|||
std::shared_ptr<VariableExpression> VariableState::getVariableExpression(std::string const& name) const { |
|||
std::shared_ptr<VariableExpression> const* variableExpression = this->integerVariables_.find(name); |
|||
if (variableExpression != nullptr) { |
|||
return *variableExpression; |
|||
} |
|||
|
|||
variableExpression = this->booleanVariables_.find(name); |
|||
if (variableExpression != nullptr) { |
|||
return *variableExpression; |
|||
} |
|||
LOG4CPLUS_ERROR(logger, "Variable " << name << " does not exist."); |
|||
throw storm::exceptions::InvalidArgumentException() << "Variable " << name << " does not exist."; |
|||
} |
|||
|
|||
void VariableState::clearLocalVariables() { |
|||
this->localBooleanVariables_.clear(); |
|||
this->localIntegerVariables_.clear(); |
|||
this->nextLocalBooleanVariableIndex = 0; |
|||
this->nextLocalIntegerVariableIndex = 0; |
|||
} |
|||
|
|||
bool VariableState::isFreeIdentifier(std::string const& identifier) const { |
|||
if (this->booleanVariableNames_.find(identifier) != nullptr) return false; |
|||
if (this->integerVariableNames_.find(identifier) != nullptr) return false; |
|||
if (this->allConstantNames_.find(identifier) != nullptr) return false; |
|||
if (this->labelNames_.find(identifier) != nullptr) return false; |
|||
if (this->moduleNames_.find(identifier) != nullptr) return false; |
|||
if (this->keywords.find(identifier) != nullptr) return false; |
|||
if (this->booleanFormulas_.find(identifier) != nullptr) return false; |
|||
if (this->integerFormulas_.find(identifier) != nullptr) return false; |
|||
if (this->doubleFormulas_.find(identifier) != nullptr) return false; |
|||
if (this->constantBooleanFormulas_.find(identifier) != nullptr) return false; |
|||
if (this->constantIntegerFormulas_.find(identifier) != nullptr) return false; |
|||
if (this->constantDoubleFormulas_.find(identifier) != nullptr) return false; |
|||
return true; |
|||
} |
|||
|
|||
bool VariableState::isIdentifier(std::string const& identifier) const { |
|||
if (this->allConstantNames_.find(identifier) != nullptr) return false; |
|||
if (this->keywords.find(identifier) != nullptr) return false; |
|||
return true; |
|||
} |
|||
|
|||
void VariableState::prepareForSecondRun() { |
|||
integerConstants_.clear(); |
|||
booleanConstants_.clear(); |
|||
doubleConstants_.clear(); |
|||
allConstantNames_.clear(); |
|||
constantBooleanFormulas_.clear(); |
|||
booleanFormulas_.clear(); |
|||
constantIntegerFormulas_.clear(); |
|||
integerFormulas_.clear(); |
|||
constantDoubleFormulas_.clear(); |
|||
doubleFormulas_.clear(); |
|||
this->firstRun = false; |
|||
nextGlobalCommandIndex = 0; |
|||
nextGlobalUpdateIndex = 0; |
|||
} |
|||
|
|||
} // namespace prism
|
|||
} // namespace parser
|
|||
} // namespace storm
|
@ -1,207 +0,0 @@ |
|||
/* |
|||
* File: VariableState.h |
|||
* Author: nafur |
|||
* |
|||
* Created on April 10, 2013, 4:43 PM |
|||
*/ |
|||
|
|||
#ifndef STORM_PARSER_PRISMPARSER_VARIABLESTATE_H |
|||
#define STORM_PARSER_PRISMPARSER_VARIABLESTATE_H |
|||
|
|||
#include <iostream> |
|||
|
|||
#include "src/ir/IR.h" |
|||
#include "Includes.h" |
|||
#include "Tokens.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
using namespace storm::ir; |
|||
using namespace storm::ir::expressions; |
|||
|
|||
template<typename T> |
|||
std::ostream& operator<<(std::ostream& out, qi::symbols<char, T>& symbols); |
|||
|
|||
/*! |
|||
* This class contains the internal state that is needed for parsing a PRISM model. |
|||
*/ |
|||
class VariableState { |
|||
public: |
|||
/*! |
|||
* Creates a new variable state object. By default, this object will be set to a state in which |
|||
* it is ready for performing a first run on some input. The first run creates all variables |
|||
* while the second one checks for the correct usage of variables in expressions. |
|||
* |
|||
* @param firstRun If set, this object will be in a state ready for performing the first run. If |
|||
* set to false, this object will assume that it has all variable data already. |
|||
*/ |
|||
VariableState(bool firstRun = true); |
|||
|
|||
/*! |
|||
* Indicator, if we are still in the first run. |
|||
*/ |
|||
bool firstRun; |
|||
|
|||
/*! |
|||
* A parser for all reserved keywords. |
|||
*/ |
|||
keywordsStruct keywords; |
|||
|
|||
/*! |
|||
* Internal counter for the local index of the next new boolean variable. |
|||
*/ |
|||
uint_fast64_t nextLocalBooleanVariableIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free local index for a boolean variable. |
|||
* |
|||
* @return The next free local index for a boolean variable. |
|||
*/ |
|||
uint_fast64_t getNextLocalBooleanVariableIndex() const; |
|||
|
|||
/*! |
|||
* Internal counter for the local index of the next new integer variable. |
|||
*/ |
|||
uint_fast64_t nextLocalIntegerVariableIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free global index for a integer variable. |
|||
* |
|||
* @return The next free global index for a integer variable. |
|||
*/ |
|||
uint_fast64_t getNextLocalIntegerVariableIndex() const; |
|||
|
|||
/*! |
|||
* Internal counter for the index of the next new boolean variable. |
|||
*/ |
|||
uint_fast64_t nextGlobalBooleanVariableIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free global index for a boolean variable. |
|||
* |
|||
* @return The next free global index for a boolean variable. |
|||
*/ |
|||
uint_fast64_t getNextGlobalBooleanVariableIndex() const; |
|||
|
|||
/*! |
|||
* Internal counter for the index of the next new integer variable. |
|||
*/ |
|||
uint_fast64_t nextGlobalIntegerVariableIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free global index for a integer variable. |
|||
* |
|||
* @return The next free global index for a integer variable. |
|||
*/ |
|||
uint_fast64_t getNextGlobalIntegerVariableIndex() const; |
|||
|
|||
/*! |
|||
* Internal counter for the index of the next command. |
|||
*/ |
|||
uint_fast64_t nextGlobalCommandIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free global index for a command. |
|||
* |
|||
* @return The next free global index for a command. |
|||
*/ |
|||
uint_fast64_t getNextGlobalCommandIndex() const; |
|||
|
|||
/*! |
|||
* Internal counter for the index of the next update. |
|||
*/ |
|||
uint_fast64_t nextGlobalUpdateIndex; |
|||
|
|||
/*! |
|||
* Retrieves the next free global index for an update. |
|||
* |
|||
* @return The next free global index for an update. |
|||
*/ |
|||
uint_fast64_t getNextGlobalUpdateIndex() const; |
|||
|
|||
// Structures mapping variable and constant names to the corresponding expression nodes of |
|||
// the intermediate representation. |
|||
struct qi::symbols<char, std::shared_ptr<VariableExpression>> integerVariables_, booleanVariables_; |
|||
struct qi::symbols<char, std::shared_ptr<BaseExpression>> integerConstants_, booleanConstants_, doubleConstants_, booleanFormulas_, constantBooleanFormulas_, integerFormulas_, constantIntegerFormulas_, doubleFormulas_, constantDoubleFormulas_; |
|||
|
|||
// A structure representing the identity function over identifier names. |
|||
struct variableNamesStruct : qi::symbols<char, std::string> { } |
|||
integerVariableNames_, booleanVariableNames_, commandNames_, labelNames_, allConstantNames_, moduleNames_, |
|||
localBooleanVariables_, localIntegerVariables_, assignedBooleanVariables_, assignedIntegerVariables_, |
|||
globalBooleanVariables_, globalIntegerVariables_; |
|||
|
|||
/*! |
|||
* Adds a new boolean variable with the given name. |
|||
* |
|||
* @param name The name of the variable. |
|||
* @return The global index of the variable. |
|||
*/ |
|||
uint_fast64_t addBooleanVariable(std::string const& name); |
|||
|
|||
/*! |
|||
* Adds a new integer variable with the given name. |
|||
* |
|||
* @param name The name of the variable. |
|||
* @return The global index of the variable. |
|||
*/ |
|||
uint_fast64_t addIntegerVariable(std::string const& name); |
|||
|
|||
/*! |
|||
* Retrieves the variable expression for the boolean variable with the given name. |
|||
* |
|||
* @param name The name of the boolean variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the boolean variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getBooleanVariableExpression(std::string const& name) const; |
|||
|
|||
/*! |
|||
* Retrieves the variable expression for the integer variable with the given name. |
|||
* |
|||
* @param name The name of the integer variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the integer variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getIntegerVariableExpression(std::string const& name) const; |
|||
|
|||
/*! |
|||
* Retrieve the variable expression for the variable with the given name. |
|||
* |
|||
* @param name The name of the variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getVariableExpression(std::string const& name) const; |
|||
|
|||
/*! |
|||
* Clears all local variables. |
|||
*/ |
|||
void clearLocalVariables(); |
|||
|
|||
/*! |
|||
* Check if the given string is a free identifier. |
|||
* |
|||
* @param identifier A string to be checked. |
|||
* @return True iff the given string is a free identifier. |
|||
*/ |
|||
bool isFreeIdentifier(std::string const& identifier) const; |
|||
|
|||
/*! |
|||
* Check if given string is a valid identifier. |
|||
* |
|||
* @param identifier A string to be checked. |
|||
* @return True iff the given string is an identifier. |
|||
*/ |
|||
bool isIdentifier(std::string const& identifier) const; |
|||
|
|||
/*! |
|||
* Prepare state to proceed to second parser run. Currently, this clears the constants. |
|||
*/ |
|||
void prepareForSecondRun(); |
|||
}; |
|||
|
|||
} // namespace prism |
|||
} // namespace parser |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_PARSER_PRISMPARSER_VARIABLESTATE_H */ |
|||
|
@ -0,0 +1,17 @@ |
|||
#include "src/storage/prism/LocatedInformation.h"
|
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
LocatedInformation::LocatedInformation(std::string const& filename, uint_fast64_t lineNumber) : filename(filename), lineNumber(lineNumber) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
std::string const& LocatedInformation::getFilename() const { |
|||
return this->filename; |
|||
} |
|||
|
|||
uint_fast64_t LocatedInformation::getLineNumber() const { |
|||
return this->lineNumber; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
#ifndef STORM_STORAGE_PRISM_LOCATEDINFORMATION_H_ |
|||
#define STORM_STORAGE_PRISM_LOCATEDINFORMATION_H_ |
|||
|
|||
#include <string> |
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
class LocatedInformation { |
|||
public: |
|||
/*! |
|||
* Constructs a located information with the given filename and line number. |
|||
* |
|||
* @param filename The file in which the information was found. |
|||
* @param lineNumber The line number in which the information was found. |
|||
*/ |
|||
LocatedInformation(std::string const& filename, uint_fast64_t lineNumber); |
|||
|
|||
// Create default implementations of constructors/assignment. |
|||
LocatedInformation(LocatedInformation const& other) = default; |
|||
LocatedInformation& operator=(LocatedInformation const& other)= default; |
|||
LocatedInformation(LocatedInformation&& other) = default; |
|||
LocatedInformation& operator=(LocatedInformation&& other) = default; |
|||
|
|||
/*! |
|||
* Retrieves the name of the file in which the information was found. |
|||
* |
|||
* @return The name of the file in which the information was found. |
|||
*/ |
|||
std::string const& getFilename() const; |
|||
|
|||
/*! |
|||
* Retrieves the line number in which the information was found. |
|||
* |
|||
* @return The line number in which the information was found. |
|||
*/ |
|||
uint_fast64_t getLineNumber() const; |
|||
|
|||
private: |
|||
// The file in which the piece of information was found. |
|||
std::string filename; |
|||
|
|||
// The line in the file in which the piece of information was found. |
|||
uint_fast64_t lineNumber; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_PRISM_LOCATEDINFORMATION_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue