Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dizys/nyu-ai-lab-2

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver
https://github.com/dizys/nyu-ai-lab-2

antlr4 bnf-parser bnf-to-cnf dpll-solver python

Last synced: 14 days ago
JSON representation

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver

Awesome Lists containing this project

README

        

# nyu-ai-lab-2

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver. BNF parser is built with [ANTLR4](https://github.com/dizys/nyu-ai-lab-2/tree/main/antlr).

This implementation properly handles grouping (`()`) and symbol `_` in atom's names.

## Prerequisite

- Python 3.8+

## Getting-started

### Switch to Python 3.8 on CIMS machines

The Python version has to at least have full type hint support, thus requiring Python 3.8+.

```bash
module load python-3.8
```

If successful, the command `python3 --version` should give you:

```bash
$ python3 --version
Python 3.8.6
```

### Install dependencies/packages

Install Python packages used in this lab by running the following command:

```bash
pip3 install -r requirements.txt
```

or if you want to specify ANTLR4 runtime manually:

```bash
pip3 install antlr4-python3-runtime==4.9.3
```

### Script usages

> 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:

```bash
$ ./solver -m cnf input.txt
```

```bash
$ ./solver -m dpll -v input.txt
```

```bash
$ ./solver -m solver -v input.txt
```

## Project structure

```
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
```