Expressions

- Began Expression::toInfix to upgrade old-style filters to infix
  algebraic filters.
- Added operator support to Arguments::categorize.
- Modified CmdCustom.cpp as a read-only command guinea-pig for the
  new argument processing.
This commit is contained in:
Paul Beckingham 2011-06-05 13:43:32 -04:00
parent 68a749ee16
commit 86dcec8aea
6 changed files with 98 additions and 11 deletions

View file

@ -25,15 +25,14 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <Context.h>
#include <Expression.h>
////////////////////////////////////////////////////////////////////////////////
Expression::Expression ()
{
}
extern Context context;
////////////////////////////////////////////////////////////////////////////////
Expression::Expression (Arguments& arguments)
: _original (arguments)
{
}
@ -49,13 +48,38 @@ bool Expression::eval (Task& task)
}
////////////////////////////////////////////////////////////////////////////////
// Inserts the 'and' operator by default between terms that are not separated by
// at least one operator.
//
// Converts: <term1> <term2> <op> <term3>
// to: <term1> and <term2> <op> <term3>
//
void Expression::toInfix ()
{
_infix.clear ();
std::string previous = "op";
std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = _original.begin (); arg != _original.end (); ++arg)
{
if (previous != "op" &&
arg->second != "op")
_infix.push_back (std::make_pair ("and", "op"));
_infix.push_back (*arg);
previous = arg->second;
}
_infix.dump ("Expression::toInfix");
}
////////////////////////////////////////////////////////////////////////////////
// Dijkstra Shunting Algorithm.
void Expression::toPostfix ()
{
_postfix.clear ();
_postfix.dump ("Expression::toPostfix");
}
////////////////////////////////////////////////////////////////////////////////