Browse Source
A lot of work on PrismParser:
A lot of work on PrismParser:
* Created a distinct parser for each expression type and for identifiers * Removed all expression rules from PrismParser, using new parsers instead * Reduced excessive usage of boost::lambda, using semantic actions only for single calls * Moved actual state to new class (-> VariableState, whole two-run-logic can probably implemented there) * Much cleanup Work should be finished on expression parser, but not yet on prism parser...main
18 changed files with 540 additions and 312 deletions
-
132src/parser/PrismParser.cpp
-
36src/parser/PrismParser.h
-
98src/parser/PrismParser/BaseGrammar.h
-
52src/parser/PrismParser/BooleanExpressionGrammar.cpp
-
35src/parser/PrismParser/BooleanExpressionGrammar.h
-
54src/parser/PrismParser/ConstBooleanExpressionGrammar.cpp
-
23src/parser/PrismParser/ConstBooleanExpressionGrammar.h
-
53src/parser/PrismParser/ConstDoubleExpressionGrammar.cpp
-
43src/parser/PrismParser/ConstDoubleExpressionGrammar.h
-
29src/parser/PrismParser/ConstIntegerExpressionGrammar.cpp
-
11src/parser/PrismParser/ConstIntegerExpressionGrammar.h
-
23src/parser/PrismParser/IdentifierGrammars.cpp
-
36src/parser/PrismParser/IdentifierGrammars.h
-
6src/parser/PrismParser/Includes.h
-
39src/parser/PrismParser/IntegerExpressionGrammar.cpp
-
28src/parser/PrismParser/IntegerExpressionGrammar.h
-
42src/parser/PrismParser/Tokens.h
-
78src/parser/PrismParser/VariableState.h
@ -0,0 +1,98 @@ |
|||
/* |
|||
* 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 { |
|||
|
|||
template <typename T> |
|||
class BaseGrammar { |
|||
public: |
|||
BaseGrammar(std::shared_ptr<VariableState>& state) : state(state) {} |
|||
|
|||
static T& instance(std::shared_ptr<VariableState>& state = nullptr) { |
|||
if (BaseGrammar::instanceObject == nullptr) { |
|||
BaseGrammar::instanceObject = std::shared_ptr<T>(new T(state)); |
|||
} |
|||
return *BaseGrammar::instanceObject; |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> createBoolLiteral(const bool value) { |
|||
return std::shared_ptr<BooleanLiteral>(new BooleanLiteral(value)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createDoubleLiteral(const double value) { |
|||
return std::shared_ptr<DoubleLiteral>(new DoubleLiteral(value)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createIntLiteral(const int_fast64_t value) { |
|||
return std::shared_ptr<IntegerLiteral>(new IntegerLiteral(value)); |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> createPlus(const std::shared_ptr<BaseExpression> left, bool addition, const std::shared_ptr<BaseExpression> right, BaseExpression::ReturnType type) { |
|||
if (addition) { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(type, left, right, BinaryNumericalFunctionExpression::PLUS)); |
|||
} else { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(type, left, right, BinaryNumericalFunctionExpression::MINUS)); |
|||
} |
|||
} |
|||
std::shared_ptr<BaseExpression> createDoublePlus(const std::shared_ptr<BaseExpression> left, bool addition, const std::shared_ptr<BaseExpression> right) { |
|||
return this->createPlus(left, addition, right, BaseExpression::double_); |
|||
} |
|||
std::shared_ptr<BaseExpression> createIntPlus(const std::shared_ptr<BaseExpression> left, bool addition, const std::shared_ptr<BaseExpression> right) { |
|||
return this->createPlus(left, addition, right, BaseExpression::int_); |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> createIntMult(const std::shared_ptr<BaseExpression> left, const std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::int_, left, right, BinaryNumericalFunctionExpression::TIMES)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createDoubleMult(const std::shared_ptr<BaseExpression> left, bool multiplication, const std::shared_ptr<BaseExpression> right) { |
|||
if (multiplication) { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::TIMES)); |
|||
} else { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::DIVIDE)); |
|||
} |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> createRelation(std::shared_ptr<BaseExpression> left, BinaryRelationExpression::RelationType relationType, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryRelationExpression>(new BinaryRelationExpression(left, right, relationType)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createNot(std::shared_ptr<BaseExpression> child) { |
|||
return std::shared_ptr<UnaryBooleanFunctionExpression>(new UnaryBooleanFunctionExpression(child, UnaryBooleanFunctionExpression::NOT)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createAnd(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryBooleanFunctionExpression>(new BinaryBooleanFunctionExpression(left, right, BinaryBooleanFunctionExpression::AND)); |
|||
} |
|||
std::shared_ptr<BaseExpression> createOr(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryBooleanFunctionExpression>(new BinaryBooleanFunctionExpression(left, right, BinaryBooleanFunctionExpression::OR)); |
|||
} |
|||
std::shared_ptr<BaseExpression> getBoolVariable(const std::string name) { |
|||
return state->getBooleanVariable(name); |
|||
} |
|||
std::shared_ptr<BaseExpression> getIntVariable(const std::string name) { |
|||
return state->getIntegerVariable(name); |
|||
} |
|||
|
|||
protected: |
|||
std::shared_ptr<VariableState> state; |
|||
|
|||
private: |
|||
static std::shared_ptr<T> instanceObject; |
|||
}; |
|||
|
|||
template <typename T> |
|||
std::shared_ptr<T> BaseGrammar<T>::instanceObject; |
|||
} |
|||
} |
|||
} |
|||
#endif /* BASEGRAMMAR_H */ |
|||
|
@ -1,53 +1,35 @@ |
|||
#include "BooleanExpressionGrammar.h"
|
|||
|
|||
#include "IntegerExpressionGrammar.h"
|
|||
#include "ConstBooleanExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
BooleanExpressionGrammar::BooleanExpressionGrammar(std::shared_ptr<VariableState>& state) |
|||
: BooleanExpressionGrammar::base_type(booleanExpression), state(state) { |
|||
|
|||
IntegerExpressionGrammar intExpr(this->state); |
|||
: BooleanExpressionGrammar::base_type(booleanExpression), BaseGrammar(state) { |
|||
|
|||
// This rule defines all identifiers that have not been previously used.
|
|||
identifierName %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]][ qi::_pass = phoenix::bind(&storm::parser::prism::VariableState::isIdentifier, this->state.get(), qi::_1) ]; |
|||
identifierName.name("identifier"); |
|||
freeIdentifierName %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]][ qi::_pass = phoenix::bind(&storm::parser::prism::VariableState::isFreeIdentifier, this->state.get(), qi::_1) ]; |
|||
freeIdentifierName.name("unused identifier"); |
|||
booleanExpression %= orExpression; |
|||
booleanExpression.name("boolean expression"); |
|||
|
|||
// This block defines all literal expressions.
|
|||
booleanLiteralExpression = qi::bool_[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BooleanLiteral>(qi::_1))]; |
|||
booleanLiteralExpression.name("boolean literal"); |
|||
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"); |
|||
|
|||
// This block defines all expressions that are variables.
|
|||
std::shared_ptr<BaseExpression> boolvarexpr = std::shared_ptr<BaseExpression>(new VariableExpression(BaseExpression::bool_, std::numeric_limits<uint_fast64_t>::max(), "bool", std::shared_ptr<BaseExpression>(nullptr), std::shared_ptr<BaseExpression>(nullptr))); |
|||
booleanVariableExpression = identifierName[qi::_val = boolvarexpr]; |
|||
booleanVariableExpression.name("boolean variable"); |
|||
notExpression = atomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> atomicBooleanExpression)[qi::_val = phoenix::bind(&BaseGrammar::createNot, this, qi::_1)]; |
|||
notExpression.name("boolean expression"); |
|||
|
|||
// This block defines all atomic expressions that are constant, i.e. literals and constants.
|
|||
booleanConstantExpression %= (this->state->booleanConstants_ | booleanLiteralExpression); |
|||
booleanConstantExpression.name("boolean constant or literal"); |
|||
atomicBooleanExpression %= (relativeExpression | booleanVariableExpression | qi::lit("(") >> booleanExpression >> qi::lit(")") | ConstBooleanExpressionGrammar::instance(this->state)); |
|||
atomicBooleanExpression.name("boolean expression"); |
|||
|
|||
// This block defines all expressions of type boolean.
|
|||
relativeExpression = (intExpr >> relations_ >> intExpr)[qi::_val = phoenix::construct<std::shared_ptr<storm::ir::expressions::BaseExpression>>(phoenix::new_<storm::ir::expressions::BinaryRelationExpression>(qi::_1, qi::_3, qi::_2))]; |
|||
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"); |
|||
atomicBooleanExpression %= (relativeExpression | booleanVariableExpression | qi::lit("(") >> booleanExpression >> qi::lit(")") | booleanConstantExpression); |
|||
atomicBooleanExpression.name("boolean expression"); |
|||
notExpression = atomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> atomicBooleanExpression)[qi::_val = phoenix::construct<std::shared_ptr<UnaryBooleanFunctionExpression>>(phoenix::new_<UnaryBooleanFunctionExpression>(qi::_1, UnaryBooleanFunctionExpression::NOT))]; |
|||
notExpression.name("boolean expression"); |
|||
andExpression = notExpression[qi::_val = qi::_1] >> *(qi::lit("&") >> notExpression)[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BinaryBooleanFunctionExpression>(qi::_val, qi::_1, BinaryBooleanFunctionExpression::AND))]; |
|||
andExpression.name("boolean expression"); |
|||
orExpression = andExpression[qi::_val = qi::_1] >> *(qi::lit("|") >> andExpression)[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BinaryBooleanFunctionExpression>(qi::_val, qi::_1, BinaryBooleanFunctionExpression::OR))]; |
|||
orExpression.name("boolean expression"); |
|||
booleanExpression %= orExpression; |
|||
booleanExpression.name("boolean expression"); |
|||
|
|||
// This block defines auxiliary entities that are used to check whether a certain variable exist.
|
|||
booleanVariableName %= this->state->booleanVariableNames_; |
|||
booleanVariableName.name("boolean variable"); |
|||
unassignedLocalBooleanVariableName %= this->state->localBooleanVariables_ - this->state->assignedLocalBooleanVariables_; |
|||
unassignedLocalBooleanVariableName.name("unassigned local boolean variable"); |
|||
booleanVariableExpression = IdentifierGrammar::instance(this->state)[qi::_val = phoenix::bind(&BaseGrammar::getBoolVariable, this, qi::_1)]; |
|||
booleanVariableExpression.name("boolean variable"); |
|||
} |
|||
|
|||
} |
|||
|
@ -1,31 +1,53 @@ |
|||
#include "ConstBooleanExpressionGrammar.h"
|
|||
|
|||
#include "ConstIntegerExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
std::shared_ptr<BaseExpression> ConstBooleanExpressionGrammar::createRelation(std::shared_ptr<BaseExpression> left, BinaryRelationExpression::RelationType relationType, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryRelationExpression>(new BinaryRelationExpression(left, right, relationType)); |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstBooleanExpressionGrammar::createNot(std::shared_ptr<BaseExpression> child) { |
|||
return std::shared_ptr<UnaryBooleanFunctionExpression>(new UnaryBooleanFunctionExpression(child, UnaryBooleanFunctionExpression::NOT)); |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstBooleanExpressionGrammar::createAnd(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryBooleanFunctionExpression>(new BinaryBooleanFunctionExpression(left, right, BinaryBooleanFunctionExpression::AND)); |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstBooleanExpressionGrammar::createOr(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right) { |
|||
return std::shared_ptr<BinaryBooleanFunctionExpression>(new BinaryBooleanFunctionExpression(left, right, BinaryBooleanFunctionExpression::OR)); |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstBooleanExpressionGrammar::createLiteral(const bool value) { |
|||
return std::shared_ptr<BooleanLiteral>(new BooleanLiteral(value)); |
|||
} |
|||
|
|||
ConstBooleanExpressionGrammar::ConstBooleanExpressionGrammar(std::shared_ptr<VariableState>& state) |
|||
: ConstBooleanExpressionGrammar::base_type(constantBooleanExpression), state(state) { |
|||
: ConstBooleanExpressionGrammar::base_type(constantBooleanExpression), BaseGrammar(state) { |
|||
|
|||
ConstIntegerExpressionGrammar constIntExpr(this->state); |
|||
constantBooleanExpression %= constantOrExpression; |
|||
constantBooleanExpression.name("constant boolean expression"); |
|||
|
|||
constantOrExpression = constantAndExpression[qi::_val = qi::_1] >> *(qi::lit("|") >> constantAndExpression)[qi::_val = phoenix::bind(&ConstBooleanExpressionGrammar::createOr, this, qi::_val, qi::_1)]; |
|||
constantOrExpression.name("constant boolean expression"); |
|||
|
|||
constantAndExpression = constantNotExpression[qi::_val = qi::_1] >> *(qi::lit("&") >> constantNotExpression)[qi::_val = phoenix::bind(&ConstBooleanExpressionGrammar::createAnd, this, qi::_val, qi::_1)]; |
|||
constantAndExpression.name("constant boolean expression"); |
|||
|
|||
constantNotExpression = constantAtomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> constantAtomicBooleanExpression)[qi::_val = phoenix::bind(&ConstBooleanExpressionGrammar::createNot, this, qi::_1)]; |
|||
constantNotExpression.name("constant boolean expression"); |
|||
|
|||
booleanLiteralExpression = qi::bool_[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BooleanLiteral>(qi::_1))]; |
|||
booleanLiteralExpression.name("boolean literal"); |
|||
booleanConstantExpression %= (this->state->booleanConstants_ | booleanLiteralExpression); |
|||
booleanConstantExpression.name("boolean constant or literal"); |
|||
constantRelativeExpression = (constIntExpr >> relations_ >> constIntExpr)[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BinaryRelationExpression>(qi::_1, qi::_3, qi::_2))]; |
|||
constantRelativeExpression.name("constant boolean expression"); |
|||
constantAtomicBooleanExpression %= (constantRelativeExpression | qi::lit("(") >> constantBooleanExpression >> qi::lit(")") | booleanLiteralExpression | booleanConstantExpression); |
|||
constantAtomicBooleanExpression.name("constant boolean expression"); |
|||
constantNotExpression = constantAtomicBooleanExpression[qi::_val = qi::_1] | (qi::lit("!") >> constantAtomicBooleanExpression)[qi::_val = phoenix::construct<std::shared_ptr<UnaryBooleanFunctionExpression>>(phoenix::new_<UnaryBooleanFunctionExpression>(qi::_1, UnaryBooleanFunctionExpression::NOT))]; |
|||
constantNotExpression.name("constant boolean expression"); |
|||
constantAndExpression = constantNotExpression[qi::_val = qi::_1] >> *(qi::lit("&") >> constantNotExpression)[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BinaryBooleanFunctionExpression>(qi::_val, qi::_1, BinaryBooleanFunctionExpression::AND))]; |
|||
constantAndExpression.name("constant boolean expression"); |
|||
constantOrExpression = constantAndExpression[qi::_val = qi::_1] >> *(qi::lit("|") >> constantAndExpression)[qi::_val = phoenix::construct<std::shared_ptr<BaseExpression>>(phoenix::new_<BinaryBooleanFunctionExpression>(qi::_val, qi::_1, BinaryBooleanFunctionExpression::OR))]; |
|||
constantOrExpression.name("constant boolean expression"); |
|||
constantBooleanExpression %= constantOrExpression; |
|||
constantBooleanExpression.name("constant boolean expression"); |
|||
|
|||
constantRelativeExpression = (ConstIntegerExpressionGrammar::instance(this->state) >> relations_ >> ConstIntegerExpressionGrammar::instance(this->state))[qi::_val = phoenix::bind(&ConstBooleanExpressionGrammar::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(&ConstBooleanExpressionGrammar::createLiteral, this, qi::_1)]; |
|||
booleanLiteralExpression.name("boolean literal"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,53 @@ |
|||
#include "ConstDoubleExpressionGrammar.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
|
|||
std::shared_ptr<BaseExpression> ConstDoubleExpressionGrammar::createLiteral(double value) { |
|||
return std::shared_ptr<DoubleLiteral>(new DoubleLiteral(value)); |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstDoubleExpressionGrammar::createPlus(const std::shared_ptr<BaseExpression> left, bool addition, const std::shared_ptr<BaseExpression> right) { |
|||
if (addition) { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::PLUS)); |
|||
} else { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::MINUS)); |
|||
} |
|||
} |
|||
std::shared_ptr<BaseExpression> ConstDoubleExpressionGrammar::createMult(const std::shared_ptr<BaseExpression> left, bool multiplication, const std::shared_ptr<BaseExpression> right) { |
|||
if (multiplication) { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::TIMES)); |
|||
} else { |
|||
return std::shared_ptr<BinaryNumericalFunctionExpression>(new BinaryNumericalFunctionExpression(BaseExpression::double_, left, right, BinaryNumericalFunctionExpression::DIVIDE)); |
|||
} |
|||
} |
|||
|
|||
ConstDoubleExpressionGrammar::ConstDoubleExpressionGrammar(std::shared_ptr<VariableState>& 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) |
|||
[phoenix::bind(&ConstDoubleExpressionGrammar::createPlus, 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) |
|||
[phoenix::bind(&ConstDoubleExpressionGrammar::createMult, this, qi::_val, qi::_a, qi::_1)]; |
|||
constantDoubleMultExpression.name("constant double expression"); |
|||
|
|||
constantAtomicDoubleExpression %= (qi::lit("(") >> constantDoubleExpression >> qi::lit(")") | doubleConstantExpression); |
|||
constantAtomicDoubleExpression.name("constant double expression"); |
|||
|
|||
doubleConstantExpression %= (this->state->doubleConstants_ | doubleLiteralExpression); |
|||
doubleConstantExpression.name("double constant or literal"); |
|||
|
|||
doubleLiteralExpression = qi::double_[qi::_val = phoenix::bind(&ConstDoubleExpressionGrammar::createLiteral, this, qi::_1)]; |
|||
doubleLiteralExpression.name("double literal"); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* |
|||
* 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 { |
|||
|
|||
class ConstDoubleExpressionGrammar : public qi::grammar<Iterator, std::shared_ptr<BaseExpression>(), Skipper, Unused>, public BaseGrammar<ConstDoubleExpressionGrammar> { |
|||
public: |
|||
ConstDoubleExpressionGrammar(std::shared_ptr<VariableState>& 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; |
|||
|
|||
std::shared_ptr<BaseExpression> createLiteral(double value); |
|||
std::shared_ptr<BaseExpression> createPlus(const std::shared_ptr<BaseExpression> left, bool addition, const std::shared_ptr<BaseExpression> right); |
|||
std::shared_ptr<BaseExpression> createMult(const std::shared_ptr<BaseExpression> left, bool multiplication, const std::shared_ptr<BaseExpression> right); |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* CONSTDOUBLEEXPRESSIONGRAMMAR_H */ |
|||
|
@ -0,0 +1,23 @@ |
|||
#include "IdentifierGrammars.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
namespace prism { |
|||
|
|||
IdentifierGrammar::IdentifierGrammar(std::shared_ptr<VariableState>& 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>& 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"); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
/* |
|||
* 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 { |
|||
|
|||
class IdentifierGrammar : public qi::grammar<Iterator, std::string(), Skipper, Unused>, public BaseGrammar<IdentifierGrammar> { |
|||
public: |
|||
IdentifierGrammar(std::shared_ptr<VariableState>& state); |
|||
private: |
|||
qi::rule<Iterator, std::string(), Skipper> identifierName; |
|||
}; |
|||
|
|||
class FreeIdentifierGrammar : public qi::grammar<Iterator, std::string(), Skipper, Unused>, public BaseGrammar<IdentifierGrammar> { |
|||
public: |
|||
FreeIdentifierGrammar(std::shared_ptr<VariableState>& state); |
|||
private: |
|||
qi::rule<Iterator, std::string(), Skipper> freeIdentifierName; |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
#endif /* IDENTIFIERGRAMMARS_H */ |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue