- Removed std::cout diagnostics, stubbed the A3::dump replacement.
This commit is contained in:
Paul Beckingham 2014-05-25 14:11:55 -04:00
parent 6b2a71770d
commit fee493bcc0
2 changed files with 57 additions and 18 deletions

View file

@ -26,8 +26,11 @@
#include <iostream> #include <iostream>
#include <time.h> #include <time.h>
#include <Context.h>
#include <Eval.h> #include <Eval.h>
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Supported operators, borrowed from C++, particularly the precedence. // Supported operators, borrowed from C++, particularly the precedence.
// Note: table is sorted by length of operator string, so searches match // 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 <std::string, Lexer::Type> (token, type)); tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
// Parse for syntax checking and operator replacement. // Parse for syntax checking and operator replacement.
if (_debug)
context.debug ("Infix tokens " + dump (tokens));
infixParse (tokens); infixParse (tokens);
if (_debug) if (_debug)
{ context.debug ("Parsed tokens " + dump (tokens));
std::vector <std::pair <std::string, Lexer::Type> >::iterator i;
for (i = tokens.begin (); i != tokens.end (); ++i)
std::cout << "# token infix '" << i->first << "' " << Lexer::type_name (i->second) << "\n";
}
// Convert infix --> postfix. // Convert infix --> postfix.
infixToPostfix (tokens); infixToPostfix (tokens);
if (_debug)
context.debug ("Postfix tokens " + dump (tokens));
// Call the postfix evaluator. // Call the postfix evaluator.
evaluatePostfixStack (tokens, v); evaluatePostfixStack (tokens, v);
@ -149,11 +152,10 @@ void Eval::evaluatePostfixExpression (const std::string& e, Variant& v) const
std::string token; std::string token;
Lexer::Type type; Lexer::Type type;
while (l.token (token, type)) while (l.token (token, type))
{
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type)); tokens.push_back (std::pair <std::string, Lexer::Type> (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. // Call the postfix evaluator.
evaluatePostfixStack (tokens, v); evaluatePostfixStack (tokens, v);
@ -168,23 +170,19 @@ void Eval::compileExpression (const std::string& e)
std::string token; std::string token;
Lexer::Type type; Lexer::Type type;
while (l.token (token, type)) while (l.token (token, type))
{
_compiled.push_back (std::pair <std::string, Lexer::Type> (token, type)); _compiled.push_back (std::pair <std::string, Lexer::Type> (token, type));
if (_debug)
std::cout << "# token '" << token << "' " << Lexer::type_name (type) << "\n";
}
// Parse for syntax checking and operator replacement. // Parse for syntax checking and operator replacement.
if (_debug)
context.debug ("Filter infix tokens " + dump (_compiled));
infixParse (_compiled); infixParse (_compiled);
if (_debug) if (_debug)
{ context.debug ("Filter parsed tokens " + dump (_compiled));
std::vector <std::pair <std::string, Lexer::Type> >::iterator i;
for (i = _compiled.begin (); i != _compiled.end (); ++i)
std::cout << "# token infix '" << i->first << "' " << Lexer::type_name (i->second) << "\n";
}
// Convert infix --> postfix. // Convert infix --> postfix.
infixToPostfix (_compiled); infixToPostfix (_compiled);
if (_debug)
context.debug ("Postfix tokens " + dump (_compiled));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -857,4 +855,43 @@ bool Eval::identifyOperator (
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Eval::dump (
std::vector <std::pair <std::string, Lexer::Type> >& tokens) const
{
std::string output;
std::vector <std::pair <std::string, Lexer::Type> >::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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -67,6 +67,8 @@ private:
bool parsePrimitive (std::vector <std::pair <std::string, Lexer::Type> >&, int &) const; bool parsePrimitive (std::vector <std::pair <std::string, Lexer::Type> >&, int &) const;
bool identifyOperator (const std::string&, char&, int&, char&) const; bool identifyOperator (const std::string&, char&, int&, char&) const;
std::string dump (std::vector <std::pair <std::string, Lexer::Type> >&) const;
private: private:
std::vector <bool (*)(const std::string&, Variant&)> _sources; std::vector <bool (*)(const std::string&, Variant&)> _sources;
bool _ambiguity; bool _ambiguity;