- Created A3::is_operator to allow for more complex processing.  Renamed
  old A3::is_operator to A3::which_operator.
This commit is contained in:
Paul Beckingham 2011-09-10 13:25:46 -04:00
parent 562fd8ce3c
commit 1994240899
2 changed files with 24 additions and 5 deletions

View file

@ -738,7 +738,7 @@ const A3 A3::tokenize (const A3& input) const
found_something_after_sequence = true; found_something_after_sequence = true;
} }
else if (n.getOneOf (operators, s)) else if (is_operator (operators, n, s))
{ {
output.push_back (Arg (s, Arg::cat_op)); output.push_back (Arg (s, Arg::cat_op));
if (found_sequence) if (found_sequence)
@ -1201,13 +1201,13 @@ const A3 A3::postfix (const A3& input) const
else else
throw std::string ("Mismatched parentheses in expression"); throw std::string ("Mismatched parentheses in expression");
} }
else if (is_operator (arg->_raw, type, precedence, associativity)) else if (which_operator (arg->_raw, type, precedence, associativity))
{ {
char type2; char type2;
int precedence2; int precedence2;
char associativity2; char associativity2;
while (op_stack.size () > 0 && while (op_stack.size () > 0 &&
is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) && which_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
((associativity == 'l' && precedence <= precedence2) || ((associativity == 'l' && precedence <= precedence2) ||
(associativity == 'r' && precedence < precedence2))) (associativity == 'r' && precedence < precedence2)))
{ {
@ -1731,6 +1731,24 @@ bool A3::is_integer (Nibbler& n, int& i)
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
bool A3::is_operator (
std::vector <std::string>& operators,
Nibbler& n,
std::string& result)
{
n.save ();
if (n.getOneOf (operators, result) &&
isTokenEnd (n.str (), n.cursor () - 1))
{
return true;
}
n.restore ();
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool A3::extract_pattern (const std::string& input, std::string& pattern) bool A3::extract_pattern (const std::string& input, std::string& pattern)
{ {
@ -1967,7 +1985,7 @@ bool A3::extract_uuid (
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool A3::is_operator ( bool A3::which_operator (
const std::string& input, const std::string& input,
char& type, char& type,
int& precedence, int& precedence,

View file

@ -88,6 +88,7 @@ public:
static bool is_tag (Nibbler&, std::string&); static bool is_tag (Nibbler&, std::string&);
static bool is_number (Nibbler&, double&); static bool is_number (Nibbler&, double&);
static bool is_integer (Nibbler&, int&); static bool is_integer (Nibbler&, int&);
static bool is_operator (std::vector <std::string>&, Nibbler&, std::string&);
static bool extract_pattern (const std::string&, std::string&); static bool extract_pattern (const std::string&, std::string&);
static bool extract_tag (const std::string&, char&, std::string&); static bool extract_tag (const std::string&, char&, std::string&);
@ -97,7 +98,7 @@ public:
static bool extract_id (const std::string&, std::vector <int>&); static bool extract_id (const std::string&, std::vector <int>&);
static bool extract_uuid (const std::string&, std::vector <std::string>&); static bool extract_uuid (const std::string&, std::vector <std::string>&);
static bool is_operator (const std::string&, char&, int&, char&); static bool which_operator (const std::string&, char&, int&, char&);
void dump (const std::string&); void dump (const std::string&);