Support exponentiation operator
Because of a bug in the Clingo API, the exponentation operator was not properly exposed to anthem. This updates Clingo to a version with a fixed API and adds proper support for exponentation within anthem along with a matching unit test.
This commit is contained in:
parent
7b6729acaa
commit
eaabeb0c55
@ -32,7 +32,8 @@ struct BinaryOperation
|
|||||||
Minus,
|
Minus,
|
||||||
Multiplication,
|
Multiplication,
|
||||||
Division,
|
Division,
|
||||||
Modulo
|
Modulo,
|
||||||
|
Power
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit BinaryOperation(Operator operator_, Term &&left, Term &&right)
|
explicit BinaryOperation(Operator operator_, Term &&left, Term &&right)
|
||||||
|
@ -23,6 +23,12 @@ ast::BinaryOperation::Operator translate(Clingo::AST::BinaryOperator binaryOpera
|
|||||||
{
|
{
|
||||||
switch (binaryOperator)
|
switch (binaryOperator)
|
||||||
{
|
{
|
||||||
|
case Clingo::AST::BinaryOperator::XOr:
|
||||||
|
throw TranslationException(term.location, "binary operation “xor” currently unsupported");
|
||||||
|
case Clingo::AST::BinaryOperator::Or:
|
||||||
|
throw TranslationException(term.location, "binary operation “or” currently unsupported");
|
||||||
|
case Clingo::AST::BinaryOperator::And:
|
||||||
|
throw TranslationException(term.location, "binary operation “and” currently unsupported");
|
||||||
case Clingo::AST::BinaryOperator::Plus:
|
case Clingo::AST::BinaryOperator::Plus:
|
||||||
return ast::BinaryOperation::Operator::Plus;
|
return ast::BinaryOperation::Operator::Plus;
|
||||||
case Clingo::AST::BinaryOperator::Minus:
|
case Clingo::AST::BinaryOperator::Minus:
|
||||||
@ -33,11 +39,11 @@ ast::BinaryOperation::Operator translate(Clingo::AST::BinaryOperator binaryOpera
|
|||||||
return ast::BinaryOperation::Operator::Division;
|
return ast::BinaryOperation::Operator::Division;
|
||||||
case Clingo::AST::BinaryOperator::Modulo:
|
case Clingo::AST::BinaryOperator::Modulo:
|
||||||
return ast::BinaryOperation::Operator::Modulo;
|
return ast::BinaryOperation::Operator::Modulo;
|
||||||
default:
|
case Clingo::AST::BinaryOperator::Power:
|
||||||
throw TranslationException(term.location, "“binary operation” terms currently unsupported");
|
return ast::BinaryOperation::Operator::Power;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast::BinaryOperation::Operator::Plus;
|
throw TranslationException(term.location, "unknown binary operation");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -85,6 +85,8 @@ inline output::ColorStream &print(output::ColorStream &stream, BinaryOperation::
|
|||||||
return (stream << output::Operator("/"));
|
return (stream << output::Operator("/"));
|
||||||
case BinaryOperation::Operator::Modulo:
|
case BinaryOperation::Operator::Modulo:
|
||||||
return (stream << output::Operator("%"));
|
return (stream << output::Operator("%"));
|
||||||
|
case BinaryOperation::Operator::Power:
|
||||||
|
return (stream << output::Operator("**"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit e2187b697f738f236828f7f780b5481c9a9284e6
|
Subproject commit 969ce8f618c4cdf78d5c430ba827217075b88460
|
@ -296,4 +296,12 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
|
|||||||
|
|
||||||
CHECK(output.str() == "((V1 in U1 and V2 in U2 and exists X1, X2 (X1 in U3 and X2 in U4 and q(X1, X2))) -> p(V1, V2))\n");
|
CHECK(output.str() == "((V1 in U1 and V2 in U2 and exists X1, X2 (X1 in U3 and X2 in U4 and q(X1, X2))) -> p(V1, V2))\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("exponentiation operator")
|
||||||
|
{
|
||||||
|
input << "p(N, N ** N) :- N = 1..n.";
|
||||||
|
anthem::translate("input", input, context);
|
||||||
|
|
||||||
|
CHECK(output.str() == "((V1 in U1 and V2 in (U1 ** U1) and exists X1, X2 (X1 in U1 and X2 in 1..n and X1 = X2)) -> p(V1, V2))\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user