summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorHaniel Barbosa <hanielbbarbosa@gmail.com>2021-06-11 18:29:19 -0300
committerGitHub <noreply@github.com>2021-06-11 21:29:19 +0000
commit8ddd5e82c8e896977d5573b639524264c7207d85 (patch)
treeee6a94468288397e290cb3db60db76dbdf69e978 /src/parser
parentf10087c3b347da6ef625a2ad92846551ad324d73 (diff)
Better support for HOL parsing and set up (#6697)
This commit adds a new parser option, --hol, which marks that HOL is being used. This option has the effect of prepending the problem's logic with "HO_", which teels the solver that the logic is higher order. The parser builder, base parser, and SMT2 and TPTP parsers are all updated to work with this new setting, as is the logic info class. For now this parser option is enabling the --uf-ho option for internal use, since for now higher-order solving relies it. In a future PR this dependency will be removed (since this information is already given to the SMT solver via the logic).
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/parser.cpp4
-rw-r--r--src/parser/parser.h23
-rw-r--r--src/parser/parser_builder.cpp3
-rw-r--r--src/parser/smt2/smt2.cpp26
-rw-r--r--src/parser/tptp/Tptp.g6
-rw-r--r--src/parser/tptp/tptp.cpp30
-rw-r--r--src/parser/tptp/tptp.h4
7 files changed, 58 insertions, 38 deletions
diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp
index f6592a931..d96e94d43 100644
--- a/src/parser/parser.cpp
+++ b/src/parser/parser.cpp
@@ -109,8 +109,8 @@ api::Term Parser::getExpressionForNameAndType(const std::string& name,
if(expr.isNull()) {
// the variable is overloaded, try with type if the type exists
if(!t.isNull()) {
- // if we decide later to support annotations for function types, this will update to
- // separate t into ( argument types, return type )
+ // if we decide later to support annotations for function types, this will
+ // update to separate t into ( argument types, return type )
expr = getOverloadedConstantForType(name, t);
if(expr.isNull()) {
parseError("Cannot get overloaded constant for type ascription.");
diff --git a/src/parser/parser.h b/src/parser/parser.h
index 8add1c698..4b04c77b7 100644
--- a/src/parser/parser.h
+++ b/src/parser/parser.h
@@ -303,9 +303,10 @@ public:
virtual api::Term getExpressionForName(const std::string& name);
/**
- * Returns the expression that name should be interpreted as, based on the current binding.
+ * Returns the expression that name should be interpreted as, based on the
+ * current binding.
*
- * This is the same as above but where the name has been type cast to t.
+ * This is the same as above but where the name has been type cast to t.
*/
virtual api::Term getExpressionForNameAndType(const std::string& name,
api::Sort t);
@@ -331,9 +332,9 @@ public:
* This is a generalization of ExprManager::operatorToKind that also
* handles variables whose types are "function-like", i.e. where
* checkFunctionLike(fun) returns true.
- *
+ *
* For examples of the latter, this function returns
- * APPLY_UF if fun has function type,
+ * APPLY_UF if fun has function type,
* APPLY_CONSTRUCTOR if fun has constructor type.
*/
api::Kind getKindForFunction(api::Term fun);
@@ -379,7 +380,7 @@ public:
/**
* Checks whether the given expression is function-like, i.e.
- * it expects arguments. This is checked by looking at the type
+ * it expects arguments. This is checked by looking at the type
* of fun. Examples of function types are function, constructor,
* selector, tester.
* @param fun the expression to check
@@ -443,11 +444,12 @@ public:
std::vector<api::Term> bindBoundVars(const std::vector<std::string> names,
const api::Sort& type);
- /** Create a new variable definition (e.g., from a let binding).
+ /** Create a new variable definition (e.g., from a let binding).
* levelZero is set if the binding must be done at level 0.
* If a symbol with name already exists,
* then if doOverload is true, we create overloaded operators.
- * else if doOverload is false, the existing expression is shadowed by the new expression.
+ * else if doOverload is false, the existing expression is shadowed by the
+ * new expression.
*/
void defineVar(const std::string& name,
const api::Term& val,
@@ -648,9 +650,10 @@ public:
/** Is the symbol bound to a boolean variable? */
bool isBoolean(const std::string& name);
- /** Is fun a function (or function-like thing)?
- * Currently this means its type is either a function, constructor, tester, or selector.
- */
+ /** Is fun a function (or function-like thing)?
+ * Currently this means its type is either a function, constructor, tester, or
+ * selector.
+ */
bool isFunctionLike(api::Term fun);
/** Is the symbol bound to a predicate? */
diff --git a/src/parser/parser_builder.cpp b/src/parser/parser_builder.cpp
index e4f46326f..1f25e00dd 100644
--- a/src/parser/parser_builder.cpp
+++ b/src/parser/parser_builder.cpp
@@ -143,7 +143,8 @@ ParserBuilder& ParserBuilder::withIncludeFile(bool flag) {
return *this;
}
-ParserBuilder& ParserBuilder::withForcedLogic(const std::string& logic) {
+ParserBuilder& ParserBuilder::withForcedLogic(const std::string& logic)
+{
d_logicIsForced = true;
d_forcedLogic = logic;
return *this;
diff --git a/src/parser/smt2/smt2.cpp b/src/parser/smt2/smt2.cpp
index 5961de587..56aebdcf7 100644
--- a/src/parser/smt2/smt2.cpp
+++ b/src/parser/smt2/smt2.cpp
@@ -315,10 +315,7 @@ bool Smt2::isTheoryEnabled(theory::TheoryId theory) const
return d_logic.isTheoryEnabled(theory);
}
-bool Smt2::isHoEnabled() const
-{
- return getLogic().isHigherOrder() && options::getUfHo(d_solver->getOptions());
-}
+bool Smt2::isHoEnabled() const { return d_logic.isHigherOrder(); }
bool Smt2::logicIsSet() {
return d_logicSet;
@@ -505,8 +502,7 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
d_logicSet = true;
d_logic = name;
- // if sygus is enabled, we must enable UF, datatypes, integer arithmetic and
- // higher-order
+ // if sygus is enabled, we must enable UF, datatypes, and integer arithmetic
if(sygus()) {
if (!d_logic.isQuantified())
{
@@ -772,7 +768,7 @@ void Smt2::checkLogicAllowsFunctions()
parseError(
"Functions (of non-zero arity) cannot "
"be declared in logic "
- + d_logic.getLogicString() + " unless option --uf-ho is used");
+ + d_logic.getLogicString() + ". Try adding the prefix HO_.");
}
}
@@ -1012,8 +1008,6 @@ api::Term Smt2::applyParseOp(ParseOp& p, std::vector<api::Term>& args)
}
}
}
- // Second phase: apply the arguments to the parse op
- const Options& opts = d_solver->getOptions();
// handle special cases
if (p.d_kind == api::CONST_ARRAY && !p.d_type.isNull())
{
@@ -1102,17 +1096,17 @@ api::Term Smt2::applyParseOp(ParseOp& p, std::vector<api::Term>& args)
}
else if (isBuiltinOperator)
{
- if (!options::getUfHo(opts)
- && (kind == api::EQUAL || kind == api::DISTINCT))
+ if (!isHoEnabled() && (kind == api::EQUAL || kind == api::DISTINCT))
{
- // need --uf-ho if these operators are applied over function args
+ // need hol if these operators are applied over function args
for (std::vector<api::Term>::iterator i = args.begin(); i != args.end();
++i)
{
if ((*i).getSort().isFunction())
{
parseError(
- "Cannot apply equalty to functions unless --uf-ho is set.");
+ "Cannot apply equalty to functions unless logic is prefixed by "
+ "HO_.");
}
}
}
@@ -1155,9 +1149,11 @@ api::Term Smt2::applyParseOp(ParseOp& p, std::vector<api::Term>& args)
unsigned arity = argt.getFunctionArity();
if (args.size() - 1 < arity)
{
- if (!options::getUfHo(opts))
+ if (!isHoEnabled())
{
- parseError("Cannot partially apply functions unless --uf-ho is set.");
+ parseError(
+ "Cannot partially apply functions unless logic is prefixed by "
+ "HO_.");
}
Debug("parser") << "Partial application of " << args[0];
Debug("parser") << " : #argTypes = " << arity;
diff --git a/src/parser/tptp/Tptp.g b/src/parser/tptp/Tptp.g
index 5f078cab7..c96fbf07d 100644
--- a/src/parser/tptp/Tptp.g
+++ b/src/parser/tptp/Tptp.g
@@ -194,7 +194,11 @@ parseCommand returns [cvc5::Command* cmd = NULL]
cmd = PARSER_STATE->makeAssertCommand(fr, aexpr, /* cnf == */ false, true);
}
) RPAREN_TOK DOT_TOK
- | THF_TOK LPAREN_TOK nameN[name] COMMA_TOK
+ | THF_TOK
+ {
+ PARSER_STATE->setHol();
+ }
+ LPAREN_TOK nameN[name] COMMA_TOK
// Supported THF formulas: either a logic formula or a typing atom (i.e. we
// ignore subtyping and logic sequents). Also, only TH0
( TYPE_TOK COMMA_TOK thfAtomTyping[cmd]
diff --git a/src/parser/tptp/tptp.cpp b/src/parser/tptp/tptp.cpp
index 764e83361..91fcc7a12 100644
--- a/src/parser/tptp/tptp.cpp
+++ b/src/parser/tptp/tptp.cpp
@@ -25,6 +25,7 @@
#include "options/options_public.h"
#include "parser/parser.h"
#include "smt/command.h"
+#include "theory/logic_info.h"
// ANTLR defines these, which is really bad!
#undef true
@@ -37,7 +38,10 @@ Tptp::Tptp(api::Solver* solver,
SymbolManager* sm,
bool strictMode,
bool parseOnly)
- : Parser(solver, sm, strictMode, parseOnly), d_cnf(false), d_fof(false)
+ : Parser(solver, sm, strictMode, parseOnly),
+ d_cnf(false),
+ d_fof(false),
+ d_hol(false)
{
addTheory(Tptp::THEORY_CORE);
@@ -312,21 +316,18 @@ api::Term Tptp::applyParseOp(ParseOp& p, std::vector<api::Term>& args)
isBuiltinKind = true;
}
Assert(kind != api::NULL_EXPR);
- const Options& opts = d_solver->getOptions();
// Second phase: apply parse op to the arguments
if (isBuiltinKind)
{
- if (!options::getUfHo(opts)
- && (kind == api::EQUAL || kind == api::DISTINCT))
+ if (!hol() && (kind == api::EQUAL || kind == api::DISTINCT))
{
- // need --uf-ho if these operators are applied over function args
+ // need hol if these operators are applied over function args
for (std::vector<api::Term>::iterator i = args.begin(); i != args.end();
++i)
{
if ((*i).getSort().isFunction())
{
- parseError(
- "Cannot apply equalty to functions unless --uf-ho is set.");
+ parseError("Cannot apply equalty to functions unless THF.");
}
}
}
@@ -364,9 +365,9 @@ api::Term Tptp::applyParseOp(ParseOp& p, std::vector<api::Term>& args)
unsigned arity = argt.getFunctionArity();
if (args.size() - 1 < arity)
{
- if (!options::getUfHo(opts))
+ if (!hol())
{
- parseError("Cannot partially apply functions unless --uf-ho is set.");
+ parseError("Cannot partially apply functions unless THF.");
}
Debug("parser") << "Partial application of " << args[0];
Debug("parser") << " : #argTypes = " << arity;
@@ -438,6 +439,17 @@ api::Term Tptp::mkDecimal(
return d_solver->mkReal(ss.str());
}
+bool Tptp::hol() const { return d_hol; }
+void Tptp::setHol()
+{
+ if (d_hol)
+ {
+ return;
+ }
+ d_hol = true;
+ d_solver->setLogic("HO_UF");
+}
+
void Tptp::forceLogic(const std::string& logic)
{
Parser::forceLogic(logic);
diff --git a/src/parser/tptp/tptp.h b/src/parser/tptp/tptp.h
index 964c0bdfb..258394486 100644
--- a/src/parser/tptp/tptp.h
+++ b/src/parser/tptp/tptp.h
@@ -47,6 +47,9 @@ class Tptp : public Parser {
bool fof() const { return d_fof; }
void setFof(bool fof) { d_fof = fof; }
+ bool hol() const;
+ void setHol();
+
void forceLogic(const std::string& logic) override;
void addFreeVar(api::Term var);
@@ -209,6 +212,7 @@ class Tptp : public Parser {
bool d_cnf; // in a cnf formula
bool d_fof; // in an fof formula
+ bool d_hol; // in a thf formula
};/* class Tptp */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback