staticcharbackspaceText[BUFFER_SIZE+1];// Pretty dumb waste of memory because only backspace characters, used with send_string to backspace and remove input
staticchartext[BUFFER_SIZE+1];// Used to store input and then output when ready to print
staticunsignedcharinputLocation=0;// Current index in text input
doublecalc(charinput[])// Finds value of input char array, relatively small and fast I think
{
charinputToken[BUFFER_SIZE+1];// Input buffer, used when a single token (generally a number) takes up more
unsignedcharinputTokenLocation=0,inputLocation=0;// Keep track of indices
structTokentokens[BUFFER_SIZE+1];// Input, converted to tokens, one extra large to accomodate for possible negative sign then open parenthesis as first character
unsignedchartokenCount=0;// Keep track of index
booldashAsMinus=false;// Kind of a hacky solution to determining whether to treat a dash as a minus sign or a negative sign
while(inputLocation<BUFFER_SIZE)
{
shortnumber=input[inputLocation]-'0';// Using a short here because both signed char and unsigned char would overflow, potentially
// sscanf(inputToken, "%lf", &tokens[tokenCount].raw.num); // I would like to use sscanf here, but the small version of stdio.h on the chip doesn't allow sscanf or its sister functions to be used to process floats
tokens[tokenCount].raw.num=atof(inputToken);
tokens[tokenCount].isNum=true;
for(unsignedchari=0;i<inputTokenLocation+1;i++)
{
inputToken[i]='\0';
}
inputTokenLocation=0;
tokenCount++;
dashAsMinus=true;
}
tokens[tokenCount].isNum=false;
tokens[tokenCount].raw.op.c=input[inputLocation];
tokens[tokenCount].raw.op.priority=0;
tokens[tokenCount].raw.op.ltr=true;
dashAsMinus=false;
switch(input[inputLocation])
{
caseCHAR_BEG:
break;
caseCHAR_END:
dashAsMinus=true;
break;
caseCHAR_ADD:
tokens[tokenCount].raw.op.priority=PRIO_ADD;
break;
caseCHAR_SUB:
tokens[tokenCount].raw.op.priority=PRIO_SUB;
break;
caseCHAR_MUL:
tokens[tokenCount].raw.op.priority=PRIO_MUL;
break;
caseCHAR_DIV:
tokens[tokenCount].raw.op.priority=PRIO_DIV;
break;
caseCHAR_EXP:
tokens[tokenCount].raw.op.priority=PRIO_EXP;
tokens[tokenCount].raw.op.ltr=false;
break;
caseCHAR_SIN:
break;
caseCHAR_COS:
break;
caseCHAR_TAN:
break;
caseCHAR_ASN:
break;
caseCHAR_ACS:
break;
caseCHAR_ATN:
break;
caseCHAR_LGE:
break;
caseCHAR_LOG:
break;
caseCHAR_SQT:
break;
case'\0':
tokenCount--;
inputLocation=BUFFER_SIZE;
break;
default:
tokenCount--;
break;
}
tokenCount++;
inputLocation++;
}
}
structTokenoutput[BUFFER_SIZE+1];// Final output tokens before evaluation
structTokenopstack[BUFFER_SIZE+1];// Stack of operators
unsignedcharoutputLocation=0,opstackLocation=0;// Keep track of indices
unsignedcharnumBrackets=0;// The number of parenthesis