def fill_values(formula): """returns genexp with the all fillings with 0 and 1""" letters = "".join(set(re.findall("[A-Za-z]", formula))) for digits in product("10", repeat=len(letters)): table = str.maketrans(letters, "".join(digits)) yield formula.translate(table)
It uses some Python features (that's why I like to use it, not for its efficiency, but because lots of libraries to quick get things done). The whole thing works something like that (asciinema screenacast):
https://asciinema.org/a/TarY4YQQTbm3To5ZpBXTci3Y4?t=8
Still lacks error handling, checks if a formula is syntactically correct. For example, it does this:
$ ./eval.py Propositional Logic Parser, press help, /h, -h or -usage for help > q ~ a Formula is satisfiable
I would like anybody doing some logic exercises, to try it out, or just for fun, that certainly will help:).
Code on Github . Out of the box here:
https://repl.it/@lion137/propositionalcalculluseval
Thanks for patience, bye for now:)