Skip to content

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

License

Notifications You must be signed in to change notification settings

mahdavipanah/pyCFG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyCFG is an application and library for working with context free grammars (CFG) in Python. It uses tkinter for it's graphical interface.

pyCFG app screenshot

Installing application

Prerequisites

Running

$ python pycfg.py

Windows

You can download pyCFG's binary for windows from Here.

Using library

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.

Tests

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

pytest test.py

Author

Hamidreza Mahdavipanah

Contributors

  • Lucas Seiki Oshiro

License

MIT