From fee493bcc049c73524eceabf88535333bb96edc2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 25 May 2014 14:11:55 -0400 Subject: [PATCH] Eval - Removed std::cout diagnostics, stubbed the A3::dump replacement. --- src/Eval.cpp | 73 +++++++++++++++++++++++++++++++++++++++------------- src/Eval.h | 2 ++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/Eval.cpp b/src/Eval.cpp index 5273b3143..7597c03fc 100644 --- a/src/Eval.cpp +++ b/src/Eval.cpp @@ -26,8 +26,11 @@ #include #include +#include #include +extern Context context; + //////////////////////////////////////////////////////////////////////////////// // Supported operators, borrowed from C++, particularly the precedence. // Note: table is sorted by length of operator string, so searches match @@ -124,16 +127,16 @@ void Eval::evaluateInfixExpression (const std::string& e, Variant& v) const tokens.push_back (std::pair (token, type)); // Parse for syntax checking and operator replacement. + if (_debug) + context.debug ("Infix tokens " + dump (tokens)); infixParse (tokens); if (_debug) - { - std::vector >::iterator i; - for (i = tokens.begin (); i != tokens.end (); ++i) - std::cout << "# token infix '" << i->first << "' " << Lexer::type_name (i->second) << "\n"; - } + context.debug ("Parsed tokens " + dump (tokens)); // Convert infix --> postfix. infixToPostfix (tokens); + if (_debug) + context.debug ("Postfix tokens " + dump (tokens)); // Call the postfix evaluator. evaluatePostfixStack (tokens, v); @@ -149,11 +152,10 @@ void Eval::evaluatePostfixExpression (const std::string& e, Variant& v) const std::string token; Lexer::Type type; while (l.token (token, type)) - { tokens.push_back (std::pair (token, type)); - if (_debug) - std::cout << "# token postfix '" << token << "' " << Lexer::type_name (type) << "\n"; - } + + if (_debug) + context.debug ("Filter postfix tokens " + dump (tokens)); // Call the postfix evaluator. evaluatePostfixStack (tokens, v); @@ -168,23 +170,19 @@ void Eval::compileExpression (const std::string& e) std::string token; Lexer::Type type; while (l.token (token, type)) - { _compiled.push_back (std::pair (token, type)); - if (_debug) - std::cout << "# token '" << token << "' " << Lexer::type_name (type) << "\n"; - } // Parse for syntax checking and operator replacement. + if (_debug) + context.debug ("Filter infix tokens " + dump (_compiled)); infixParse (_compiled); if (_debug) - { - std::vector >::iterator i; - for (i = _compiled.begin (); i != _compiled.end (); ++i) - std::cout << "# token infix '" << i->first << "' " << Lexer::type_name (i->second) << "\n"; - } + context.debug ("Filter parsed tokens " + dump (_compiled)); // Convert infix --> postfix. infixToPostfix (_compiled); + if (_debug) + context.debug ("Postfix tokens " + dump (_compiled)); } //////////////////////////////////////////////////////////////////////////////// @@ -857,4 +855,43 @@ bool Eval::identifyOperator ( } //////////////////////////////////////////////////////////////////////////////// +std::string Eval::dump ( + std::vector >& tokens) const +{ + std::string output; + std::vector >::const_iterator i; + for (i = tokens.begin (); i != tokens.end (); ++i) + { + if (i != tokens.begin ()) + output += ' '; + + switch (i->second) + { + case Lexer::typeOperator: + output += i->first; + break; + + case Lexer::typeNone: + case Lexer::typeString: + case Lexer::typeIdentifier: + case Lexer::typeIdentifierEscape: + case Lexer::typeEscape: + case Lexer::typeEscapeHex: + case Lexer::typeEscapeUnicode: + case Lexer::typeNumber: + case Lexer::typeDecimal: + case Lexer::typeExponentIndicator: + case Lexer::typeExponent: + case Lexer::typeHex: + case Lexer::typeDate: + case Lexer::typeDuration: + output += i->first; + break; + } + } + + return output; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Eval.h b/src/Eval.h index 79350caed..3541a91b8 100644 --- a/src/Eval.h +++ b/src/Eval.h @@ -67,6 +67,8 @@ private: bool parsePrimitive (std::vector >&, int &) const; bool identifyOperator (const std::string&, char&, int&, char&) const; + std::string dump (std::vector >&) const; + private: std::vector _sources; bool _ambiguity;