NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver. BNF parser is built with ANTLR4.
This implementation properly handles grouping (()
) and symbol _
in atom's names.
- Python 3.8+
The Python version has to at least have full type hint support, thus requiring Python 3.8+.
module load python-3.8
If successful, the command python3 --version
should give you:
$ python3 --version
Python 3.8.6
Install Python packages used in this lab by running the following command:
pip3 install -r requirements.txt
or if you want to specify ANTLR4 runtime manually:
pip3 install antlr4-python3-runtime==4.9.3
The main entrance is a python script, not a binary. It is in Shebang style, thus can be executed directly.
Use ./solver -h
command to see the usage:
usage: solver [-h] [-v] -m MODE inputfile
A BNF to CNF converter and DPLL solver.
positional arguments:
inputfile input file path
optional arguments:
-h, --help show this help message and exit
-v, --verbose verbose output
-m MODE, --mode MODE solver mode, should be one of "cnf", "dpll" or
"solver"
Examples:
$ ./solver -m cnf input.txt
$ ./solver -m dpll -v input.txt
$ ./solver -m solver -v input.txt
project
├─solving solving python module
│ ├─bnf_parser BNF parser python module
│ │ ├─__init__.py Module initialization
│ │ ├─bnf_listener.py BNF parser tree walk listener
│ │ ├─bnf_node.py BNF parser output custom tree node
│ │ ├─bnf_tree.py Function to call parser and generate tree
│ │ ├─BNFLexer.py BNF lexer generated by ANTLR4
│ │ └─BNFParser.py BNF parser generated by ANTLR4
│ │
│ ├─__init__.py Module initialization
│ ├─bnf.py Text/CNF converter and BNF to CNF converter
│ └─dpll.py DPLL solver
│
├─solver Main entrance python script (shebang style)
├─requirements.txt Python packages used in this project
└─README.md The file you're reading