#include "ProcessString.h" #include "ProcessDerivative.h" #include "node.h" #include #include #include #include "VariableMap.h" #include "OperatorMap.h" #include "differentiatorNodes.h" /** *ProcessDerivative is a class that helps turn a string into nodes. It is used by *NodeCreator in this program. ProcessDerivaative is responsible for taking each *part of the string and looking up to see how each char of the string should *be dealt with.It is specifically added by the Differentiator functionality * *Written by Jessica Smith and Poornima Vijayshanker */ //constructor ProcessDerivative::ProcessDerivative(string & line, int & position, const VariableMap & variableMap) :ProcessString(line,position,variableMap) { } void ProcessDerivative::processBeginning() { //Process the beginning of the string and check first for BinaryFunctions, then proceed as had before string binaryString; checkBinaryFunction(myLine,myPosition,binaryString); ProcessString::processBeginning(); } void ProcessDerivative::processRest() { //Process the rest of the string checking for Binary Operator first string binaryString; for(;myPosition>value; return value; } string ProcessDerivative::findKey( int & position) { //Searches for the key, telling it by its location after the comma, if not there return empty string string key; while(isalpha(myLine[position])) { key+=myLine[position]; position++; } myLine=myLine.substr(position+1,myLine.length()-position-1); myPosition=-1; return key; } bool ProcessDerivative::checkBinaryFunction( string & line, int & position, string & binaryString) { //Checks to see if the string given is a call to a binary function string binaryCheck; int placeHolder=position; //holds location of original location while(isalpha(line[position])) { binaryCheck+=line[position]; position++; } position--; if(myOperatorMap.isTypeOperator(binaryCheck,BINARY_FUNCTION_PRECEDENCE)) { binaryString=binaryCheck; return true; } position=placeHolder; return false; } Node * ProcessDerivative::findWord(string & line, int& position,string key,int value) { //Finds the string for the entire variable name and created a node for it. position is updated accordingly string name; name+=line[position];//pushes letter onto string position++; while(isalpha(line[position]))//continues while it still is letter { name+=line[position]; position++; } if(myOperatorMap.isOperator(name)) { return(myOperatorMap.lookUpOperator(name)); } if(name==key) { return(new Variable(name,value,CONSTANT_PRECEDENCE)); } return(new Variable(name,myVariable.lookUpVar(name)->evaluate(),CONSTANT_PRECEDENCE)); } void ProcessDerivative::processInternalExpression(string & toEvaluate,string & key,double & value) { //Process interior part of binary function and pushes on nodes string binaryString=""; for(int k=0;k