Built initial AST for normalized PDDL.

This commit is contained in:
Patrick Lühne 2017-06-23 00:51:09 +02:00
parent 834209d506
commit 480da6ff09
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 357 additions and 0 deletions

View File

@ -0,0 +1,161 @@
#ifndef __PDDL_PARSE__NORMALIZED_AST_H
#define __PDDL_PARSE__NORMALIZED_AST_H
#include <limits>
#include <experimental/optional>
#include <set>
#include <type_traits>
#include <vector>
#include <pddlparse/NormalizedASTForward.h>
namespace pddl
{
namespace normalizedAST
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Normalized AST
//
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Compounds
////////////////////////////////////////////////////////////////////////////////////////////////////
struct DerivedPredicate
{
using Arguments = Terms;
explicit DerivedPredicate(Arguments &&arguments, DerivedPredicateDeclaration *declaration)
: arguments{std::move(arguments)},
declaration{declaration}
{
}
DerivedPredicate(const DerivedPredicate &other) = delete;
DerivedPredicate &operator=(const DerivedPredicate &&other) = delete;
DerivedPredicate(DerivedPredicate &&other) = default;
DerivedPredicate &operator=(DerivedPredicate &&other) = default;
Arguments arguments;
DerivedPredicateDeclaration *declaration;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct DerivedPredicateDeclaration
{
explicit DerivedPredicateDeclaration(std::string &&name, VariableDeclarations &&parameters)
: name{std::move(name)},
parameters{std::move(parameters)}
{
}
DerivedPredicateDeclaration(const DerivedPredicateDeclaration &other) = delete;
DerivedPredicateDeclaration &operator=(const DerivedPredicateDeclaration &&other) = delete;
DerivedPredicateDeclaration(DerivedPredicateDeclaration &&other) = default;
DerivedPredicateDeclaration &operator=(DerivedPredicateDeclaration &&other) = default;
std::string name;
VariableDeclarations parameters;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// PDDL Structure
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Action
{
Action() = default;
Action(const Action &other) = delete;
Action &operator=(const Action &&other) = delete;
Action(Action &&other) = default;
Action &operator=(Action &&other) = default;
std::string name;
VariableDeclarations parameters;
std::experimental::optional<Precondition> precondition;
std::experimental::optional<Effect> effect;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Domain
{
Domain() = default;
Domain(const Domain &other) = delete;
Domain &operator=(const Domain &&other) = delete;
Domain(Domain &&other) = delete;
Domain &operator=(Domain &&other) = delete;
std::string name;
PrimitiveTypeDeclarations types;
ConstantDeclarations constants;
PredicateDeclarations predicates;
DerivedPredicateDeclarations derivedPredicates;
Actions actions;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct InitialState
{
InitialState() = default;
InitialState(const InitialState &other) = delete;
InitialState &operator=(const InitialState &&other) = delete;
InitialState(InitialState &&other) = default;
InitialState &operator=(InitialState &&other) = default;
Facts facts;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Problem
{
Problem() = default;
Problem(Domain *domain)
: domain{domain}
{
}
Problem(const Problem &other) = delete;
Problem &operator=(const Problem &&other) = delete;
Problem(Problem &&other) = default;
Problem &operator=(Problem &&other) = default;
Domain *domain;
std::string name;
ConstantDeclarations objects;
InitialState initialState;
std::experimental::optional<Goal> goal;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Description
{
Description() = default;
Description(const Description &other) = delete;
Description &operator=(const Description &&other) = delete;
Description(Description &&other) = default;
Description &operator=(Description &&other) = default;
DomainPointer domain;
std::experimental::optional<ProblemPointer> problem;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -0,0 +1,196 @@
#ifndef __PDDL_PARSE__NORMALIZED_AST_FORWARD_H
#define __PDDL_PARSE__NORMALIZED_AST_FORWARD_H
#include <pddlparse/AST.h>
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Normalized AST Forward Declarations
//
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace normalizedAST
{
////////////////////////////////////////////////////////////////////////////////////////////////////
// Primitives
////////////////////////////////////////////////////////////////////////////////////////////////////
using ast::Constant;
using ast::ConstantPointer;
using ast::ConstantDeclaration;
using ast::ConstantDeclarationPointer;
using ast::ConstantDeclarations;
using ast::PrimitiveTypePointer;
using ast::PrimitiveType;
using ast::PrimitiveTypePointer;
using ast::PrimitiveTypes;
using ast::PrimitiveTypeDeclaration;
using ast::PrimitiveTypeDeclarationPointer;
using ast::PrimitiveTypeDeclarations;
using ast::Variable;
using ast::VariablePointer;
using ast::Variables;
using ast::VariableDeclaration;
using ast::VariableDeclarationPointer;
using ast::VariableDeclarations;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Compounds
////////////////////////////////////////////////////////////////////////////////////////////////////
struct DerivedPredicate;
using DerivedPredicatePointer = std::unique_ptr<DerivedPredicate>;
using DerivedPredicates = std::vector<DerivedPredicatePointer>;
struct DerivedPredicateDeclaration;
using DerivedPredicateDeclarationPointer = std::unique_ptr<DerivedPredicateDeclaration>;
using DerivedPredicateDeclarations = std::vector<DerivedPredicateDeclarationPointer>;
using ast::Predicate;
using ast::PredicatePointer;
using ast::Predicates;
using ast::PredicateDeclaration;
using ast::PredicateDeclarationPointer;
using ast::PredicateDeclarations;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Expressions
////////////////////////////////////////////////////////////////////////////////////////////////////
using ast::And;
using ast::AndPointer;
using ast::At;
using ast::AtPointer;
using ast::Either;
using ast::EitherPointer;
using ast::Exists;
using ast::Not;
using ast::NotPointer;
using ast::When;
using ast::WhenPointer;
////////////////////////////////////////////////////////////////////////////////////////////////////
// PDDL Structure
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Action;
using ActionPointer = std::unique_ptr<Action>;
using Actions = std::vector<ActionPointer>;
struct Description;
using DescriptionPointer = std::unique_ptr<Description>;
struct Domain;
using DomainPointer = std::unique_ptr<Domain>;
struct Problem;
using ProblemPointer = std::unique_ptr<Problem>;
enum class Requirement;
using Requirements = std::vector<Requirement>;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Variants
////////////////////////////////////////////////////////////////////////////////////////////////////
using ast::Term;
using ast::Terms;
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace detail
{
using AtomicFormulaT = Variant<
DerivedPredicatePointer,
PredicatePointer>;
}
class AtomicFormula : public detail::AtomicFormulaT
{
using detail::AtomicFormulaT::AtomicFormulaT;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace detail
{
using LiteralT = Variant<
AtomicFormula,
NotPointer<AtomicFormula>>;
}
class Literal : public detail::LiteralT
{
using detail::LiteralT::LiteralT;
};
using Literals = std::vector<Literal>;
////////////////////////////////////////////////////////////////////////////////////////////////////
class Precondition;
namespace detail
{
using PreconditionT = Variant<
Literal,
AndPointer<Literal>>;
}
class Precondition : public detail::PreconditionT
{
using detail::PreconditionT::PreconditionT;
};
using Preconditions = std::vector<Precondition>;
////////////////////////////////////////////////////////////////////////////////////////////////////
class ConditionalEffect;
namespace detail
{
using ConditionalEffectT = Variant<
Literal,
AndPointer<Literal>,
NotPointer<ConditionalEffect>>;
}
class ConditionalEffect : public detail::ConditionalEffectT
{
using detail::ConditionalEffectT::ConditionalEffectT;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: support effects appropriately
class Effect;
namespace detail
{
using EffectT = Variant<
AtomicFormula,
AndPointer<Effect>,
ast::ForAllPointer<Effect>,
NotPointer<Effect>,
WhenPointer<Precondition, ConditionalEffect>>;
}
class Effect : public detail::EffectT
{
using detail::EffectT::EffectT;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
using Fact = Literal;
using Facts = std::vector<Fact>;
////////////////////////////////////////////////////////////////////////////////////////////////////
using Goal = Precondition;
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif