This is a cross-platform library for parsing boolean arithmetic expressions like
a && b && (!c || !d) and evaluating them by assigning values to the variables.
Boolean expressions are parsed into an abstract syntax tree (AST) using a lexer/parser generated by various Lex/Yacc clones for the various programming languages. This allows grammars to be fairly similar across languages.
Evaluation of the boolean expressions is done by traversing the AST with a visitor. (This is obviously overkill for something as simple as boolean expressions, keep reading to understand why).
The purpose of this library is twofold.
First, it serves as a simple example of how to build a custom interpreted language with a fast lexer/parser that build a visitor-traversable AST, and that runs on many different platforms. People who want to build a bigger cross-platform language could leverage the structure and build files in this project. A new Gherkin 3.0 project may use this project as a template.
Second, this project actually has a use. The Cucumber project may use it to evaluate tag expressions as current Cucumber implementations don't have a proper parser for this.
Building for all platforms
If you're lucky and already have all the needed software installed you can just run
If that fails for you (it probably will the first time), don't worry. Follow the OS-specific instructions below and try again. If you still run into problems, see the relevant READMEs in the sub directories.
If you don't already have Bison 2.7 installed then the top level
Makefile will install it into
OS X ships with an old Bison we can't use. If you prefer to install Bison 2.7 with Homebrew instead of under
then you must first install Homebrew-Dupes
before you can install Bison and the other requirements:
brew tap homebrew/dupes brew install bison flex wget node
Ubuntu users can install the needed software with:
sudo apt-get install bison flex wget node mingw32
At the time of this writing,
apt-get will install Bison 2.5, which is too old, so the
Makefile will install
apt-get installs Bison 2.7 some day in the future this step will be skipped.
Fedora 18 can install the needed software with:
yum install bison flex wget node mingw32-gcc