You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
3.0 KiB

  1. #ifndef STORM_PARSER_FORMULAPARSER_H_
  2. #define STORM_PARSER_FORMULAPARSER_H_
  3. #include <sstream>
  4. #include "src/parser/SpiritParserDefinitions.h"
  5. #include "src/parser/ExpressionParser.h"
  6. #include "src/logic/Formulas.h"
  7. #include "src/storage/expressions/Expression.h"
  8. #include "src/utility/macros.h"
  9. #include "src/storage/prism/Program.h"
  10. namespace storm {
  11. namespace parser {
  12. // Forward-declare grammar.
  13. class FormulaParserGrammar;
  14. class FormulaParser {
  15. public:
  16. FormulaParser(std::shared_ptr<storm::expressions::ExpressionManager const> const& manager = std::shared_ptr<storm::expressions::ExpressionManager>(new storm::expressions::ExpressionManager()));
  17. FormulaParser(storm::prism::Program const& program);
  18. FormulaParser(FormulaParser const& other);
  19. FormulaParser& operator=(FormulaParser const& other);
  20. /*!
  21. * Parses the formula given by the provided string.
  22. *
  23. * @param formulaString The formula as a string.
  24. * @return The resulting formula.
  25. */
  26. std::shared_ptr<storm::logic::Formula const> parseSingleFormulaFromString(std::string const& formulaString) const;
  27. /*!
  28. * Parses the formula given by the provided string.
  29. *
  30. * @param formulaString The formula as a string.
  31. * @return The contained formulas.
  32. */
  33. std::vector<std::shared_ptr<storm::logic::Formula const>> parseFromString(std::string const& formulaString) const;
  34. /*!
  35. * Parses the formulas in the given file.
  36. *
  37. * @param filename The name of the file to parse.
  38. * @return The contained formulas.
  39. */
  40. std::vector<std::shared_ptr<storm::logic::Formula const>> parseFromFile(std::string const& filename) const;
  41. /*!
  42. * Adds an identifier and the expression it is supposed to be replaced with. This can, for example be used
  43. * to substitute special identifiers in the formula by expressions.
  44. *
  45. * @param identifier The identifier that is supposed to be substituted.
  46. * @param expression The expression it is to be substituted with.
  47. */
  48. void addIdentifierExpression(std::string const& identifier, storm::expressions::Expression const& expression);
  49. private:
  50. // The manager used to parse expressions.
  51. std::shared_ptr<storm::expressions::ExpressionManager const> manager;
  52. // Keep track of added identifier expressions.
  53. qi::symbols<char, storm::expressions::Expression> identifiers_;
  54. // The grammar used to parse the input.
  55. std::shared_ptr<FormulaParserGrammar> grammar;
  56. };
  57. } // namespace parser
  58. } // namespace storm
  59. #endif /* STORM_PARSER_FORMULAPARSER_H_ */