Zadanie:
Sprawdzić, czy napis jest poprawną formułą rachunku zdań.
logic_formula_checker | ||
README.md | ||
requirements.txt | ||
run.py | ||
tests.py |
Logic formula checker
Script for checking is formula is correct
Installation
You can run this script without downloading any other libraries.
Usage
There are several ways of usage.
- You can use is as a library in your project:
from logic_formula_checker import is_formula_correct
- With run.py for interactive console
- From bash
$ python -m logic_formula_checker -f (a∧b)
Testing
Some tests is written in tests.py file. They check if formula single tests work properly.
Script logic explaination
It takes two test of formula for checking formula's correctness. Firstly check if all brackets are properly opened and closed.
( { } ) - Good
( { ) } - Wrong
( { } - Wrong
Next script checks if signs are rightly put. Brackets are bypassed. Steps:
- Read sign, check what kind it is (Types are in logic_formula_checker/types.py).
- Check if it is in expected_sign list.
- Update expected_sign list base on current sign
a ^ ¬ b # take a, write to expected_sign conjuction symbols and negation symbols
^ ¬ b # take ^, check is it in expected_sign, update expected_sign with asci lowercase sings (formula variables) and negation signs