Parser 
This example shows how to use the parser via the parser API.
 1/******************************************************************************
 2 * Top contributors (to current version):
 3 *   Andrew Reynolds
 4 *
 5 * This file is part of the cvc5 project.
 6 *
 7 * Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
 8 * in the top-level source directory and their institutional affiliations.
 9 * All rights reserved.  See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
12 *
13 * A simple demonstration of using the parser via C++ API.
14 */
15
16#include <cvc5/cvc5.h>
17#include <cvc5/cvc5_parser.h>
18
19#include <iostream>
20
21using namespace cvc5;
22using namespace cvc5::parser;
23
24int main()
25{
26  Solver slv;
27
28  // set that we should print success after each successful command
29  slv.setOption("print-success", "true");
30
31  // construct an input parser associated the solver above
32  InputParser parser(&slv);
33
34  std::stringstream ss;
35  ss << "(set-logic QF_LIA)" << std::endl;
36  ss << "(declare-fun a () Int)" << std::endl;
37  ss << "(declare-fun b () Int)" << std::endl;
38  ss << "(declare-fun c () Int)" << std::endl;
39  ss << "(assert (> a (+ b c)))" << std::endl;
40  ss << "(assert (< a b))" << std::endl;
41  ss << "(assert (> c 0))" << std::endl;
42  parser.setStreamInput(modes::InputLanguage::SMT_LIB_2_6, ss, "MyStream");
43
44  // get the symbol manager of the parser, used when invoking commands below
45  SymbolManager* sm = parser.getSymbolManager();
46
47  // parse commands until finished
48  Command cmd;
49  while (true)
50  {
51    cmd = parser.nextCommand();
52    if (cmd.isNull())
53    {
54      break;
55    }
56    std::cout << "Executing command " << cmd << ":" << std::endl;
57    // invoke the command on the solver and the symbol manager, print the result
58    // to std::cout
59    cmd.invoke(&slv, sm, std::cout);
60  }
61  std::cout << "Finished parsing commands" << std::endl;
62
63  // now, check sat with the solver
64  Result r = slv.checkSat();
65  std::cout << "expected: unsat" << std::endl;
66  std::cout << "result: " << r << std::endl;
67}
             1/******************************************************************************
 2 * Top contributors (to current version):
 3 *   Andrew Reynolds
 4 *
 5 * This file is part of the cvc5 project.
 6 *
 7 * Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
 8 * in the top-level source directory and their institutional affiliations.
 9 * All rights reserved.  See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
12 *
13 * A simple demonstration of using the parser via Java API.
14 */
15
16import io.github.cvc5.*;
17import io.github.cvc5.modes.*;
18public class Parser
19{
20  public static void main(String args[]) throws CVC5ApiException
21  {
22    Solver slv = new Solver();
23
24    // set that we should print success after each successful command
25    slv.setOption("print-success", "true");
26
27    // construct an input parser associated the solver above
28    InputParser parser = new InputParser(slv);
29
30    String ss = "";
31    ss += "(set-logic QF_LIA)\n";
32    ss += "(declare-fun a () Int)\n";
33    ss += "(declare-fun b () Int)\n";
34    ss += "(declare-fun c () Int)\n";
35    ss += "(assert (> a (+ b c)))\n";
36    ss += "(assert (< a b))\n";
37    ss += "(assert (> c 0))\n";
38    parser.setStringInput(InputLanguage.SMT_LIB_2_6, ss, "MyStream");
39
40    // get the symbol manager of the parser, used when invoking commands below
41    SymbolManager sm = parser.getSymbolManager();
42
43    // parse commands until finished
44    Command cmd;
45    while (true)
46    {
47      cmd = parser.nextCommand();
48      if (cmd.isNull())
49      {
50        break;
51      }
52      System.out.println("Executing command " + cmd + ":");
53      // invoke the command on the solver and the symbol manager, print the result
54      // to standard output
55      System.out.println(cmd.invoke(slv, sm));
56    }
57    System.out.println("Finished parsing commands");
58
59    // now, check sat with the solver
60    Result r = slv.checkSat();
61    System.out.println("expected: unsat");
62    System.out.println("result: " + r);
63  }
64}
             1#!/usr/bin/env python
 2###############################################################################
 3# Top contributors (to current version):
 4#   Daniel Larraz
 5#
 6# This file is part of the cvc5 project.
 7#
 8# Copyright (c) 2009-2023 by the authors listed in the file AUTHORS
 9# in the top-level source directory and their institutional affiliations.
10# All rights reserved.  See the file COPYING in the top-level source
11# directory for licensing information.
12# #############################################################################
13#
14# A simple demonstration of using the parser via Python API
15##
16
17import cvc5
18
19if __name__ == "__main__":
20    slv = cvc5.Solver()
21
22    # set that we should print success after each successful command
23    slv.setOption("print-success", "true")
24
25    # construct an input parser associated the solver above
26    parser = cvc5.InputParser(slv)
27
28    input = """
29        (set-logic QF_LIA)
30        (declare-fun a () Int)
31        (declare-fun b () Int)
32        (declare-fun c () Int)
33        (assert (> a (+ b c)))
34        (assert (< a b))
35        (assert (> c 0))
36    """
37    
38    parser.setStringInput(cvc5.InputLanguage.SMT_LIB_2_6, input, "MyInput")
39
40    # get the symbol manager of the parser, used when invoking commands below
41    sm = parser.getSymbolManager()
42
43    # parse commands until finished
44    while True:
45        cmd = parser.nextCommand()
46        if cmd.isNull():
47            break
48        print(f"Executing command {cmd}:")
49        # invoke the command on the solver and the symbol manager, print the result
50        print(cmd.invoke(slv, sm), end="")
51
52    print("Finished parsing commands")
53
54    # now, check sat with the solver
55    r = slv.checkSat()
56    print("expected: unsat")
57    print(f"result: {r}")
            examples/api/smtlib/parser.smt2
1(set-logic QF_LIA)
2(declare-fun a () Int)
3(declare-fun b () Int)
4(declare-fun c () Int)
5(assert (> a (+ b c)))
6(assert (< a b))
7(assert (> c 0))
8(check-sat)