Browse Source

Documentation of parser class

main
Lanchid 12 years ago
parent
commit
fe6061e120
  1. 10
      src/parser/PrctlParser.cpp
  2. 12
      src/parser/PrctlParser.h

10
src/parser/PrctlParser.cpp

@ -39,7 +39,6 @@ struct PrctlParser::PrctlGrammar : qi::grammar<Iterator, storm::formula::Abstrac
//This block defines rules for parsing state formulas //This block defines rules for parsing state formulas
stateFormula %= orFormula; stateFormula %= orFormula;
stateFormula.name("state formula"); stateFormula.name("state formula");
andFormula = notFormula[qi::_val = qi::_1] > *(qi::lit("&") > notFormula)[qi::_val = andFormula = notFormula[qi::_val = qi::_1] > *(qi::lit("&") > notFormula)[qi::_val =
phoenix::new_<storm::formula::And<double>>(qi::_val, qi::_1)]; phoenix::new_<storm::formula::And<double>>(qi::_val, qi::_1)];
andFormula.name("state formula"); andFormula.name("state formula");
@ -50,6 +49,8 @@ struct PrctlParser::PrctlGrammar : qi::grammar<Iterator, storm::formula::Abstrac
phoenix::new_<storm::formula::Not<double>>(qi::_1)]; phoenix::new_<storm::formula::Not<double>>(qi::_1)];
notFormula.name("state formula"); notFormula.name("state formula");
//This block defines rules for atomic state formulas
//(Propositions, probabilistic/reward formulas, and state formulas in brackets)
atomicStateFormula %= probabilisticBoundOperator | rewardBoundOperator | atomicProposition | qi::lit("(") >> stateFormula >> qi::lit(")"); atomicStateFormula %= probabilisticBoundOperator | rewardBoundOperator | atomicProposition | qi::lit("(") >> stateFormula >> qi::lit(")");
atomicStateFormula.name("state formula"); atomicStateFormula.name("state formula");
atomicProposition = (freeIdentifierName)[qi::_val = atomicProposition = (freeIdentifierName)[qi::_val =
@ -154,6 +155,7 @@ void storm::parser::PrctlParser::parse(std::string formulaString) {
PrctlGrammar<PositionIteratorType, BOOST_TYPEOF(boost::spirit::ascii::space)> grammar; PrctlGrammar<PositionIteratorType, BOOST_TYPEOF(boost::spirit::ascii::space)> grammar;
// Now, parse the formula from the given string
try { try {
qi::phrase_parse(positionIteratorBegin, positionIteratorEnd, grammar, boost::spirit::ascii::space, result_pointer); qi::phrase_parse(positionIteratorBegin, positionIteratorEnd, grammar, boost::spirit::ascii::space, result_pointer);
} catch(const qi::expectation_failure<PositionIteratorType>& e) { } catch(const qi::expectation_failure<PositionIteratorType>& e) {
@ -182,6 +184,10 @@ void storm::parser::PrctlParser::parse(std::string formulaString) {
// Now propagate exception. // Now propagate exception.
throw storm::exceptions::WrongFormatException() << msg.str(); throw storm::exceptions::WrongFormatException() << msg.str();
} }
// The syntax can be so wrong that no rule can be matched at all
// In that case, no expectation failure is thrown, but the parser just returns nullptr
// Then, of course the result is not usable, hence we throw a WrongFormatException, too.
if (result_pointer == nullptr) { if (result_pointer == nullptr) {
throw storm::exceptions::WrongFormatException() << "Syntax error in formula"; throw storm::exceptions::WrongFormatException() << "Syntax error in formula";
} }
@ -190,5 +196,7 @@ void storm::parser::PrctlParser::parse(std::string formulaString) {
} }
storm::parser::PrctlParser::PrctlParser(std::string formula) { storm::parser::PrctlParser::PrctlParser(std::string formula) {
// delegate the string to the parse function
// this function has to be separate, as it may be called in subclasses which don't call this constructor
parse(formula); parse(formula);
} }

12
src/parser/PrctlParser.h

@ -32,7 +32,7 @@ class PrctlParser : Parser
PrctlParser(std::string formulaString); PrctlParser(std::string formulaString);
/*! /*!
* @return the parsed formula object
* @return a pointer to the parsed formula object
*/ */
storm::formula::AbstractFormula<double>* getFormula() storm::formula::AbstractFormula<double>* getFormula()
{ {
@ -42,11 +42,15 @@ class PrctlParser : Parser
protected: protected:
/*! /*!
* Empty constructor. * Empty constructor.
* Should only be used by subclasses which don't get a string representation of the formula
* directly.
*
* Some subclasses do not get a formula string as input (E.g. PrctlFileFormat), hence they should not
* call the usual constructor of this class.
*
* However, this constructor should never be called directly (only as constructor of the super class),
* as it will not parse anything (and formula will point to nullptr then), so it is protected.
*/ */
PrctlParser() { PrctlParser() {
//intentionally left empty
formula = nullptr;
} }
/*! /*!

Loading…
Cancel
Save