Matthias Volk
7 years ago
4 changed files with 94 additions and 69 deletions
-
30src/storm/parser/DirectEncodingParser.cpp
-
41src/storm/parser/DirectEncodingParser.h
-
39src/storm/parser/ValueParser.cpp
-
53src/storm/parser/ValueParser.h
@ -0,0 +1,39 @@ |
|||||
|
#include "storm/parser/ValueParser.h"
|
||||
|
|
||||
|
#include "storm/exceptions/NotSupportedException.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace parser { |
||||
|
|
||||
|
template<typename ValueType> |
||||
|
void ValueParser<ValueType>::addParameter(std::string const& parameter) { |
||||
|
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Parameters are not supported in this build."); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
void ValueParser<storm::RationalFunction>::addParameter(std::string const& parameter) { |
||||
|
//STORM_LOG_THROW((std::is_same<ValueType, storm::RationalFunction>::value), storm::exceptions::NotSupportedException, "Parameters only allowed when using rational functions.");
|
||||
|
storm::expressions::Variable var = manager->declareRationalVariable(parameter); |
||||
|
identifierMapping.emplace(var.getName(), var); |
||||
|
parser.setIdentifierMapping(identifierMapping); |
||||
|
STORM_LOG_TRACE("Added parameter: " << var.getName()); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
double ValueParser<double>::parseValue(std::string const& value) const { |
||||
|
return boost::lexical_cast<double>(value); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
storm::RationalFunction ValueParser<storm::RationalFunction>::parseValue(std::string const& value) const { |
||||
|
storm::RationalFunction rationalFunction = evaluator.asRational(parser.parseFromString(value)); |
||||
|
STORM_LOG_TRACE("Parsed expression: " << rationalFunction); |
||||
|
return rationalFunction; |
||||
|
} |
||||
|
|
||||
|
// Template instantiations.
|
||||
|
template class ValueParser<double>; |
||||
|
template class ValueParser<storm::RationalFunction>; |
||||
|
|
||||
|
} // namespace parser
|
||||
|
} // namespace storm
|
@ -0,0 +1,53 @@ |
|||||
|
#ifndef STORM_PARSER_VALUEPARSER_H_ |
||||
|
#define STORM_PARSER_VALUEPARSER_H_ |
||||
|
|
||||
|
#include "storm/storage/expressions/ExpressionManager.h" |
||||
|
#include "storm/parser/ExpressionParser.h" |
||||
|
#include "storm/storage/expressions/ExpressionEvaluator.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace parser { |
||||
|
/*! |
||||
|
* Parser for values according to their ValueType. |
||||
|
*/ |
||||
|
template<typename ValueType> |
||||
|
class ValueParser { |
||||
|
public: |
||||
|
|
||||
|
/*! |
||||
|
* Constructor. |
||||
|
*/ |
||||
|
ValueParser() : manager(new storm::expressions::ExpressionManager()), parser(*manager), evaluator(*manager) { |
||||
|
} |
||||
|
|
||||
|
/*! |
||||
|
* Parse ValueType from string. |
||||
|
* |
||||
|
* @param value String containing the value. |
||||
|
* |
||||
|
* @return ValueType |
||||
|
*/ |
||||
|
ValueType parseValue(std::string const& value) const; |
||||
|
|
||||
|
/*! |
||||
|
* Add declaration of parameter. |
||||
|
* |
||||
|
* @param parameter New parameter. |
||||
|
*/ |
||||
|
void addParameter(std::string const& parameter); |
||||
|
|
||||
|
private: |
||||
|
|
||||
|
std::shared_ptr<storm::expressions::ExpressionManager> manager; |
||||
|
|
||||
|
storm::parser::ExpressionParser parser; |
||||
|
|
||||
|
storm::expressions::ExpressionEvaluator<ValueType> evaluator; |
||||
|
|
||||
|
std::unordered_map<std::string, storm::expressions::Expression> identifierMapping; |
||||
|
}; |
||||
|
|
||||
|
} // namespace parser |
||||
|
} // namespace storm |
||||
|
|
||||
|
#endif /* STORM_PARSER_VALUEPARSER_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue