def decl_const_or_fun(definition): if isinstance(definition, Sort): fargs_sorts = definition.arg_sorts if len(fargs_sorts) == 0: return sast.Command("declare-const", [definition.name, sp.sort_of(definition)]) else: return sast.Command("declare-fun", [definition.name, [sp.sort_of(x) for x in fargs_sorts], sp.sort_of(definition)]) else: logger.error("decl_constant_or_fun called on %s" % str(definition)) raise TypeError("%s is not supported." % str(definition))
def p_define_functions_rec(p): '''command : LPAR DEFFUNSREC LPAR function_def_list RPAR LPAR term_list RPAR RPAR''' if len(p[4]) != len(p[7]): raise Exception( "Function definition: provide as many terms as functions definition." ) p[0] = ast.Command(p[2], [p[4], p[7]])
def smtlib_string(ast : list, funcs, extra_consts="" ,extra_asserts = ""): funcs = [decl_const_or_fun(definition) for definition in funcs] new_ast = [] before_asserts = True for i in range(len(ast)): c = ast[i] if isinstance(c, BoolFuncApp) or (isinstance(c, Let) and isinstance(c.term, BoolFuncApp)): if before_asserts: before_asserts = False new_ast += funcs new_ast.append(sast.Command("assert", [c])) elif isinstance(c, sast.Command) and c.cname == "assert": if before_asserts: before_asserts = False new_ast += funcs new_ast.append(c) else: new_ast.append(c) smtlib = "\n".join([str(command) for command in new_ast]) logger.info("\n"+smtlib) return extra_consts + smtlib + extra_asserts
def p_checksat_assuming(p): '''command : LPAR CHKSATASSUMING prop_literal_list RPAR''' p[0] = ast.Command(p[2], p[3])
def p_set_logic(p): '''command : LPAR SETLOGIC symbol RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_reset_assertions(p): '''command : LPAR RESETASSERTIONS''' p[0] = ast.Command(p[2], [])
def p_push(p): '''command : LPAR PUSH NUMBER RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_get_value(p): '''command : LPAR GETVAL LPAR term_list RPAR RPAR''' p[0] = ast.Command(p[2], [p[4]])
def p_get_unsat_assumptions(p): '''command : LPAR GETUNSATASSUMPTS RPAR''' p[0] = ast.Command(p[2])
def p_define_function_rec(p): '''command : LPAR DEFFUNREC function_def RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_declare_sort(p): '''command : LPAR DECLSORT symbol NUMBER RPAR''' p[0] = ast.Command(p[2], [p[3], p[4]])
def p_declare_function(p): '''command : LPAR DECLFUN symbol LPAR sortlist RPAR sort RPAR''' p[0] = ast.Command(p[2], [p[3], p[5], p[7]])
def p_declare_datatypes(p): '''command : LPAR DECLDATATYPES LPAR symbollist RPAR LPAR datatype_dec_list RPAR RPAR''' p[0] = ast.Command(p[2], [p[4], p[7]])
def p_declare_datatype(p): '''command : LPAR DECLDATATYPE symbol datatype_dec RPAR''' p[0] = ast.Command(p[2], [p[3], p[4]])
def p_declare_const(p): '''command : LPAR DECLCONST symbol sort RPAR''' p[0] = ast.Command(p[2], [p[3], p[4]])
def p_getoptions(p): '''command : LPAR GETOPT RPAR''' p[0] = ast.Command(p[2], [])
def p_getproof(p): '''command : LPAR GETPRF RPAR''' p[0] = ast.Command(p[2], [])
def p_define_sort(p): '''command : LPAR DEFSORT symbol LPAR symbollist RPAR sort RPAR''' p[0] = ast.Command(p[2], [p[3], p[5], p[7]])
def p_get_unsat_core(p): '''command : LPAR GETUNSATCORE RPAR''' p[0] = ast.Command(p[2], [])
def p_echo(p): '''command : LPAR ECHO STRING RPAR''' p[0] = ast.Command(p[2], p[3])
def p_pop(p): '''command : LPAR POP NUMBER RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_exit(p): '''command : LPAR EXIT RPAR''' p[0] = ast.Command(p[2], [])
def p_reset(p): '''command : LPAR RESET RPAR''' p[0] = ast.Command(p[2])
def p_geassertions(p): '''command : LPAR GETASSERTIONS RPAR''' p[0] = ast.Command(p[2], [])
def p_set_info(p): '''command : LPAR SETINFO attribute RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_getassignment(p): '''command : LPAR GETASSIGNMENT RPAR''' p[0] = ast.Command(p[2], [])
def p_set_option(p): '''command : LPAR SETOPT option RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_getinfo(p): '''command : LPAR GETINF info_flag RPAR''' p[0] = ast.Command(p[2], [p[3]])
def p_getmodel(p): '''command : LPAR GETMOD RPAR''' p[0] = ast.Command(p[2], [])
def p_checksat(p): '''command : LPAR CHKSAT RPAR''' p[0] = ast.Command(p[2], [])