inline RexxInternalObject *requiredLogicalExpression(int terminators, RexxErrorCodes error) { RexxInternalObject *conditional = parseLogical(terminators); if (conditional == OREF_NULL) { syntaxError(error); } return conditional; }
//////////////////////////////////////////////////////////////////////////////// // Primitive --> "(" Logical ")" | Variant bool Eval::parsePrimitive ( std::vector <std::pair <std::string, Lexer::Type> >& infix, int &i) const { if (i < infix.size ()) { if (infix[i].first == "(") { ++i; if (i < infix.size () && parseLogical (infix, i)) { if (i < infix.size () && infix[i].first == ")") { ++i; return true; } } } else { bool found = false; std::vector <bool (*)(const std::string&, Variant&)>::const_iterator source; for (source = _sources.begin (); source != _sources.end (); ++source) { Variant v; if ((*source) (infix[i].first, v)) { found = true; break; } } if (found) { ++i; return true; } else if (infix[i].second != Lexer::typeOperator) { ++i; return true; } } } return false; }
//////////////////////////////////////////////////////////////////////////////// // Primitive --> "(" Logical ")" | Variant bool Eval::parsePrimitive ( std::vector <std::pair <std::string, Lexer::Type>>& infix, unsigned int &i) const { if (i < infix.size ()) { if (infix[i].first == "(") { ++i; if (i < infix.size () && parseLogical (infix, i)) { if (i < infix.size () && infix[i].first == ")") { ++i; return true; } } } else { bool found = false; for (auto source = _sources.begin (); source != _sources.end (); ++source) { Variant v; if ((*source) (infix[i].first, v)) { found = true; break; } } if (found) { ++i; return true; } else if (infix[i].second != Lexer::Type::op) { ++i; return true; } } } return false; }
//////////////////////////////////////////////////////////////////////////////// // // Grammar: // Logical --> Regex {( "and" | "or" | "xor" ) Regex} // Regex --> Equality {( "~" | "!~" ) Equality} // Equality --> Comparative {( "==" | "=" | "!=" ) Comparative} // Comparative --> Arithmetic {( "<=" | "<" | ">=" | ">" ) Arithmetic} // Arithmetic --> Geometric {( "+" | "-" ) Geometric} // Geometric --> Tag {( "*" | "/" | "%" ) Tag} // Tag --> Unary {( "_hastag_" | "_notag_" ) Unary} // Unary --> [( "-" | "+" | "!" )] Exponent // Exponent --> Primitive ["^" Primitive] // Primitive --> "(" Logical ")" | Variant // void Eval::infixParse ( std::vector <std::pair <std::string, Lexer::Type> >& infix) const { int i = 0; parseLogical (infix, i); }