14#include <unordered_map>
36const static std::unordered_map<std::string, int> precedence = {
37 {
NOT, 5}, {
AND, 4}, {
OR, 3}, {
XOR, 2}, {
IMPLIES, 1}, {
IFF, 0}};
98 std::shared_ptr<Expression>
getLeft();
105 std::shared_ptr<Expression>
getRight();
113 void setLeft(std::shared_ptr<Expression>
left, std::shared_ptr<Expression>
parent);
142 std::shared_ptr<Expression>
clone();
160 bool compare(std::shared_ptr<Expression> other);
170 bool compareTree(std::shared_ptr<Expression> other);
207 std::shared_ptr<Expression>
left;
Abstract syntax tree for logic expressions.
std::shared_ptr< Expression > right
Pointer to right subexpression.
bool compareTree(std::shared_ptr< Expression > other)
Compare the entire expression tree to another expression tree.
std::string getValue()
Get the value of the current expression.
std::shared_ptr< Expression > getLeft()
Get the left subexpression of the current expression.
bool compare(std::shared_ptr< Expression > other)
Compare the current expression to another expression.
std::set< std::string > getVariables()
Get all the variables in the current expression and subexpressions.
void setRight(std::shared_ptr< Expression > right, std::shared_ptr< Expression > parent)
Sets the right child expression of this expression.
std::shared_ptr< Expression > getRight()
Get the right subexpression of the current expression.
std::string toString()
Convert the current expression to a string.
std::string toStringTree()
Convert the whole expression tree to a string.
std::shared_ptr< Expression > left
Pointer to left subexpression.
std::shared_ptr< Expression > getParent()
Get the parent expression of the current expression.
bool hasRight()
Check if the current expression has a right subexpression.
bool isBinary()
Check if the current expression is a binary expression.
std::shared_ptr< Expression > cloneTree()
Create a clone of the whole expression tree and returns the pointer to the node where it is called.
bool isVar()
Check if the current expression is a variable.
void setParent(std::shared_ptr< Expression > parent)
Sets the parent node expression of this expression.
std::shared_ptr< Expression > clone()
Create a clone of the current expression and subexpressions.
std::string value
The current expression.
std::string toStringMinimal()
Convert the current expression to a string with minimal parentheses.
bool hasLeft()
Check if the current expression has a left subexpression.
void setLeft(std::shared_ptr< Expression > left, std::shared_ptr< Expression > parent)
Sets the left child expression of this expression.
std::shared_ptr< Expression > parent
Pointer to parent expression.