patrick
/
plasp
Archived
1
0
Fork 0

Added AST representation for “equals” expressions.

This commit is contained in:
Patrick Lühne 2017-08-31 17:54:30 +02:00
parent 9199b68080
commit 716b4801aa
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
5 changed files with 43 additions and 2 deletions

View File

@ -292,6 +292,19 @@ struct Either: public NAry<Either<Argument>, Argument>
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ArgumentLeft, class ArgumentRight>
struct Equals: public Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight>
{
static constexpr const auto Identifier = "=";
explicit Equals(ArgumentLeft &&argumentLeft, ArgumentRight &&argumentRight)
: Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight>(std::move(argumentLeft), std::move(argumentRight))
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
struct Exists: public Quantified<Exists<Argument>, Argument>
{

View File

@ -70,6 +70,10 @@ template<class Argument>
struct Either;
template<class Argument>
using EitherPointer = std::unique_ptr<Either<Argument>>;
template<class ArgumentLeft, class ArgumentRight>
struct Equals;
template<class ArgumentLeft, class ArgumentRight>
using EqualsPointer = std::unique_ptr<Equals<ArgumentLeft, ArgumentRight>>;
template<class Argument>
struct Exists;
template<class Argument>
@ -136,8 +140,8 @@ using Terms = std::vector<Term>;
namespace detail
{
// TODO: add missing types
using AtomicFormulaT = Variant<
EqualsPointer<Term, Term>,
PredicatePointer>;
}

View File

@ -267,6 +267,14 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either<
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ArgumentLeft, class ArgumentRight>
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Equals<ArgumentLeft, ArgumentRight> &equals, pddl::detail::PrintContext &printContext)
{
return print(stream, static_cast<const Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight> &>(equals), printContext);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists<Argument> &exists, pddl::detail::PrintContext &printContext)
{

View File

@ -65,6 +65,15 @@ void collectFreeVariables(const ast::AndPointer<Argument> &and_, std::vector<nor
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ArgumentLeft, class ArgumentRight>
void collectFreeVariables(const ast::EqualsPointer<ArgumentLeft, ArgumentRight> &equals, std::vector<normalizedAST::VariableDeclaration *> &freeVariables, VariableStack &variableStack)
{
collectFreeVariables(equals->argumentLeft, freeVariables, variableStack);
collectFreeVariables(equals->argumentRight, freeVariables, variableStack);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Argument>
void collectFreeVariables(const ast::ExistsPointer<Argument> &exists, std::vector<normalizedAST::VariableDeclaration *> &freeVariables, VariableStack &variableStack)
{

View File

@ -17,13 +17,20 @@ namespace detail
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula)
{
const auto handleEquals =
[&](ast::EqualsPointer<ast::Term, ast::Term> &) -> normalizedAST::AtomicFormula
{
// TODO: implement
throw NormalizationException("“=” expressions currently unsupported by normalization");
};
const auto handlePredicate =
[&](ast::PredicatePointer &predicate) -> normalizedAST::AtomicFormula
{
return std::move(predicate);
};
return atomicFormula.match(handlePredicate);
return atomicFormula.match(handleEquals, handlePredicate);
}
////////////////////////////////////////////////////////////////////////////////////////////////////