Handling as many variables as you want, with all elementary operations available.
This project contains the Lexer, the Parser and the Interpreter for it to work properly, all made from scratch for this purpose only.
You can run the given compiled file with java -jar TruthTable.jar
, you will then be able to write your expressions and get the corresponding truth table.
Quicker, you can run the given compiled file and give your expression as an argument and get the corresponding truth table directly, for exemple, java -jar TruthTable.jar p->!q
will result in the truth table corresponding to "If p then not q".
This section will go trough every available operation in this project, their syntax and their corresponding truth table.
Priorities are respected during the parsing, following the conventional rules.
For a given proposition p, "not p" has the opposite truth table. "Not p" is written here either as !p
or ¬p
.
p | !p |
---|---|
T | F |
F | T |
For given propositions p and q, "p and q" is true only if both p and q are true, and is false otherwise. "p and q" is written here either as p & q
or p ∧ q
.
p | q | p&q |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | F |
For given propositions p and q, "p or q" is true when at least one of p or q is true. "p or q" is written here either as p | q
or p ∨ q
.
p | q | p&q |
---|---|---|
T | T | T |
T | F | T |
F | T | T |
F | F | F |
For given propositions p and q, "p xor q" is true when p and q have different truth values. "p xor q" is written here either as p + q
or p ⊕ q
.
p | q | p&q |
---|---|---|
T | T | F |
T | F | T |
F | T | T |
F | F | F |
For given propositions p and q, "if p then q" is false only if p is true and q is false, and is true otherwise. "if p then q" is written here either as p -> q
or p → q
.
p | q | p -> q |
---|---|---|
T | T | T |
T | F | F |
F | T | T |
F | F | T |
For given propositions p and q, "p if and only if q" is true when p and q have the same truth value. "p if and only if q" is written here either as p <-> q
or p ↔ q
.
p | q | p <-> q |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | T |