#include "Complex.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <conio.h>
#include "OperandStack.h"
#include "Expression.h"
using namespace std;

void perform(char op, Complex &operand1, const Complex &operand2);

void main()
{
//  Complex::unitTest();
    OperandStack dataStack;
    Complex operand1, operand2;
    ifstream infile("test1.dat");

    Expression expr(infile);
    expr.inorderPrint(cout);
    operand1 = expr.evaluate();    
    
/*
    char buf;
    infile.close();
    infile.open("test1.dat");

    while (infile>>buf)
    {
        if ((buf=='+')||(buf=='-')||(buf=='*')||(buf=='/'))
        {
//            cout << "[" << buf << "]" << endl;
            dataStack.pop(operand2);
            dataStack.pop(operand1);
            perform(buf, operand1, operand2);
//            cout << "[[" << operand1 << "]]" << endl;
            dataStack.push(operand1);
        }
        else
        {
            infile.unget();
            infile >> operand1;
//            cout << operand1 << endl;
            dataStack.push(operand1);
        }
//        if (getch()==27) exit(1);
    }
    dataStack.pop(operand1);
*/
    cout << " = " << operand1 << endl;

    Expression expr1 = expr;
    expr1.inorderPrint(cout);
    operand1 = expr1.evaluate();
    cout << " = " << operand1 << endl;

    system("pause");
}

void perform(char op, Complex &operand1, const Complex &operand2)
{
    if (op == '+')
        operand1.add(operand2);
    else if (op == '-')
        operand1.subtract(operand2);
    else if (op == '*')
        operand1.multiply(operand2);
    else if (op == '/')
        operand1.divide(operand2);
}


/*

(1.1+2.2i) * (3+4.5i) / (-5.1+6i) + (-3i) - (-2+1.5i) * (1+i)
 --------------------
     (-6.6 +11.55i)                              (-3.5-0.5i)
          ------------------------
              (1.6604-0.3113i)
                    ---------------------
                            (1.6604 - 3.3113i)
                               -------------------------------
                                           (5.1604 - 2.8113i)
*/