A C++ interpreter for propositional logic expressions that lexes, parses, and evaluates boolean equations using recursive descent parsing.
- Lexical Analysis: Tokenizes propositional logic expressions
- Syntax Analysis: Recursive descent parser that handles precedence
- Semantic Evaluation: Stack-based evaluation of boolean expressions
- Operator Support: NOT (
~), AND (^), OR (v), IMPLIES (->)
The interpreter implements the following formal grammar:
B → IT '.'
IT → OT IT'
IT' → '->' OT IT' | ε
OT → AT OT'
OT' → 'v' AT OT' | ε
AT → L AT'
AT' → '^' L AT' | ε
L → '~' L | A
A → 'T' | 'F' | '(' IT ')'
Requires CMake 3.10+ and a minimum C++17 compiler.
mkdir build && cd build
cmake ..
makeThis produces two executables:
interpreter- Main interpreter binarytest- Lexer testing
Currently configured for programmatic use. Modify main.cpp to evaluate different expressions:
std::string input = "TvF."; // true OR false
lexer::Lex lex(input);
if (parser::B(lex)) {
bool result = parser::getResult();
std::cout << (result ? "True" : "False");
}
else {
std::cout << "Syntax invalid";
}| Expression | Meaning | Result |
|---|---|---|
T. |
True | True |
~F. |
NOT False | True |
T^F. |
True AND False | False |
TvF. |
True OR False | True |
F->T. |
False IMPLIES True | True |
T->(F->T). |
Nested implication | True |
~(T^F). |
NOT (True AND False) | True |