Skip to content

Commit

Permalink
fix infinite recursion when parsing :functions
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 22, 2024
1 parent 636222a commit 7d6d02a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const auto atomic_function_skeleton_general_def = lit('(') > function_symbol > t
const auto atomic_function_skeleton_def = atomic_function_skeleton_total_cost | atomic_function_skeleton_general;
const auto function_typed_list_of_atomic_function_skeletons_recursively_def =
(+atomic_function_skeleton >> lit('-')) > type_number > -function_typed_list_of_atomic_function_skeletons;
const auto function_typed_list_of_atomic_function_skeletons_def = function_typed_list_of_atomic_function_skeletons_recursively | *atomic_function_skeleton;
const auto function_typed_list_of_atomic_function_skeletons_def = function_typed_list_of_atomic_function_skeletons_recursively | +atomic_function_skeleton;

const auto atomic_formula_of_terms_predicate_def = (lit('(') >> predicate) > *term > lit(')');
const auto atomic_formula_of_terms_equality_def = (lit('(') >> lit('=')) >> term > term > lit(')');
Expand Down Expand Up @@ -396,8 +396,6 @@ const auto assign_operator_def =
// For action cost effects only
const auto numeric_term_def = function_expression_number | function_expression_head;

// const auto effect_root_def = ((lit('(') >> keyword_lit("and")) > *(effect_production_numeric_fluent_total_cost | effect) > lit(')')) | effect_conditional
// | effect_production | effect_production_numeric_fluent_total_cost;
const auto effect_root_def = ((lit('(') >> keyword_lit("and")) > *effect_numeric_fluent_total_cost_or_effect > lit(')')) | effect_conditional
| effect_production | effect_production_numeric_fluent_total_cost;
const auto effect_def = ((lit('(') >> keyword_lit("and")) > *effect > lit(')')) | effect_conditional | effect_production;
Expand Down
18 changes: 8 additions & 10 deletions src/pddl/parser/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,12 @@ FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node, Context
{
throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, ""));
}
else
{
context.references.untrack(RequirementEnum::ACTION_COSTS);
}
if ((!context.requirements->test(RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)))
{
throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, ""));
}
else
{
context.references.untrack(RequirementEnum::ACTION_COSTS);
context.references.untrack(RequirementEnum::NUMERIC_FLUENTS);
}
context.references.untrack(RequirementEnum::ACTION_COSTS);
context.references.untrack(RequirementEnum::NUMERIC_FLUENTS);

assert(context.scopes.get<TypeImpl>("number").has_value());
const auto [type, _position, _error_handler] = context.scopes.get<TypeImpl>("number").value();
Expand All @@ -173,10 +166,15 @@ FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node, Context

FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node, Context& context)
{
if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS))
if (!context.requirements->test(RequirementEnum::ACTION_COSTS))
{
throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, ""));
}
if ((!context.requirements->test(RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)))
{
throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, ""));
}
context.references.untrack(RequirementEnum::ACTION_COSTS);
context.references.untrack(RequirementEnum::NUMERIC_FLUENTS);

context.scopes.open_scope();
Expand Down
18 changes: 15 additions & 3 deletions src/pddl/parser/initial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ std::variant<GroundLiteral, NumericFluent> parse(const ast::InitialElementNumeri
{
if (!context.requirements->test(RequirementEnum::ACTION_COSTS))
{
throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.scopes.get_error_handler()(node, ""));
throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, ""));
}
if ((!context.requirements->test(RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)))
{
throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, ""));
}
context.references.untrack(RequirementEnum::ACTION_COSTS);
context.references.untrack(RequirementEnum::NUMERIC_FLUENTS);

const auto function_skeleton = parse_function_skeleton_reference(node.function_symbol_total_cost, context);
const auto basic_function_term = context.factories.get_or_create_function(function_skeleton, TermList {});
double number = parse(node.number);
Expand All @@ -61,11 +67,17 @@ std::variant<GroundLiteral, NumericFluent> parse(const ast::InitialElementNumeri

std::variant<GroundLiteral, NumericFluent> parse(const ast::InitialElementNumericFluentsGeneral& node, Context& context)
{
if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS))
if (!context.requirements->test(RequirementEnum::ACTION_COSTS))
{
throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, ""));
throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, ""));
}
if ((!context.requirements->test(RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)))
{
throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, ""));
}
context.references.untrack(RequirementEnum::ACTION_COSTS);
context.references.untrack(RequirementEnum::NUMERIC_FLUENTS);

const auto basic_function_term = parse(node.basic_function_term, context);
double number = parse(node.number);
if (number < 0 && context.requirements->test(RequirementEnum::ACTION_COSTS))
Expand Down
1 change: 1 addition & 0 deletions src/utils/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DomainParser::DomainParser(const fs::path& file_path) :
const auto equal_predicate = context.factories.get_or_create_predicate("=", binary_parameterlist);
context.scopes.insert("=", equal_predicate, {});

std::cout << "Started semantic domain file: " << file_path << std::endl;
m_domain = parse(node, context);

// Only the global scope remains
Expand Down

0 comments on commit 7d6d02a

Please sign in to comment.