LogiXpr
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Expression Class Reference

Abstract syntax tree for logic expressions. More...

#include <expression.h>

Public Member Functions

 Expression (std::string value)
 Construct a new Expression object.
 
std::string getValue ()
 Get the value of the current expression.
 
bool hasLeft ()
 Check if the current expression has a left subexpression.
 
bool hasRight ()
 Check if the current expression has a right subexpression.
 
bool isBinary ()
 Check if the current expression is a binary expression.
 
bool isVar ()
 Check if the current expression is a variable.
 
std::shared_ptr< ExpressiongetParent ()
 Get the parent expression of the current expression.
 
std::shared_ptr< ExpressiongetLeft ()
 Get the left subexpression of the current expression.
 
std::shared_ptr< ExpressiongetRight ()
 Get the right subexpression of the current expression.
 
void setLeft (std::shared_ptr< Expression > left, std::shared_ptr< Expression > parent)
 Sets the left child expression of this expression.
 
void setRight (std::shared_ptr< Expression > right, std::shared_ptr< Expression > parent)
 Sets the right child expression of this expression.
 
void setParent (std::shared_ptr< Expression > parent)
 Sets the parent node expression of this expression.
 
std::set< std::string > getVariables ()
 Get all the variables in the current expression and subexpressions.
 
std::shared_ptr< Expressionclone ()
 Create a clone of the current expression and subexpressions.
 
std::shared_ptr< ExpressioncloneTree ()
 Create a clone of the whole expression tree and returns the pointer to the node where it is called.
 
bool compare (std::shared_ptr< Expression > other)
 Compare the current expression to another expression.
 
bool compareTree (std::shared_ptr< Expression > other)
 Compare the entire expression tree to another expression tree.
 
std::string toString ()
 Convert the current expression to a string.
 
std::string toStringTree ()
 Convert the whole expression tree to a string.
 
std::string toStringMinimal ()
 Convert the current expression to a string with minimal parentheses.
 

Private Attributes

std::string value
 The current expression.
 
std::shared_ptr< Expressionparent
 Pointer to parent expression.
 
std::shared_ptr< Expressionleft
 Pointer to left subexpression.
 
std::shared_ptr< Expressionright
 Pointer to right subexpression.
 

Detailed Description

Abstract syntax tree for logic expressions.

Definition at line 42 of file expression.h.

Constructor & Destructor Documentation

◆ Expression()

Expression::Expression ( std::string  value)

Construct a new Expression object.

Parameters
valuethe current expression

Definition at line 8 of file expression.cpp.

Member Function Documentation

◆ clone()

std::shared_ptr< Expression > Expression::clone ( )

Create a clone of the current expression and subexpressions.

Returns
pointer to cloned expression

Definition at line 92 of file expression.cpp.

◆ cloneTree()

std::shared_ptr< Expression > Expression::cloneTree ( )

Create a clone of the whole expression tree and returns the pointer to the node where it is called.

Returns
pointer to cloned expression

Definition at line 105 of file expression.cpp.

◆ compare()

bool Expression::compare ( std::shared_ptr< Expression other)

Compare the current expression to another expression.

Parameters
otherpointer to other expression to compare to
Returns
bool of whether the current expression is equal to the other expression

Definition at line 136 of file expression.cpp.

◆ compareTree()

bool Expression::compareTree ( std::shared_ptr< Expression other)

Compare the entire expression tree to another expression tree.

Parameters
otherpointer to other expression to compare to
Returns
bool of whether the current expression tree is equal to the other expression tree

Definition at line 160 of file expression.cpp.

◆ getLeft()

std::shared_ptr< Expression > Expression::getLeft ( )

Get the left subexpression of the current expression.

Returns
pointer to left subexpression

Definition at line 44 of file expression.cpp.

◆ getParent()

std::shared_ptr< Expression > Expression::getParent ( )

Get the parent expression of the current expression.

Returns
pointer to parent expression

Definition at line 39 of file expression.cpp.

◆ getRight()

std::shared_ptr< Expression > Expression::getRight ( )

Get the right subexpression of the current expression.

Returns
pointer to right subexpression

Definition at line 49 of file expression.cpp.

◆ getValue()

std::string Expression::getValue ( )

Get the value of the current expression.

Returns
the value of the current expression

Definition at line 13 of file expression.cpp.

◆ getVariables()

std::set< std::string > Expression::getVariables ( )

Get all the variables in the current expression and subexpressions.

Returns
set of strings of all the variables in the current expression and subexpressions

Definition at line 71 of file expression.cpp.

◆ hasLeft()

bool Expression::hasLeft ( )

Check if the current expression has a left subexpression.

Returns
bool of whether the current expression has a left subexpression

Definition at line 18 of file expression.cpp.

◆ hasRight()

bool Expression::hasRight ( )

Check if the current expression has a right subexpression.

Returns
bool of whether the current expression has a right subexpression

Definition at line 23 of file expression.cpp.

◆ isBinary()

bool Expression::isBinary ( )

Check if the current expression is a binary expression.

Returns
bool of whether the current expression is a binary expression

Definition at line 28 of file expression.cpp.

◆ isVar()

bool Expression::isVar ( )

Check if the current expression is a variable.

Returns
bool of whether the current expression is a variable

Definition at line 33 of file expression.cpp.

◆ setLeft()

void Expression::setLeft ( std::shared_ptr< Expression left,
std::shared_ptr< Expression parent 
)

Sets the left child expression of this expression.

Parameters
leftpointer to expression to be set as the left child
parentpointer to current expression

Definition at line 54 of file expression.cpp.

◆ setParent()

void Expression::setParent ( std::shared_ptr< Expression parent)

Sets the parent node expression of this expression.

Parameters
parentpointer to expression to be set as the parent

Definition at line 66 of file expression.cpp.

◆ setRight()

void Expression::setRight ( std::shared_ptr< Expression right,
std::shared_ptr< Expression parent 
)

Sets the right child expression of this expression.

Parameters
rightpointer to expression to be set as the right child
parentpointer to current expression

Definition at line 60 of file expression.cpp.

◆ toString()

std::string Expression::toString ( )

Convert the current expression to a string.

Returns
string of the current expression

Definition at line 172 of file expression.cpp.

◆ toStringMinimal()

std::string Expression::toStringMinimal ( )

Convert the current expression to a string with minimal parentheses.

Returns
string of the current expression

Definition at line 204 of file expression.cpp.

◆ toStringTree()

std::string Expression::toStringTree ( )

Convert the whole expression tree to a string.

Returns
string of the whole expression tree

Definition at line 191 of file expression.cpp.

Member Data Documentation

◆ left

std::shared_ptr<Expression> Expression::left
private

Pointer to left subexpression.

Definition at line 207 of file expression.h.

◆ parent

std::shared_ptr<Expression> Expression::parent
private

Pointer to parent expression.

Definition at line 202 of file expression.h.

◆ right

std::shared_ptr<Expression> Expression::right
private

Pointer to right subexpression.

Definition at line 212 of file expression.h.

◆ value

std::string Expression::value
private

The current expression.

Definition at line 197 of file expression.h.


The documentation for this class was generated from the following files: