diff --git a/Bora.g4 b/Bora.g4 index f8f62d5..3af4078 100644 --- a/Bora.g4 +++ b/Bora.g4 @@ -9,8 +9,8 @@ expr | expr OR expr # orOperator | expr NOR expr # norOperator | expr XOR expr # xorOperator - | expr IMPLIES expr # impliesOperator - | expr XNOR expr # xnorOperator + | expr IMPLIES expr # impliesOperator + | expr XNOR expr # xnorOperator | term # termExpr; term diff --git a/README.md b/README.md index 9d8627b..def23a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # TruthTables -The package strictly\* follows the operator precedence found +The package strictly follows the operator precedence found [here](http://intrologic.stanford.edu/dictionary/operator_precedence.html). ## Development @@ -19,8 +19,6 @@ the parser code for both TypeScript and Python with `npm run antlr`. With `python -m python.qpy.truthtable.formula._parser` you can test the parser. ### TODO -- [ ] \* Currently, `p => q => r` gets parsed to `((p => q) => r)` and not `(p => (q => r))`. The same is true for the -equivalent-operator. - [ ] Generate random but good and valid formulas. - [ ] Restricting formula input fields to a set of allowed operations / symbols. (Whitelist, blacklist or both?) - [ ] Remove / reorder intermediate formula columns. diff --git a/python/qpy/truthtable/formula/_parser/generated/BoraParser.py b/python/qpy/truthtable/formula/_parser/generated/BoraParser.py index 8dde621..a6b4d55 100644 --- a/python/qpy/truthtable/formula/_parser/generated/BoraParser.py +++ b/python/qpy/truthtable/formula/_parser/generated/BoraParser.py @@ -21,7 +21,7 @@ def serializedATN(): 5,8,0,0,19,36,3,2,1,8,20,21,10,6,0,0,21,22,5,5,0,0,22,36,3,2,1,7, 23,24,10,5,0,0,24,25,5,7,0,0,25,36,3,2,1,6,26,27,10,4,0,0,27,28, 5,9,0,0,28,36,3,2,1,5,29,30,10,3,0,0,30,31,5,11,0,0,31,36,3,2,1, - 4,32,33,10,2,0,0,33,34,5,10,0,0,34,36,3,2,1,3,35,14,1,0,0,0,35,17, + 3,32,33,10,2,0,0,33,34,5,10,0,0,34,36,3,2,1,2,35,14,1,0,0,0,35,17, 1,0,0,0,35,20,1,0,0,0,35,23,1,0,0,0,35,26,1,0,0,0,35,29,1,0,0,0, 35,32,1,0,0,0,36,39,1,0,0,0,37,35,1,0,0,0,37,38,1,0,0,0,38,3,1,0, 0,0,39,37,1,0,0,0,40,41,6,2,-1,0,41,42,3,6,3,0,42,47,1,0,0,0,43, @@ -420,7 +420,7 @@ def expr(self, _p:int=0): self.state = 30 self.match(BoraParser.IMPLIES) self.state = 31 - self.expr(4) + self.expr(3) pass elif la_ == 7: @@ -433,7 +433,7 @@ def expr(self, _p:int=0): self.state = 33 self.match(BoraParser.XNOR) self.state = 34 - self.expr(3) + self.expr(2) pass diff --git a/tests/python/test_parser.py b/tests/python/test_parser.py index 1dba64a..8eddf57 100644 --- a/tests/python/test_parser.py +++ b/tests/python/test_parser.py @@ -11,7 +11,7 @@ @pytest.fixture(autouse=True) -def check_eval(): +def check_eval_not_called(): with patch("builtins.eval") as mock_eval: yield mock_eval.assert_not_called() @@ -29,9 +29,8 @@ def check_eval(): ("x<->y->z", Equivalent(x, Implies(y, z))), ("xyz", And(And(x, y), z)), ("x+y+z", Or(Or(x, y), z)), - # TODO: right association - #("x->y->z", Implies(x, Implies(y, z))), - #("x<->y<->z", Equivalent(x, Equivalent(y, z))), + ("x->y->z", Implies(x, Implies(y, z))), + ("x<->y<->z", Equivalent(x, Equivalent(y, z))), ("xy->z", Implies(And(x, y), z)), ("x->yz", Implies(x, And(y, z))), ("x+y->z", Implies(Or(x, y), z)), diff --git a/ts/src/parser/generated/BoraParser.ts b/ts/src/parser/generated/BoraParser.ts index ea7064d..7fbffe2 100644 --- a/ts/src/parser/generated/BoraParser.ts +++ b/ts/src/parser/generated/BoraParser.ts @@ -226,7 +226,7 @@ export default class BoraParser extends Parser { this.state = 30; this.match(BoraParser.IMPLIES); this.state = 31; - this.expr(4); + this.expr(3); } break; case 7: @@ -240,7 +240,7 @@ export default class BoraParser extends Parser { this.state = 33; this.match(BoraParser.XNOR); this.state = 34; - this.expr(3); + this.expr(2); } break; } @@ -455,8 +455,8 @@ export default class BoraParser extends Parser { 0,14,15,10,8,0,0,15,16,5,4,0,0,16,36,3,2,1,9,17,18,10,7,0,0,18,19,5,8,0, 0,19,36,3,2,1,8,20,21,10,6,0,0,21,22,5,5,0,0,22,36,3,2,1,7,23,24,10,5,0, 0,24,25,5,7,0,0,25,36,3,2,1,6,26,27,10,4,0,0,27,28,5,9,0,0,28,36,3,2,1, - 5,29,30,10,3,0,0,30,31,5,11,0,0,31,36,3,2,1,4,32,33,10,2,0,0,33,34,5,10, - 0,0,34,36,3,2,1,3,35,14,1,0,0,0,35,17,1,0,0,0,35,20,1,0,0,0,35,23,1,0,0, + 5,29,30,10,3,0,0,30,31,5,11,0,0,31,36,3,2,1,3,32,33,10,2,0,0,33,34,5,10, + 0,0,34,36,3,2,1,2,35,14,1,0,0,0,35,17,1,0,0,0,35,20,1,0,0,0,35,23,1,0,0, 0,35,26,1,0,0,0,35,29,1,0,0,0,35,32,1,0,0,0,36,39,1,0,0,0,37,35,1,0,0,0, 37,38,1,0,0,0,38,3,1,0,0,0,39,37,1,0,0,0,40,41,6,2,-1,0,41,42,3,6,3,0,42, 47,1,0,0,0,43,44,10,1,0,0,44,46,3,4,2,2,45,43,1,0,0,0,46,49,1,0,0,0,47,