pyCFG is an application and library for working with context free grammars (CFG) in Python. It uses tkinter for it's graphical interface.
$ python pycfg.py
You can download pyCFG's binary for windows from Here.
pyCFG library is in cfg.py
module and can be imported and be used easily. For example:
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.
If you want to test, make sure that pytest
is installed, then run:
pytest test.py
Hamidreza Mahdavipanah
- Lucas Seiki Oshiro