From 480da6ff0960402124ed98f81a0273b9b529ca07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 23 Jun 2017 00:51:09 +0200 Subject: [PATCH] Built initial AST for normalized PDDL. --- .../include/pddlparse/NormalizedAST.h | 161 ++++++++++++++ .../include/pddlparse/NormalizedASTForward.h | 196 ++++++++++++++++++ 2 files changed, 357 insertions(+) create mode 100644 lib/pddlparse/include/pddlparse/NormalizedAST.h create mode 100644 lib/pddlparse/include/pddlparse/NormalizedASTForward.h diff --git a/lib/pddlparse/include/pddlparse/NormalizedAST.h b/lib/pddlparse/include/pddlparse/NormalizedAST.h new file mode 100644 index 0000000..f25949a --- /dev/null +++ b/lib/pddlparse/include/pddlparse/NormalizedAST.h @@ -0,0 +1,161 @@ +#ifndef __PDDL_PARSE__NORMALIZED_AST_H +#define __PDDL_PARSE__NORMALIZED_AST_H + +#include +#include +#include +#include +#include + +#include + +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 &¶meters) + : 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; + std::experimental::optional 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; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +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 problem; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/lib/pddlparse/include/pddlparse/NormalizedASTForward.h b/lib/pddlparse/include/pddlparse/NormalizedASTForward.h new file mode 100644 index 0000000..eaacac6 --- /dev/null +++ b/lib/pddlparse/include/pddlparse/NormalizedASTForward.h @@ -0,0 +1,196 @@ +#ifndef __PDDL_PARSE__NORMALIZED_AST_FORWARD_H +#define __PDDL_PARSE__NORMALIZED_AST_FORWARD_H + +#include + +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; +using DerivedPredicates = std::vector; +struct DerivedPredicateDeclaration; +using DerivedPredicateDeclarationPointer = std::unique_ptr; +using DerivedPredicateDeclarations = std::vector; +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; +using Actions = std::vector; +struct Description; +using DescriptionPointer = std::unique_ptr; +struct Domain; +using DomainPointer = std::unique_ptr; +struct Problem; +using ProblemPointer = std::unique_ptr; +enum class Requirement; +using Requirements = std::vector; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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>; +} + +class Literal : public detail::LiteralT +{ + using detail::LiteralT::LiteralT; +}; + +using Literals = std::vector; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class Precondition; + +namespace detail +{ +using PreconditionT = Variant< + Literal, + AndPointer>; +} + +class Precondition : public detail::PreconditionT +{ + using detail::PreconditionT::PreconditionT; +}; + +using Preconditions = std::vector; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class ConditionalEffect; + +namespace detail +{ +using ConditionalEffectT = Variant< + Literal, + AndPointer, + NotPointer>; +} + +class ConditionalEffect : public detail::ConditionalEffectT +{ + using detail::ConditionalEffectT::ConditionalEffectT; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +// TODO: support effects appropriately +class Effect; + +namespace detail +{ +using EffectT = Variant< + AtomicFormula, + AndPointer, + ast::ForAllPointer, + NotPointer, + WhenPointer>; +} + +class Effect : public detail::EffectT +{ + using detail::EffectT::EffectT; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +using Fact = Literal; +using Facts = std::vector; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +using Goal = Precondition; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif