1 #ifndef EXPRESSION_PARSER_H
2 #define EXPRESSION_PARSER_H
59 template<
class CharSeq>
79 ternary_either_or = 10,
313 template<
unsigned Precedence>
321 template<
unsigned Precedence>
322 typename std::enable_if<(Precedence == 0),evaluation>::type
327 template<
unsigned Precedence>
328 typename std::enable_if<(Precedence > 0),
evaluation>::type
330 return infix_op<Precedence>(chew,end);
361 template<
unsigned Precedence>
362 std::pair<expression_parser::infix_operation,bool>
381 _deletions[loff] = deletion_code::not_deleted;
382 _deletions[roff] = deletion_code::not_deleted;
412 void cut(
size_t start,
size_t end) {
414 for ( ;start < end; ++start) {
evaluation op_bit_and(evaluation const &lhs, evaluation const &rhs)
Bitwise AND operator.
template struct traits::is_random_access_char_sequence<T> exports a static const boolean member value...
std::vector< deletion_code > _deletions
Vector of logical deletion codes;.
evaluation op_rshift(evaluation const &lhs, evaluation const &rhs)
Right-shift operator.
evaluation apply(infix_operation op, evaluation &lhs, evaluation &rhs)
Apply a infix operation to arguments.
integer const & value() const
Get the integral value of the expression.
evaluation op_add(evaluation const &lhs, evaluation const &rhs)
Addition operator.
evaluation op_lt(evaluation const &lhs, evaluation const &rhs)
Less-than operator.
std::string simplified() const
Get the most simplified form of the expression.
ptrdiff_t _last_deletion
Index of rightmost deletion, -1 if none.
evaluation op_ne(evaluation const &lhs, evaluation const &rhs)
Inequality operator.
evaluation op_lshift(evaluation const &lhs, evaluation const &rhs)
Left-shift operator.
size_t _cuts
Number of logically deleted operands.
evaluation op_subtract(evaluation const &lhs, evaluation const &rhs)
Subtraction operator.
void defer_diagnostic(diagnostic_base &gripe)
Defer a diagnostic, with the current line context appended if a source line is being parsed...
Encapsulates parsing of preprocessor expressions.
CharSeq sequence_type
Type of character-sequence containing the parsed expression.
A base class for diagnostic classes.
void delete_paren(size_t loff, size_t roff)
Logically delete redundant parentheses.
evaluation op_le(evaluation const &lhs, evaluation const &rhs)
Less-than-or-equal operator.
evaluation op_mod(evaluation const &lhs, evaluation const &rhs)
Modulus operator.
void cut(size_t start, size_t end)
Logically delete part of the evaluated text.
evaluation op_ge(evaluation const &lhs, evaluation const &rhs)
Greater-than-or-equal operator.
std::vector< evaluation > _ternary_cond_stack
Stack of ternary conditional results;.
evaluation(expression_parser::*)(evaluation const &, evaluation const &) infix_operation
Type of an infix operation.
evaluation result() const
Get the result of parsing the expression.
bool is_simplified() const
Say whether the expression has been simplified.
expression_parser(chewer< sequence_type > &chew, reference const *ref=nullptr)
Construct given a chewer<sequence_type>
evaluation op_eq(evaluation const &lhs, evaluation const &rhs)
Equality operator.
precedence
Codes for operator precedences.
evaluation op_comma(evaluation const &lhs, evaluation const &rhs)
Comma operator.
evaluation infix_op(chewer< sequence_type > &chew, size_t end)
Evaluator for infix operations.
evaluation op_or(evaluation const &lhs, evaluation const &rhs)
Inclusive-or operator.
evaluation op_mult(evaluation const &lhs, evaluation const &rhs)
Multiplication operator.
A logically deleted parenthesis.
evaluation _eval
The evaluation that results from parsing the expression.
void restore_paren()
Restore all logically deleted parentheses.
evaluation op_divide(evaluation const &lhs, evaluation const &rhs)
Division operator.
evaluation op_ternary_either_or(evaluation const &lhs, evaluation const &rhs)
The ':' "operator". Pops the evaluation of the preceding `cond ?' from the stack. If cond is true, returns lhs; if cond is false returns rhs, else returns evaluation()
reference const * _ref
A pointer to the reference if any, that calls for expression parsing.
evaluation op_and(evaluation const &lhs, evaluation const &rhs)
And operator.
evaluation op_bit_or(evaluation const &lhs, evaluation const &rhs)
Bitwise OR operator.
`template struct chewer<CharSeq> is a cursor-like type that is associated with a character-sequence t...
std::enable_if<(Precedence==0), evaluation >::type next_evaluator(chewer< sequence_type > &chew, size_t end)
Select the member function to recursively evaluate expressions in which the major operator has a give...
evaluation op_gt(evaluation const &lhs, evaluation const &rhs)
Greater-than operator.
void restore_paren(size_t loff, size_t roff)
Restore a prematurely deleted pair of parentheses.
void parse(chewer< sequence_type > &chew)
Evaluate text from a chewer<sequence_type>
deletion_code
Codes for logical deletion status.
evaluation op_bit_xor(evaluation const &lhs, evaluation const &rhs)
Bitwise XOR operator.
evaluation unary_op(chewer< sequence_type > &chew, size_t end)
Evaluator for innermost subexpressions.
sequence_type & _seq
A reference to the character sequence being parsed.
evaluation op_ternary_if(evaluation const &lhs, evaluation const &rhs)
The '?' "operator". Stacks its left operand; returns its right.
A logically deleted non-parenthesis.
struct evaluation represents the result of evaluating a putative expression.
size_t _start
Text offset at which evaluation starts.
std::pair< expression_parser::infix_operation, bool > seek_rightmost_infix(chewer< sequence_type > &chew, size_t end, size_t &op_start, size_t &op_end)
Search for the rightmost binary operator at a given level of precedence within delimited text...