#ifndef NODECREATOR #define NODECREATOR #include #include #include #include #include #include "node.h" #include "VariableMap.h" #include "arithmetica.h" using namespace std; /** *NodeCreator is a class that is responsible for creating nodes from the users *string input. The nodes it creates are dependent on the operators, *If an unknown(undefined) input is entered, the string will be processed as *if it is not there. * *CONSTRUCTOR *NodeCreator(const VariableMap & VariableList); * *NodeCreator(const VariableMap & VariableList, Arithmetica * processor, bool SpecialInstructions) *MEMBER FUNCTIONS * *NodeStack makePostfix(const NodeList & nodeList) * This function takes the Nodelist which is in an infix order, * and converts it into a postfix NodeStack, with higher * precedence nodes on top. This calls postFixHelper if the input * is not a number or an open parenthesis. It then calls * ClearOperatorStack to empty off the operatorStack when done * *Node * makeNodeTree(NodeStack & nodeStack) * This function takes in a stack of nodes in postfix order * and recursively combines them so that they are all stored * as the children of one node at the end * *PRIVATE MEMBER FUNCTIONS * *void postFixHelper( NodeStack & operatorStack, * NodeStack & postStack, Node* entry) * Called by postFixCreator to help create the postfix. * Checks for operators of greater precedence push them * off operator stack onto main stack. Then push on new operators * *void clearOperatorStack(NodeStack & operatorStack, NodeStack & postStack) * This function clears off the rest of the operatorStack when * nothing left to push on to it. * *PRIVATE VARIABLES * * VariableMap myVariable * Holds map of all current variables * * bool mySpecialInstructions * Tells whether the specific processor has special direction for creating a node tree * *Arithmetica * myProcessorType * Type of implementation currently using *Written by Jessica Smith */ class NodeCreator{ public: typedef vector NodeList; typedef stack NodeStack; NodeCreator(const VariableMap & VariableList); NodeCreator(const VariableMap & VariableList, Arithmetica *processor, bool SpecialInstructions); NodeList CreateNodes(string & line);//Creates nodes from //a string input Node* makeNodeTree(NodeStack & stackList );//Creates a tree from stack NodeStack makePostfix(const NodeList & nodeList);//changes infix to postfix private: VariableMap myVariable; bool mySpecialInstructions; Arithmetica * myProcessorType; void postFixHelper(NodeStack & operatorStack, NodeStack & postStack, Node* entry); void clearOperatorStack(NodeStack & operatorStack, NodeStack & postStack); }; #endif NODECREATOR