From 691abe521ea8a7e87db51e22880cf101d59bf3e7 Mon Sep 17 00:00:00 2001 From: Andrew Reynolds Date: Wed, 6 Dec 2017 20:57:44 -0600 Subject: Add command for define-fun-rec and add to API (#1412) --- src/parser/smt2/Smt2.g | 48 +++++++++--------------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) (limited to 'src/parser/smt2/Smt2.g') diff --git a/src/parser/smt2/Smt2.g b/src/parser/smt2/Smt2.g index 5351bae15..1135d6dd4 100644 --- a/src/parser/smt2/Smt2.g +++ b/src/parser/smt2/Smt2.g @@ -1151,10 +1151,10 @@ smt25Command[std::unique_ptr* cmd] SExpr sexpr; Type t; Expr func; - Expr func_app; std::vector bvs; std::vector< std::vector > > sortedVarNamesList; std::vector> flattenVarsList; + std::vector> formals; std::vector funcs; std::vector func_defs; Expr aexpr; @@ -1198,41 +1198,24 @@ smt25Command[std::unique_ptr* cmd] PARSER_STATE->resetAssertions(); } | DEFINE_FUN_REC_TOK - { PARSER_STATE->checkThatLogicIsSet(); - seq.reset(new CVC4::CommandSequence()); - } + { PARSER_STATE->checkThatLogicIsSet(); } symbol[fname,CHECK_NONE,SYM_VARIABLE] { PARSER_STATE->checkUserSymbol(fname); } LPAREN_TOK sortedVarList[sortedVarNames] RPAREN_TOK sortSymbol[t,CHECK_DECLARED] { func = PARSER_STATE->mkDefineFunRec(fname, sortedVarNames, t, flattenVars); - seq->addCommand(new DeclareFunctionCommand(fname, func, t)); - PARSER_STATE->pushDefineFunRecScope(sortedVarNames, func, flattenVars, func_app, bvs, true ); + PARSER_STATE->pushDefineFunRecScope(sortedVarNames, func, flattenVars, bvs, true ); } term[expr, expr2] { PARSER_STATE->popScope(); if( !flattenVars.empty() ){ expr = PARSER_STATE->mkHoApply( expr, flattenVars ); } - Expr as = MK_EXPR( kind::EQUAL, func_app, expr); - if( !bvs.empty() ){ - std::string attr_name("fun-def"); - aexpr = MK_EXPR(kind::INST_ATTRIBUTE, func_app); - aexpr = MK_EXPR(kind::INST_PATTERN_LIST, aexpr); - //set the attribute to denote this is a function definition - seq->addCommand( new SetUserAttributeCommand( attr_name, func_app ) ); - //assert it - Expr boundVars = EXPR_MANAGER->mkExpr(kind::BOUND_VAR_LIST, bvs); - as = EXPR_MANAGER->mkExpr(kind::FORALL, boundVars, as, aexpr); - } - seq->addCommand( new AssertCommand(as, false) ); - cmd->reset(seq.release()); + cmd->reset(new DefineFunctionRecCommand(func,bvs,expr)); } | DEFINE_FUNS_REC_TOK - { PARSER_STATE->checkThatLogicIsSet(); - seq.reset(new CVC4::CommandSequence()); - } + { PARSER_STATE->checkThatLogicIsSet();} LPAREN_TOK ( LPAREN_TOK symbol[fname,CHECK_UNDECLARED,SYM_VARIABLE] @@ -1242,7 +1225,6 @@ smt25Command[std::unique_ptr* cmd] { flattenVars.clear(); func = PARSER_STATE->mkDefineFunRec( fname, sortedVarNames, t, flattenVars ); - seq->addCommand(new DeclareFunctionCommand(fname, func, t)); funcs.push_back( func ); // add to lists (need to remember for when parsing the bodies) @@ -1265,7 +1247,7 @@ smt25Command[std::unique_ptr* cmd] } bvs.clear(); PARSER_STATE->pushDefineFunRecScope( sortedVarNamesList[0], funcs[0], - flattenVarsList[0], func_app, bvs, true); + flattenVarsList[0], bvs, true); } ( term[expr,expr2] @@ -1275,26 +1257,14 @@ smt25Command[std::unique_ptr* cmd] expr = PARSER_STATE->mkHoApply( expr, flattenVarsList[j] ); } func_defs.push_back( expr ); + formals.push_back(bvs); j++; - Expr as = MK_EXPR( kind::EQUAL, func_app, expr ); - if( !bvs.empty() ){ - std::string attr_name("fun-def"); - aexpr = MK_EXPR(kind::INST_ATTRIBUTE, func_app); - aexpr = MK_EXPR(kind::INST_PATTERN_LIST, aexpr ); - //set the attribute to denote these are function definitions - seq->addCommand( new SetUserAttributeCommand( attr_name, func_app ) ); - //assert it - as = EXPR_MANAGER->mkExpr( kind::FORALL, - EXPR_MANAGER->mkExpr(kind::BOUND_VAR_LIST, bvs), - as, aexpr); - } - seq->addCommand( new AssertCommand(as, false) ); //set up the next scope PARSER_STATE->popScope(); if( func_defs.size()pushDefineFunRecScope( sortedVarNamesList[j], funcs[j], - flattenVarsList[j], func_app, bvs, true); + flattenVarsList[j], bvs, true); } } )+ @@ -1304,7 +1274,7 @@ smt25Command[std::unique_ptr* cmd] "Number of functions defined does not match number listed in " "define-funs-rec")); } - cmd->reset(seq.release()); + cmd->reset( new DefineFunctionRecCommand(funcs,formals,func_defs)); } // CHECK_SAT_ASSUMING still being discussed // GET_UNSAT_ASSUMPTIONS -- cgit v1.2.3