Implemented parsing conditional effects.

This commit is contained in:
Patrick Lühne 2016-09-08 15:56:30 +02:00
parent 4fc9b35c13
commit 9cccba42e0
4 changed files with 111 additions and 1 deletions

View File

@ -87,6 +87,9 @@ using UnsupportedPointer = boost::intrusive_ptr<Unsupported>;
class Variable; class Variable;
using VariablePointer = boost::intrusive_ptr<Variable>; using VariablePointer = boost::intrusive_ptr<Variable>;
using Variables = std::vector<VariablePointer>; using Variables = std::vector<VariablePointer>;
class When;
using WhenPointer = boost::intrusive_ptr<When>;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -113,6 +116,7 @@ class Expression
Reference, Reference,
Unsupported, Unsupported,
Variable, Variable,
When,
}; };
public: public:
@ -181,6 +185,9 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
ExpressionPointer parseEffectExpression(Context &context, ExpressionPointer parseEffectExpression(Context &context,
ExpressionContext &expressionContext); ExpressionContext &expressionContext);
ExpressionPointer parseConditionalEffectExpression(Context &context,
ExpressionContext &expressionContext);
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
} }

View File

@ -0,0 +1,67 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__WHEN_H
#define __PLASP__PDDL__EXPRESSIONS__WHEN_H
#include <plasp/pddl/expressions/Binary.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// When
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class When: public Binary<When>
{
public:
static const Expression::Type ExpressionType = Expression::Type::When;
static const std::string Identifier;
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
static WhenPointer parse(Context &context, ExpressionContext &expressionContext,
ConditionExpressionParser parseConditionExpression,
ImplicationExpressionParser parseImplicationExpression);
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename ConditionExpressionParser, typename ImplicationExpressionParser>
WhenPointer When::parse(Context &context, ExpressionContext &expressionContext,
ConditionExpressionParser parseConditionExpression,
ImplicationExpressionParser parseImplicationExpression)
{
auto &parser = context.parser;
const auto position = parser.position();
if (!parser.testAndSkip<std::string>("(")
|| !parser.testIdentifierAndSkip(Identifier))
{
parser.seek(position);
return nullptr;
}
auto expression = WhenPointer(new When);
// Parse arguments of the expression
expression->setArgument(0, parseConditionExpression(context, expressionContext));
expression->setArgument(1, parseImplicationExpression(context, expressionContext));
parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@ -13,6 +13,7 @@
#include <plasp/pddl/expressions/Predicate.h> #include <plasp/pddl/expressions/Predicate.h>
#include <plasp/pddl/expressions/PredicateDeclaration.h> #include <plasp/pddl/expressions/PredicateDeclaration.h>
#include <plasp/pddl/expressions/Unsupported.h> #include <plasp/pddl/expressions/Unsupported.h>
#include <plasp/pddl/expressions/When.h>
#include <plasp/utils/ParserException.h> #include <plasp/utils/ParserException.h>
namespace plasp namespace plasp
@ -230,7 +231,8 @@ ExpressionPointer parseEffectExpression(Context &context, ExpressionContext &exp
ExpressionPointer expression; ExpressionPointer expression;
if ((expression = expressions::And::parse(context, expressionContext, parseEffectExpression)) if ((expression = expressions::And::parse(context, expressionContext, parseEffectExpression))
|| (expression = expressions::ForAll::parse(context, expressionContext, parseEffectExpression))) || (expression = expressions::ForAll::parse(context, expressionContext, parseEffectExpression))
|| (expression = expressions::When::parse(context, expressionContext, parseExpression, parseConditionalEffectExpression)))
{ {
return expression; return expression;
} }
@ -297,6 +299,18 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer parseConditionalEffectExpression(Context &context, ExpressionContext &expressionContext)
{
ExpressionPointer expression;
if ((expression = expressions::And::parse(context, expressionContext, parseEffectBodyExpression)))
return expression;
return parseEffectBodyExpression(context, expressionContext);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer parsePredicate(Context &context, ExpressionContext &expressionContext) ExpressionPointer parsePredicate(Context &context, ExpressionContext &expressionContext)
{ {
auto &parser = context.parser; auto &parser = context.parser;

View File

@ -0,0 +1,22 @@
#include <plasp/pddl/expressions/When.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// When
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const std::string When::Identifier = "when";
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}