How to use a BAPA Z3 theory plugin? - z3

I'm trying to run this Boolean Algebra with Presburger Arithmetic Plug-In for the Z3 solver. I installed Z3 and ScalaZ3 and sbt test runs fine.
However, I have no idea how to put it all together.
All I could find in the (old) Z3 documentation was the examples section, which does not help at all.
I know the plug-in interface is deprecated, but I just want to run that plug-in (using an old Z3 version is OK).
How do I get Z3 to use the plug-in through the ScalaZ3 interface and how do I input the constraints in? (examples are given in bapaZ3/bapa-z3-master/src/main/scala/bapa/)
When I try
java -jar scalaz3_2.10-2.1.jar
I just get
no main manifest attribute, in scalaz3_2.10-2.1.jar
Thanks.

Related

Getting the typed syntax tree from dart2js or dart-analyzer

I'd like to derive exactly that subset of the sources of a dart comiler (dart2js or dartdevc or other) or of a dart analyser that can 1. transform a string of dart code (or better a list of strings each representing a compilation unit) into a typed syntax tree, 2. be translated into js, 3. be run in the browser. Is there a marked subset that fulfills these requirements, which is it, and how can I find it, in general.
Accomplishing #1 is fairly simple using package:analyzer, which is the same static analyzer used to provide IDE hinting and autocomplete, etc. The Dart Team is currently working on unifying their compiler frontends behind on main API, but for now, analyzer should definitely take care of most of what you need.
Here's an example of getting a syntax tree and running analysis on it: https://github.com/thosakwe/analyzer_examples/blob/master/analyze_a_file/analyze_a_file.dart
As for #2, you'll likely have to fork the dart-lang/sdk repo and make your own adjustments to dart2js. It's not published as a standalone package. Otherwise, you can write your own compiler, which is probably not going be fun.
I suppose you'd have to figure out how to get #2 up and running, but hypothetically, if you could compile a JavaScript source, you could just eval it after compilation.
To answer your final question, no, AFAIK, there is no subset of dart2js available that lets you create your own Dart-to-JavaScript compiler.

Z3-str/Z3str2: can it be used in conjunction with the rest of Z3?

We need a string-solver and are considering Z3-str or its successor Z3str2. Can these extensions simultaneously be used in conjunction with all the rest of Z3 (i.e. all other theory solvers implemented in Z3)? Or are these string-extensions only usable quasi standalone?
I don't think so, no. Trying to declare a real using Z3-str gives an error. It seems that only strings and ints are supported.
There are other things to consider before using Z3-str as well. It seems to require a slightly different, non SMT-LIB v2 compliant input format. There are example files provided in Z3-str/tests/. They use, for example declare-variable to declare variables rather than declare-const or declare-fun.
There's also some ambiguity in the project about the difference between Z3-str and Z3-str2. Specifically, if you go to the GitHub page then Z3-str2.py is referenced in the build instructions, but there is no such file in the repo, only Z3-str.py. I think what is on the GitHub page is nonetheless the most recent version, because there are commits from Feb 2016.
Finally, Z3-str apparently uses a deprecated API, so you have to use an old version of Z3. So you might not want to build a new project around Z3-str unless you can deal with using Z3 4.1.1 (October 2012).
You are lucky: Z3 currently natively support strings.
Of course, strings can be combined with all other theories.

z3 solver: z3-SMT on Mac platform

I need to work on Z3 SMT solver for my Master Thesis. I have already check the tutorials for Z3-SMT which is based on SMT-Lib input. But I could only install z3-Py which needs the knowledge of Python. I wanted to know if there is a possibility to install z3 using SMT front end on Mac OSX. If yes, can you please help to do that?
The simplest way to run SMT-LIB scripts is to use the rise4fun interface: http://rise4fun.com/Z3
That said, you may need to run Z3 offline for large problems or in other programs. It sounds like you've already installed Z3 since you have z3py working. If you have succeeded in installing z3py, then you can also run Z3, as z3py depends on Z3 (technically a z3 library, but you probably have both the library and the executable installed if you got the source from codeplex and compiled it). For compilation and installation instructions for all platforms see: https://z3.codeplex.com/SourceControl/latest#README
Once installed, you can execute the z3 executable on an SMT-LIB2 file called test.smt using ./z3 -smt2 test.smt (or just z3 -smt2 test.smt if you put it on the path).

