mirror of
https://github.com/Z3Prover/z3
synced 2025-07-24 05:08:55 +00:00
other components
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
e9eab22e5c
commit
68269c43a6
250 changed files with 70871 additions and 0 deletions
80
test/datalog_parser.cpp
Normal file
80
test/datalog_parser.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include "datalog_parser.h"
|
||||
#include "ast_pp.h"
|
||||
#include "arith_decl_plugin.h"
|
||||
#include "dl_context.h"
|
||||
#include "front_end_params.h"
|
||||
|
||||
using namespace datalog;
|
||||
|
||||
|
||||
static void dparse_string(char const* str) {
|
||||
ast_manager m;
|
||||
front_end_params params;
|
||||
m.register_decl_plugins();
|
||||
|
||||
context ctx(m, params);
|
||||
parser* p = parser::create(ctx,m);
|
||||
|
||||
bool res=p->parse_string(str);
|
||||
|
||||
if (!res) {
|
||||
std::cout << "Parser did not succeed on string\n"<<str<<"\n";
|
||||
SASSERT(false);
|
||||
}
|
||||
#if 0
|
||||
unsigned num_rules = p->get_num_rules();
|
||||
for (unsigned j = 0; j < num_rules; ++j) {
|
||||
rule* r = p->get_rules()[j];
|
||||
std::cout << mk_pp(r->head(), m) << "\n";
|
||||
for (unsigned i = 0; i < r->size(); ++i) {
|
||||
std::cout << "body: " << mk_pp((*r)[i], m) << "\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
dealloc(p);
|
||||
}
|
||||
|
||||
static void dparse_file(char const* file) {
|
||||
ast_manager m;
|
||||
front_end_params params;
|
||||
m.register_decl_plugins();
|
||||
|
||||
context ctx(m, params);
|
||||
parser* p = parser::create(ctx,m);
|
||||
|
||||
if (!p->parse_file(file)) {
|
||||
std::cout << "Failed to parse file\n";
|
||||
}
|
||||
#if 0
|
||||
unsigned num_rules = p->get_num_rules();
|
||||
for (unsigned j = 0; j < num_rules; ++j) {
|
||||
rule* r = p->get_rules()[j];
|
||||
std::cout << mk_pp(r->head(), m) << "\n";
|
||||
for (unsigned i = 0; i < r->size(); ++i) {
|
||||
std::cout << "body: " << mk_pp((*r)[i], m) << "\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
dealloc(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tst_datalog_parser() {
|
||||
dparse_string("\nH :- C1(X,a,b), C2(Y,a,X) .");
|
||||
dparse_string("N 128\n\nH :- C1(X,a,b), C2(Y,a,X) .");
|
||||
dparse_string("N 128\nI 128\n\nC1(x : N, y : N, z : I)\nC2(x : N, y : N, z : N)\nH :- C1(X,a,b), C2(Y,a,X) .");
|
||||
dparse_string("\nH :- C1(X,a,b), nC2(Y,a,X) .");
|
||||
dparse_string("\nH :- C1(X,a,b),nC2(Y,a,X).");
|
||||
dparse_string("\nH :- C1(X,a,b),\\\nC2(Y,a,X).");
|
||||
dparse_string("\nH :- C1(X,a\\,\\b), C2(Y,a,X) .");
|
||||
}
|
||||
|
||||
void tst_datalog_parser_file(char** argv, int argc, int & i) {
|
||||
if (i + 1 < argc) {
|
||||
dparse_file(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue