Browse Source
Changed internal data structures of PRISM classes slightly. Added classs for certain ingredients that were represented as primitives before.
Changed internal data structures of PRISM classes slightly. Added classs for certain ingredients that were represented as primitives before.
Former-commit-id: bdc61e88a5
main
18 changed files with 726 additions and 593 deletions
-
190src/parser/PrismParser.cpp
-
188src/parser/prismparser/PrismGrammar.cpp
-
121src/parser/prismparser/PrismGrammar.h
-
113src/parser/prismparser/Tokens.h
-
43src/storage/prism/Constant.cpp
-
91src/storage/prism/Constant.h
-
26src/storage/prism/Formula.cpp
-
62src/storage/prism/Formula.h
-
22src/storage/prism/Label.cpp
-
55src/storage/prism/Label.h
-
1src/storage/prism/LocatedInformation.h
-
53src/storage/prism/Module.cpp
-
27src/storage/prism/Module.h
-
115src/storage/prism/Program.cpp
-
154src/storage/prism/Program.h
-
29src/storage/prism/Update.cpp
-
26src/storage/prism/Update.h
-
3src/storm.cpp
@ -1,113 +0,0 @@ |
|||
#ifndef STORM_PARSER_PRISMPARSER_TOKENS_H_ |
|||
#define STORM_PARSER_PRISMPARSER_TOKENS_H_ |
|||
|
|||
#include "src/storage/prism/Program.h" |
|||
#include "src/storage/expressions/Expressions.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, storm::prism::Program::ModelType> { |
|||
modelTypeStruct() { |
|||
add |
|||
("dtmc", storm::prism::Program::ModelType::DTMC) |
|||
("ctmc", storm::prism::Program::ModelType::CTMC) |
|||
("mdp", storm::prism::Program::ModelType::MDP) |
|||
("ctmdp", storm::prism::Program::ModelType::CTMDP) |
|||
("ma", storm::prism::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 binary relations to the corresponding enum values. |
|||
*/ |
|||
struct BinaryRelationOperatorStruct : qi::symbols<char, storm::expressions::BinaryRelationExpression::RelationType> { |
|||
BinaryRelationOperatorStruct() { |
|||
add |
|||
("=", storm::expressions::BinaryRelationExpression::RelationType::Equal) |
|||
("!=", storm::expressions::BinaryRelationExpression::RelationType::NotEqual) |
|||
("<", storm::expressions::BinaryRelationExpression::RelationType::Less) |
|||
("<=", storm::expressions::BinaryRelationExpression::RelationType::LessOrEqual) |
|||
(">", storm::expressions::BinaryRelationExpression::RelationType::Greater) |
|||
(">=", storm::expressions::BinaryRelationExpression::RelationType::GreaterOrEqual); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of binary operators to the corresponding enum values. |
|||
*/ |
|||
struct BinaryBooleanOperatorStruct : qi::symbols<char, storm::expressions::BinaryBooleanFunctionExpression::OperatorType> { |
|||
BinaryBooleanOperatorStruct() { |
|||
add |
|||
("&", storm::expressions::BinaryBooleanFunctionExpression::OperatorType::And) |
|||
("|", storm::expressions::BinaryBooleanFunctionExpression::OperatorType::Or) |
|||
("=>", storm::expressions::BinaryBooleanFunctionExpression::OperatorType::Implies) |
|||
("<=>", storm::expressions::BinaryBooleanFunctionExpression::OperatorType::Iff); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of binary operators to the corresponding enum values. |
|||
*/ |
|||
struct UnaryBooleanOperatorStruct : qi::symbols<char, storm::expressions::UnaryBooleanFunctionExpression::OperatorType> { |
|||
UnaryBooleanOperatorStruct() { |
|||
add |
|||
("!", storm::expressions::UnaryBooleanFunctionExpression::OperatorType::Not); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of binary boolean operators to the corresponding enum values. |
|||
*/ |
|||
struct BinaryNumericalOperatorStruct : qi::symbols<char, storm::expressions::BinaryNumericalFunctionExpression::OperatorType> { |
|||
BinaryNumericalOperatorStruct() { |
|||
add |
|||
("+", storm::expressions::BinaryNumericalFunctionExpression::OperatorType::Plus) |
|||
("-", storm::expressions::BinaryNumericalFunctionExpression::OperatorType::Minus) |
|||
("*", storm::expressions::BinaryNumericalFunctionExpression::OperatorType::Times) |
|||
("/", storm::expressions::BinaryNumericalFunctionExpression::OperatorType::Divide); |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* A structure mapping the textual representation of binary operators to the corresponding enum values. |
|||
*/ |
|||
struct UnaryNumericalOperatorStruct : qi::symbols<char, storm::expressions::UnaryNumericalFunctionExpression::OperatorType> { |
|||
UnaryNumericalOperatorStruct() { |
|||
add |
|||
("!", storm::expressions::UnaryNumericalFunctionExpression::OperatorType::Minus); |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_PARSER_PRISMPARSER_TOKENS_H_ */ |
|||
|
@ -0,0 +1,43 @@ |
|||
#include "src/storage/prism/Constant.h"
|
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
Constant::Constant(ConstantType constantType, std::string const& constantName, storm::expressions::Expression const& expression, std::string const& filename, uint_fast64_t lineNumber) : LocatedInformation(filename, lineNumber), constantType(constantType), constantName(constantName), defined(true), expression(expression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Constant::Constant(ConstantType constantType, std::string const& constantName, std::string const& filename, uint_fast64_t lineNumber) : LocatedInformation(filename, lineNumber), constantType(constantType), constantName(constantName), defined(false), expression() { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
std::string const& Constant::getConstantName() const { |
|||
return this->constantName; |
|||
} |
|||
|
|||
Constant::ConstantType Constant::getConstantType() const { |
|||
return this->constantType; |
|||
} |
|||
|
|||
bool Constant::isDefined() const { |
|||
return this->defined; |
|||
} |
|||
|
|||
storm::expressions::Expression const& Constant::getExpression() const { |
|||
return this->expression; |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, Constant const& constant) { |
|||
stream << "const "; |
|||
switch (constant.getConstantType()) { |
|||
case Constant::ConstantType::Bool: stream << "bool "; break; |
|||
case Constant::ConstantType::Integer: stream << "int "; break; |
|||
case Constant::ConstantType::Double: stream << "double "; break; |
|||
} |
|||
stream << constant.getConstantName(); |
|||
if (constant.isDefined()) { |
|||
stream << " = " << constant.getExpression() << ";"; |
|||
} |
|||
return stream; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,91 @@ |
|||
#ifndef STORM_STORAGE_PRISM_CONSTANT_H_ |
|||
#define STORM_STORAGE_PRISM_CONSTANT_H_ |
|||
|
|||
#include "src/storage/prism/LocatedInformation.h" |
|||
#include "src/storage/expressions/Expression.h" |
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
class Constant : public LocatedInformation { |
|||
public: |
|||
/*! |
|||
* The possible constant types. |
|||
*/ |
|||
enum class ConstantType {Bool, Integer, Double}; |
|||
|
|||
/*! |
|||
* Creates a constant with the given type, name and defining expression. |
|||
* |
|||
* @param constantType The type of the constant. |
|||
* @param constantName The name of the constant. |
|||
* @param expression The expression that defines the constant. |
|||
* @param filename The filename in which the transition reward is defined. |
|||
* @param lineNumber The line number in which the transition reward is defined. |
|||
*/ |
|||
Constant(ConstantType constantType, std::string const& constantName, storm::expressions::Expression const& expression, std::string const& filename = "", uint_fast64_t lineNumber = 0); |
|||
|
|||
/*! |
|||
* Creates an undefined constant with the given type and name. |
|||
* |
|||
* @param constantType The type of the constant. |
|||
* @param constantName The name of the constant. |
|||
* @param filename The filename in which the transition reward is defined. |
|||
* @param lineNumber The line number in which the transition reward is defined. |
|||
*/ |
|||
Constant(ConstantType constantType, std::string const& constantName, std::string const& filename = "", uint_fast64_t lineNumber = 0); |
|||
|
|||
// Create default implementations of constructors/assignment. |
|||
Constant() = default; |
|||
Constant(Constant const& other) = default; |
|||
Constant& operator=(Constant const& other)= default; |
|||
Constant(Constant&& other) = default; |
|||
Constant& operator=(Constant&& other) = default; |
|||
|
|||
/*! |
|||
* Retrieves the name of the constant. |
|||
* |
|||
* @return The name of the constant. |
|||
*/ |
|||
std::string const& getConstantName() const; |
|||
|
|||
/*! |
|||
* Retrieves the type of the constant. |
|||
* |
|||
* @return The type of the constant; |
|||
*/ |
|||
ConstantType getConstantType() const; |
|||
|
|||
/*! |
|||
* Retrieves whether the constant is defined, i.e., whether there is an expression defining its value. |
|||
* |
|||
* @return True iff the constant is defined. |
|||
*/ |
|||
bool isDefined() const; |
|||
|
|||
/*! |
|||
* Retrieves the expression that defines the constant. This may only be called if the object is a defined |
|||
* constant. |
|||
* |
|||
* @return The expression that defines the constant. |
|||
*/ |
|||
storm::expressions::Expression const& getExpression() const; |
|||
|
|||
friend std::ostream& operator<<(std::ostream& stream, Constant const& constant); |
|||
|
|||
private: |
|||
// The type of the constant. |
|||
ConstantType constantType; |
|||
|
|||
// The name of the constant. |
|||
std::string constantName; |
|||
|
|||
// A flag that stores whether or not the constant is defined. |
|||
bool defined; |
|||
|
|||
// The expression that defines the constant (in case it is defined). |
|||
storm::expressions::Expression expression; |
|||
}; |
|||
} // namespace prism |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_STORAGE_PRISM_CONSTANT_H_ */ |
@ -0,0 +1,26 @@ |
|||
#include "src/storage/prism/Formula.h"
|
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
Formula::Formula(std::string const& formulaName, storm::expressions::Expression const& expression, std::string const& filename, uint_fast64_t lineNumber) : LocatedInformation(filename, lineNumber), formulaName(formulaName), expression(expression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
std::string const& Formula::getFormulaName() const { |
|||
return this->formulaName; |
|||
} |
|||
|
|||
storm::expressions::Expression const& Formula::getExpression() const { |
|||
return this->expression; |
|||
} |
|||
|
|||
storm::expressions::ExpressionReturnType Formula::getReturnType() const { |
|||
return this->getExpression().getReturnType(); |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, Formula const& formula) { |
|||
stream << "formula " << formula.getFormulaName() << " = " << formula.getExpression() << ";"; |
|||
return stream; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,62 @@ |
|||
#ifndef STORM_STORAGE_PRISM_FORMULA_H_ |
|||
#define STORM_STORAGE_PRISM_FORMULA_H_ |
|||
|
|||
#include "src/storage/prism/LocatedInformation.h" |
|||
#include "src/storage/expressions/Expression.h" |
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
class Formula : public LocatedInformation { |
|||
public: |
|||
/*! |
|||
* Creates a formula with the given name and expression. |
|||
* |
|||
* @param formulaName The name of the label. |
|||
* @param expression The predicate that needs to hold before taking a transition with the previously |
|||
* specified name in order to obtain the reward. |
|||
* @param filename The filename in which the transition reward is defined. |
|||
* @param lineNumber The line number in which the transition reward is defined. |
|||
*/ |
|||
Formula(std::string const& formulaName, storm::expressions::Expression const& expression, std::string const& filename = "", uint_fast64_t lineNumber = 0); |
|||
|
|||
// Create default implementations of constructors/assignment. |
|||
Formula() = default; |
|||
Formula(Formula const& other) = default; |
|||
Formula& operator=(Formula const& other)= default; |
|||
Formula(Formula&& other) = default; |
|||
Formula& operator=(Formula&& other) = default; |
|||
|
|||
/*! |
|||
* Retrieves the name that is associated with this formula. |
|||
* |
|||
* @return The name that is associated with this formula. |
|||
*/ |
|||
std::string const& getFormulaName() const; |
|||
|
|||
/*! |
|||
* Retrieves the expression that is associated with this formula. |
|||
* |
|||
* @return The expression that is associated with this formula. |
|||
*/ |
|||
storm::expressions::Expression const& getExpression() const; |
|||
|
|||
/*! |
|||
* Retrieves the return type of the formula, i.e., the return-type of the defining expression. |
|||
* |
|||
* @return The return type of the formula. |
|||
*/ |
|||
storm::expressions::ExpressionReturnType getReturnType() const; |
|||
|
|||
friend std::ostream& operator<<(std::ostream& stream, Formula const& formula); |
|||
|
|||
private: |
|||
// The name of the formula. |
|||
std::string formulaName; |
|||
|
|||
// A predicate that needs to be satisfied by states for the label to be attached. |
|||
storm::expressions::Expression expression; |
|||
}; |
|||
} // namespace prism |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_STORAGE_PRISM_FORMULA_H_ */ |
@ -0,0 +1,22 @@ |
|||
#include "src/storage/prism/Label.h"
|
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
Label::Label(std::string const& labelName, storm::expressions::Expression const& statePredicateExpression, std::string const& filename, uint_fast64_t lineNumber) : LocatedInformation(filename, lineNumber), labelName(labelName), statePredicateExpression(statePredicateExpression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
std::string const& Label::getLabelName() const { |
|||
return this->labelName; |
|||
} |
|||
|
|||
storm::expressions::Expression const& Label::getStatePredicateExpression() const { |
|||
return this->statePredicateExpression; |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, Label const& label) { |
|||
stream << "label \"" << label.getLabelName() << "\" = " << label.getStatePredicateExpression() << ";"; |
|||
return stream; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,55 @@ |
|||
#ifndef STORM_STORAGE_PRISM_LABEL_H_ |
|||
#define STORM_STORAGE_PRISM_LABEL_H_ |
|||
|
|||
#include "src/storage/prism/LocatedInformation.h" |
|||
#include "src/storage/expressions/Expression.h" |
|||
|
|||
namespace storm { |
|||
namespace prism { |
|||
class Label : public LocatedInformation { |
|||
public: |
|||
/*! |
|||
* Creates a label with the given name and state predicate expression. |
|||
* |
|||
* @param labelName The name of the label. |
|||
* @param statePredicateExpression The predicate that needs to hold before taking a transition with the previously |
|||
* specified name in order to obtain the reward. |
|||
* @param filename The filename in which the transition reward is defined. |
|||
* @param lineNumber The line number in which the transition reward is defined. |
|||
*/ |
|||
Label(std::string const& labelName, storm::expressions::Expression const& statePredicateExpression, std::string const& filename = "", uint_fast64_t lineNumber = 0); |
|||
|
|||
// Create default implementations of constructors/assignment. |
|||
Label() = default; |
|||
Label(Label const& other) = default; |
|||
Label& operator=(Label const& other)= default; |
|||
Label(Label&& other) = default; |
|||
Label& operator=(Label&& other) = default; |
|||
|
|||
/*! |
|||
* Retrieves the name that is associated with this label. |
|||
* |
|||
* @return The name that is associated with this label. |
|||
*/ |
|||
std::string const& getLabelName() const; |
|||
|
|||
/*! |
|||
* Retrieves the state predicate expression that is associated with this label. |
|||
* |
|||
* @return The state predicate expression that is associated with this label. |
|||
*/ |
|||
storm::expressions::Expression const& getStatePredicateExpression() const; |
|||
|
|||
friend std::ostream& operator<<(std::ostream& stream, Label const& label); |
|||
|
|||
private: |
|||
// The name of the label. |
|||
std::string labelName; |
|||
|
|||
// A predicate that needs to be satisfied by states for the label to be attached. |
|||
storm::expressions::Expression statePredicateExpression; |
|||
}; |
|||
} // namespace prism |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_STORAGE_PRISM_LABEL_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue