Connector* buildTree(list<char**>& args, list<char*>& cons) { // Returns the head of the tree. // Allocated data here can be deleted during cleanup via preorder deletion. printLine(30); ConnectorFactory factory; // cout << "[DEBUG] Throwing "; printArgs(args.front()); cout << " into leftCmd." << endl; cout << "[DEBUG] Building left node branch." << endl; Connector* leftCmd = factory.createBranch(args, cons); cout << "[DEBUG] Left node Subtree Built." << endl; // if (leftCmd != NULL) cout << "[DEBUG] leftCmd holds "; printArgs(leftCmd->getCmd()); cout << endl; if (args.empty()) { cout << "[DEBUG] args list held one element only, returning..." << endl; return leftCmd; } Connector* rightCmd = NULL; Connector* currHead = NULL; while (!cons.empty()) { while (!args.empty()) { if (checkConnectors(cons.front()) == 1) { // If is hash, EVACUATE. while (!args.empty()) args.pop_front(); while (!cons.empty()) cons.pop_front(); break; } currHead = factory.createConnector(checkConnectors(cons.front())); cout << "[DEBUG] currHead speaking: "; currHead->identify(); cons.pop_front(); rightCmd = factory.createBranch(args, cons); // This is going to handle precedence. cout << "[DEBUG] Branch created." << endl; currHead->setLeft(leftCmd); currHead->setRight(rightCmd); cout << "[DEBUG] Statement: leftCmd = currHead" << endl; leftCmd = currHead; // Sets left leaf to be current head. cout << "[DEBUG] leftCmd: "; leftCmd->identify(); } if (args.empty() && !cons.empty()) cons.pop_front(); } printLine(30); return currHead; }