Aunsiels / pyformlang

A python library to manipulate formal languages and various automata
https://pypi.org/project/pyformlang/
MIT License
43 stars 10 forks source link

Bug with CNF #5

Closed Yakonick closed 3 years ago

Yakonick commented 3 years ago

Hello! I found some problem with CNF. After translating my CNF grammar to text I tried to read it from text again, but got another grammar...

cfg = CFG.from_text("S -> a S b | a b") cnf = cfg.to_normal_form() cnf.contains([Terminal("a"),Terminal("b")]) True new_text = cnf.to_text() new_cnf = CFG.from_text(new_text) new_cnf.contains([Terminal("a"), Terminal("b")]) False

Can you fix this please?

P.S. I think it might be happening because of wrong translation of variables (creating variables with lowercase first letter from terminals (a#CNF# -> Terminal(a))

Aunsiels commented 3 years ago

Thank you for your feedback! I updated the representation of CFG to introduce explicit types. It should work now.