#include "Expression.h"
#include "Operand.h"
#include "Exception.h"
#include <iostream>

namespace jet {

   Expression::Expression(coreutils::ZString &in) : MString() {
      std::cout << "Expression construction:" << in << std::endl;
      
      Operand op1(in);
      
      boolean = op1.boolean;
      string = op1.string;

      if(in.unparsed().getLength() > 0) {
	 std::cout << "1)" << in.unparsed() << "(" << std::endl;
	 if(in.ifNext("+"))
	   operation = (char *)"+";
	 else if(in.ifNext("-"))
	   operation = (char *)"-";
	 else
	   throw coreutils::Exception("Expecting operator.");
	 in.skipWhitespace();
	 if(in.unparsed().getLength() == 0)
	   throw coreutils::Exception("Expecting operand.");
	 Operand op2(in);
	 std::cout << op1.string << ":" << operation << ":" << op2.string << std::endl;
      }

      
      
      std::cout << "Leaving expression string: " << string << std::endl;
      std::cout << "Unparsed: [" << in.unparsed() << "]" << std::endl;
   }

   Expression::~Expression() {}

   bool Expression::getBooleanResult() {
      return boolean;
   }
   
   double Expression::getNumericResult() {
      return 0;
   }
   
   coreutils::ZString Expression::getStringResult() {
      return coreutils::ZString();
   }
      
}
