Base Framework
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ExpressionParser Class Reference

Expression parser. More...

#include <base/math/ExpressionParser.h>

Inherits Object.

Public Member Functions

 ExpressionParser (const String &expression, ExpressionProvider &provider) noexcept
 
void parse ()
 
const List< Node > & getExpression () const noexcept
 
bool getAutoRegister () const noexcept
 
void setAutoRegister (bool value) noexcept
 
const HashTable< String, Node > & getUnknowns () const noexcept
 
bool hasUnknowns () const noexcept
 
String getString () const
 
 ~ExpressionParser () noexcept
 

Protected Types

typedef ExpressionEvaluator::Node Node
 
typedef ExpressionEvaluator::Operation Operation
 

Protected Member Functions

void pop ()
 
void push (Operation operation)
 
void readIdentifier ()
 
void readValue ()
 

Protected Attributes

bool autoRegister = false
 
HashTable< String, Nodeunknowns
 
HashTable< unsigned int, StringunknownsId
 
String expression
 
ExpressionProviderprovider
 
Stack< Operationstack
 
List< Nodenodes
 
unsigned int operands = 0
 
bool unary = false
 
unsigned int index = 0
 
unsigned int length = 0
 

Detailed Description

Expression parser.

Arithmetic expression parser.

See also
ExpressionProvider
ExpressionEvaluator
Version
1.0
Examples
testsuite/eval.cpp.

Constructor & Destructor Documentation

◆ ExpressionParser()

ExpressionParser::ExpressionParser ( const String expression,
ExpressionProvider provider 
)
noexcept

Initializes an expression parser.

Parameters
expressionThe string representation of the expression to be parsed (e.g. "4+5*x/7").
providerThe expression provider.

◆ ~ExpressionParser()

ExpressionParser::~ExpressionParser ( )
noexcept

Destroys the expression parser.

Member Function Documentation

◆ getAutoRegister()

bool ExpressionParser::getAutoRegister ( ) const
inlinenoexcept

Returns the auto-register mode.

◆ getExpression()

const List<Node>& ExpressionParser::getExpression ( ) const
inlinenoexcept

Returns the result of the parser.

Examples
testsuite/eval.cpp.

◆ getString()

String ExpressionParser::getString ( ) const

Builds string expression from internal representation.

Examples
testsuite/eval.cpp.

◆ getUnknowns()

const HashTable<String, Node>& ExpressionParser::getUnknowns ( ) const
inlinenoexcept

Returns the unknowns.

Examples
testsuite/eval.cpp.

◆ hasUnknowns()

bool ExpressionParser::hasUnknowns ( ) const
inlinenoexcept

Returns true if the expression contains unknowns.

Examples
testsuite/eval.cpp.

◆ parse()

void ExpressionParser::parse ( )

Parses the specified arithmetic expression representation.

Examples
testsuite/eval.cpp.

◆ pop()

void ExpressionParser::pop ( )
protected

Pops one operation from the stack.

◆ push()

void ExpressionParser::push ( Operation  operation)
protected

Pushed the specified operation onto the stack.

◆ readIdentifier()

void ExpressionParser::readIdentifier ( )
protected

Reads an identifier from the representation.

◆ readValue()

void ExpressionParser::readValue ( )
protected

Reads a number from the representation.

◆ setAutoRegister()

void ExpressionParser::setAutoRegister ( bool  value)
inlinenoexcept

Sets the auto-register mode.

Examples
testsuite/eval.cpp.

Member Data Documentation

◆ autoRegister

bool ExpressionParser::autoRegister = false
protected

The auto-register mode. Default is disabled.

◆ expression

String ExpressionParser::expression
protected

The expression representation.

◆ index

unsigned int ExpressionParser::index = 0
protected

The current position in the representation.

◆ length

unsigned int ExpressionParser::length = 0
protected

The length of the expression.

◆ nodes

List<Node> ExpressionParser::nodes
protected

List holding the parsed expression.

◆ operands

unsigned int ExpressionParser::operands = 0
protected

Specifies the current number of operands.

◆ provider

ExpressionProvider& ExpressionParser::provider
protected

The expression provider.

◆ stack

Stack<Operation> ExpressionParser::stack
protected

Stack holding operations.

◆ unary

bool ExpressionParser::unary = false
protected

Specifies that an unary expression is expected.

◆ unknowns

HashTable<String, Node> ExpressionParser::unknowns
protected

Unknowns.

◆ unknownsId

HashTable<unsigned int, String> ExpressionParser::unknownsId
protected

Lookup of the unknowns by id.