From 1994240899543e920298fdf867b7b2e8c3348f00 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 10 Sep 2011 13:25:46 -0400 Subject: [PATCH] Parsing - Created A3::is_operator to allow for more complex processing. Renamed old A3::is_operator to A3::which_operator. --- src/A3.cpp | 26 ++++++++++++++++++++++---- src/A3.h | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/A3.cpp b/src/A3.cpp index c2faea8bd..22aa57300 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -738,7 +738,7 @@ const A3 A3::tokenize (const A3& input) const 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)); if (found_sequence) @@ -1201,13 +1201,13 @@ const A3 A3::postfix (const A3& input) const else 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; int precedence2; char associativity2; 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 == 'r' && precedence < precedence2))) { @@ -1731,6 +1731,24 @@ bool A3::is_integer (Nibbler& n, int& i) return false; } +//////////////////////////////////////////////////////////////////////////////// +bool A3::is_operator ( + std::vector & 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) { @@ -1967,7 +1985,7 @@ bool A3::extract_uuid ( } //////////////////////////////////////////////////////////////////////////////// -bool A3::is_operator ( +bool A3::which_operator ( const std::string& input, char& type, int& precedence, diff --git a/src/A3.h b/src/A3.h index 0723c7363..7e979b72f 100644 --- a/src/A3.h +++ b/src/A3.h @@ -88,6 +88,7 @@ public: static bool is_tag (Nibbler&, std::string&); static bool is_number (Nibbler&, double&); static bool is_integer (Nibbler&, int&); + static bool is_operator (std::vector &, Nibbler&, std::string&); static bool extract_pattern (const std::string&, 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 &); static bool extract_uuid (const std::string&, std::vector &); - 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&);