Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mahdavipanah/pycfg

Context Free Grammar(CFG) parser library and application written in Python.
https://github.com/mahdavipanah/pycfg

algorithm automata cfg python tkinter

Last synced: 25 days ago
JSON representation

Context Free Grammar(CFG) parser library and application written in Python.

Awesome Lists containing this project

README

        

pyCFG is an application and library for working with context free grammars (CFG) in [Python](https://www.python.org/).
It uses [tkinter](https://wiki.python.org/moin/TkInter) for it's graphical interface.


pyCFG app screenshot

## Installing application

### Prerequisites
- [Python3.5+](https://www.python.org/)
- [tkinter](https://wiki.python.org/moin/TkInter)

### Running

```bash
$ python pycfg.py
```

### Windows

You can download pyCFG's binary for windows from [Here](https://github.com/mahdavipanah/pyCFG/releases).

## Using library
pyCFG library is in `cfg.py` module and can be imported and be used easily. For example:
```Python
from cfg import CFG

g = CFG(terminals={'a', 'b', 'c', 'λ'},
rules={'S': ['aSa', 'bSb', 'cSc', 'λ']}
)

string = input("Enter a string: ")

if g.cyk(string):
print("Grammar can generate the string!")
else:
print("Grammar cannot generate the string!")
```
Above program gets a string from input and tells if the defined grammer can generate the string or not.

## Tests

If you want to test, make sure that `pytest` is installed, then run:

~~~bash
pytest test.py
~~~

## Author

Hamidreza Mahdavipanah

### Contributors

- Lucas Seiki Oshiro

## License

[MIT](./LICENSE)