z3 MaxSAT example error

I'm interested in playing around with the MaxSAT/MaxSMT c example (specifically, maxsat.c) provided on the z3 (Microsoft Research) website. Using Visual Studio 2010, I eventually got the example to compile (using a fresh install of z3 4.0). However, I can't get any of my (SMT 2.0) models to run using them. Further, I cannot get the example posted in this question to work either.
In the first case, my compiled program crashes when it tries to call Z3_get_smtlib_num_formulas in get_hard_constraints of the file. I don't know why, instead, I get the standard windows 7 "this program has stopped working" popup.
In the second case, it reports unsupported ;benchmark.
In order to help me to get this work, I was wondering if
(a) Has anyone had similar issues when compiling this code, and if so, how did you resolve them?
or
(b) How can I debug either compilation of the file (assuming it is correct)? Namely, can someone enumerate the correct libraries (and library versions - e.g., z3 4.0?) to include in the compiler options to get this example working?
In either case, information on the error reported in the second case would also be appreciated: what does it mean exactly? The keyword was not valid? That the SMT input is the wrong version? Or something else?
Thanks.
The MaxSAT example has not been updated to SMTLIB 2.0 yet. It uses the function Z3_parse_smtlib_file to parse the input, which means that it supports only SMTLIB 1.0 at the moment.
This example is distributed alongside Z3, i.e., you should have received a copy in Z3-4.0/examples/maxsat/, which also contains compilation and execution scripts.
Compilation should be straight-forward by running build.cmd in a Visual Studio Command Prompt, or build.sh on Linux.

Any tools for clojure to parse java source code? [duplicate]

I'm trying to analyze Java source files with Clojure but I couldn't find a way to do that.
First, I thought using Eclipse AST plugin(by copying necessary JAR's to my Clojure project) but I gave up after seeing Eclipse AST's API(visitor based walker).
Then I've tried creating a Java parser with ANTLR. I can only find one Java 1.6 grammar for ANTLR( http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g ) and it doesn't compile with latest ANTLR(here's the errors I'm getting ).
Now I have no idea how can I do that. At worst I'll try to go with Eclipse AST.
Does anyone know a better way to parse Java files with Clojure?
Thanks.
Edit: To clarify my point:
I need to find some specific method calls in Java projects and inspect it's parameters(we have multiple definitions of the method, with different type of parameters). Right now I have a simple solution written in Java(Eclipse AST) but I want to use Clojure in this project as much as possible.
... and it doesn't compile with latest ANTLR ...
I could not reproduce that.
Using ANTLR v3.2, I got some warnings, but no errors. Using both ANTLR v3.3 and v3.4 (latest version), I have no problems generating a parser.
You didn't mention how you're (trying) to generate a lexer/parser, but here's how it works for me:
java -cp antlr-3.4.jar org.antlr.Tool Java.g
EDIT 1
Here's my output when running the commands:
ls
wget http://www.antlr.org/download/antlr-3.4-complete.jar
wget http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g
java -cp antlr-3.4-complete.jar org.antlr.Tool Java.g
ls
As you can see, the .java files of the lexer and parser are properly created.
EDIT 2
Instead of generating a parser yourself (from a grammar), you could use an existing parser like this one (Java 1.5 only AFAIK) and call it from your Clojure code.
It depends a bit on what you want to do - what are you hoping to get from the analysis?
If you want to actually compile Java or at least build an AST, then you probably need to go the ANTLR or Eclipse AST route. Java isn't that bad of a language to parse, but you still probably don't want to be reinventing too many wheels..... so you might as well build on the Eclipse and OpenJDK work.
If however you are just interesting in parsing the basic syntax and analysing certain features, it might be easier to use a simpler general purpose parser combinator library. Options to explore:
fnparse (Clojure, not sure how well maintained)
jparsec (Java, but can probably be used quite easily from Clojure)

Resources