Added support for Imply expression.

This commit is contained in:
Patrick Lühne 2016-06-04 17:20:25 +02:00
parent 30b4a1f614
commit 4ae37603f4
6 changed files with 178 additions and 2 deletions

View File

@ -37,6 +37,9 @@ using Constants = std::vector<ConstantPointer>;
class Either;
using EitherPointer = std::unique_ptr<Either>;
class Imply;
using ImplyPointer = std::unique_ptr<Imply>;
class Not;
using NotPointer = std::unique_ptr<Not>;

View File

@ -0,0 +1,54 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__BINARY_H
#define __PLASP__PDDL__EXPRESSIONS__BINARY_H
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/expressions/Variable.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Binary
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Binary: public Expression
{
public:
const Expression *leftArgument() const;
const Expression *rightArgument() const;
protected:
template<typename ExpressionParser>
void parse(Context &context, const Variables &parameters, ExpressionParser parseExpression);
private:
ExpressionPointer m_leftArgument;
ExpressionPointer m_rightArgument;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename ExpressionParser>
void Binary::parse(Context &context, const Variables &parameters, ExpressionParser parseExpression)
{
// Assume that expression identifier (imply, exists, etc.) is already parsed
// Parse arguments of the expression
m_leftArgument = parseExpression(context, parameters);
m_rightArgument = parseExpression(context, parameters);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@ -0,0 +1,52 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__IMPLY_H
#define __PLASP__PDDL__EXPRESSIONS__IMPLY_H
#include <plasp/pddl/expressions/Binary.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Imply
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Imply: public Binary
{
public:
template<typename ExpressionParser>
static ImplyPointer parse(Context &context, const Variables &parameters,
ExpressionParser parseExpression);
public:
void accept(ExpressionVisitor &expressionVisitor) const override;
private:
Imply() = default;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename ExpressionParser>
ImplyPointer Imply::parse(Context &context, const Variables &parameters,
ExpressionParser parseExpression)
{
auto expression = std::make_unique<Imply>(Imply());
expression->Binary::parse(context, parameters, parseExpression);
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@ -3,6 +3,7 @@
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/expressions/And.h>
#include <plasp/pddl/expressions/Imply.h>
#include <plasp/pddl/expressions/Not.h>
#include <plasp/pddl/expressions/Or.h>
#include <plasp/pddl/expressions/Predicate.h>
@ -93,8 +94,9 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
expression = expressions::Or::parse(context, parameters, parseExpression);
else if (expressionIdentifier == "not")
expression = expressions::Not::parse(context, parameters, parseExpression);
else if (expressionIdentifier == "imply"
|| expressionIdentifier == "exists"
else if (expressionIdentifier == "imply")
expression = expressions::Imply::parse(context, parameters, parseExpression);
else if (expressionIdentifier == "exists"
|| expressionIdentifier == "forall"
|| expressionIdentifier == "-"
|| expressionIdentifier == "="

View File

@ -0,0 +1,38 @@
#include <plasp/pddl/expressions/Binary.h>
#include <algorithm>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/ExpressionVisitor.h>
#include <plasp/pddl/Identifier.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Binary
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const Expression *Binary::leftArgument() const
{
return m_leftArgument.get();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const Expression *Binary::rightArgument() const
{
return m_rightArgument.get();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@ -0,0 +1,27 @@
#include <plasp/pddl/expressions/Imply.h>
#include <plasp/pddl/ExpressionVisitor.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Imply
//
////////////////////////////////////////////////////////////////////////////////////////////////////
void Imply::accept(plasp::pddl::ExpressionVisitor &expressionVisitor) const
{
expressionVisitor.visit(*this);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}