Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Bora.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
| <assoc=right> expr IMPLIES expr # impliesOperator
| <assoc=right> expr XNOR expr # xnorOperator
| term # termExpr;

term
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions python/qpy/truthtable/formula/_parser/generated/BoraParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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


Expand Down
7 changes: 3 additions & 4 deletions tests/python/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)),
Expand Down
8 changes: 4 additions & 4 deletions ts/src/parser/generated/BoraParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down