Belle II Software light-2406-ragdoll
|
Base class with the non-templated part of the formula parser. More...
#include <FormulaParser.h>
Public Types | |
enum class | EOperator : unsigned char { c_noop = 0x00 , c_roundBracketOpen = 0x01 , c_roundBracketClose = 0x02 , c_squareBracketOpen = 0x03 , c_squareBracketClose = 0x04 , c_plus = 0x11 , c_minus = 0x12 , c_multiply = 0x21 , c_divide = 0x22 , c_power = 0x31 } |
List of known operators. More... | |
enum class | ENumberStatus { c_Invalid , c_Empty , c_Sign , c_Int , c_Dot , c_LeadingDot , c_Float , c_Exponent , c_ExponentSign , c_Scientific } |
States of a string literal when checking if it is a valid number. More... | |
typedef std::variant< std::string, double > | InputToken |
Input token type: an input tokein is either a string or a float variable. | |
Public Member Functions | |
FormulaParserBase ()=default | |
Default constructor. | |
virtual | ~FormulaParserBase ()=default |
virtual, but empty destructor | |
Static Public Member Functions | |
static char | operatorToChar (EOperator op) noexcept |
Convert operator code to character. | |
static double | applyOperator (EOperator op, double a, double b) |
Apply operator on two values. | |
static ENumberStatus | checkNumber (ENumberStatus current, char next) |
Check if a string literal with a given number status continues to be a valid number if next is appended to it. | |
Protected Member Functions | |
virtual void | executeOperator (EOperator op)=0 |
Execute an operator on the current state. | |
virtual void | addVariable (const InputToken &token)=0 |
Add a variable token to the current state. | |
void | processString (const std::string &formula) |
Process the given formula and store the final state. | |
void | raiseError (const std::runtime_error &e) |
Format the given runtime_error with context information and rethrow a new one. | |
Static Protected Member Functions | |
static void | assertOperatorUsable (size_t stacksize) |
Make sure we have enough operands to use an operator. | |
Private Member Functions | |
void | addOperator (EOperator op) |
Add an operator to the internal state, convert them to reverse polish notation using the shunting yard algorithm and execute them as they become available. | |
void | flushCurrentVariable () |
Flush the currently parsed variable name and add it to the state either as variable or number. | |
void | flushPendingOperators () |
Flush all pending operators at the end of processing. | |
EOperator | checkForOperator (char next) |
Check if the next character is a operator. | |
Private Attributes | |
bool | m_lastTokenWasOperator |
Bool to check whether there were consecutive operators or variables. | |
std::istringstream | m_buffer |
Buffer for the formula. | |
std::string | m_currentVariableName |
collect characters into a variable name | |
ENumberStatus | m_currentVariableNameNumberStatus |
State of the current variable name being a valid float literal. | |
std::stack< EOperator > | m_operatorStack |
Stack of operators for the Shunting-yard algorithm. | |
Base class with the non-templated part of the formula parser.
Not very useful on its own.
Definition at line 27 of file FormulaParser.h.
typedef std::variant<std::string, double> InputToken |
Input token type: an input tokein is either a string or a float variable.
Definition at line 59 of file FormulaParser.h.
|
strong |
States of a string literal when checking if it is a valid number.
Definition at line 45 of file FormulaParser.h.
|
strong |
List of known operators.
The second word encodes the operator precedence
Definition at line 31 of file FormulaParser.h.
|
protectedpure virtual |
Add a variable token to the current state.
Implemented in FormulaParser< VariableConstructor >.
|
protectedpure virtual |
Execute an operator on the current state.
Implemented in FormulaParser< VariableConstructor >.
|
private |
Buffer for the formula.
Definition at line 103 of file FormulaParser.h.
|
private |
collect characters into a variable name
Definition at line 105 of file FormulaParser.h.
|
private |
State of the current variable name being a valid float literal.
Definition at line 107 of file FormulaParser.h.
|
private |
Bool to check whether there were consecutive operators or variables.
Definition at line 101 of file FormulaParser.h.
|
private |
Stack of operators for the Shunting-yard algorithm.
Definition at line 109 of file FormulaParser.h.