// function processing
Bool CEXPIRESSION :: Level6 (Double * Result)
{
Int Num; char funcname [8];
CHAR OP = 0;
INT paraNum = 1;
Double Para [6];
IF (isFunc (m_strtoken)) // If it is a function name
// if (expgetFunIndex (M_STRTOKEN, & NUM) == True)
{
Op = 1;
STRCPY (FuncName, M_STRTOKEN);
// get the next unit
IF (gettoken ()! = TRUE)
{
m_ierrflag = 2; // m_ierrflag = 1;
Return False;
}
}
IF (op)
{
IF ((* m_STRTOKEN == '(') && (m_ctoke == delimiter))
{
/ / Get the first unit in parentheses
IF (getToken () == true)
{
// Recursive call, complete expressions within parentheses
IF (Level2 (RESULT)! = TRUE
Return False;
While (m_ctokentype == delimiter && * m_strtoken == ',')
{
ParaNum ;
IF (gettoken ()! = TRUE)
{
m_ierrflag = 2; // m_ierrflag = 1;
Return False;
}
// Recursive call, complete expressions within parentheses
IF (Level2 (& Para [paraNum-1])! = true)
Return False;
}
PARA [0] = * result;
// The current symbol should be ')'
IF (* m_strtoken! = ')')
{
// brackets do not match
m_ierrflag = 3;
Return False;
}
IF (gettoken ()! = TRUE)
{
m_ierrflag = 2; // m_ierrflag = 1;
Return False;
}
}
Else
{
m_ierrflag = 2; // m_ierrflag = 1;
Return False;
}
}
Else
{
// brackets do not match
m_ierrflag = 3;
Return False;
}
// single parameter
IF (paraNum == 1)
{
* Result = Para [0];
/ / If the function is a trigonometric function, the angle to the radio conversion
IF (StricMP (FuncName, "SIN") == 0 ||
Stricmp (FuncName, "COS") == 0 ||
Stricmp (FuncName, "Tan") == 0)
{
IF (StricsP (FuncName, "Tan") == 0)
{
IF (FABS (* Result - 90.0) <0.0005 ||
FABS (* Result - 270.0) <0.0005 ||
FABS (* Result 90.0) <0.0005 ||
FABS (* Result 270.0) <0.0005)
{
Message ("Positive Cutting Function Flat!"); //
Return False;
}
}
IF (m_bdegunit == True)
* Result = * result / 180 * pi;
}
Else IF (StricsP (FuncName, "Asin") == 0 ||
Stricmp (FuncName, "ACOS") == 0)
{
IF (FABS (* Result)> 1.0)
{
//
Message ("" "The absolute value of the argument of the anti-sinus string function and the anti-string function must be less than 1!");
Return False;
}
}
Else IF (Stricmp (FuncName, "SQRT") == 0)
{
IF (* Result <0.0)
{
Message ("You can't open the number!"); //
Return False;
}
}
Else IF (FuncName, "LOG") == 0 ||
Stricmp (funcname, "log10") == 0)
{
IF (* Result <= 0.0)
{
Message ("Negative and zero is not logged!"); //
Return False;
}
}
IF (GetFunIndex (FuncName, & Num))
* Result = (* Funtable [NUM]) (* Result);
Else
{
m_ierrflag = 2;
Return False;
}
}
Else
Return False;
IF (paraNum == 1)
{
// If it is a reverse triangle function, the arc is converted into degrees.
IF (StricMP (FuncName, "Asin") == 0 ||
Stricmp (FuncName, "ACOS") == 0 ||
Stricmp (FuncName, "Atan") == 0)
{
IF (m_bdegunit == True)
* Result = * result * 180 / pi;
}
Return True;
}
}
IF (level7 (result)! = true)
Return False;
Return True;
}
// Brackets and function processing
Bool CEXPIRESSION :: Level7 (Double * Result)
{
// If the obtained unit is parenthery
IF ((* m_STRTOKEN == '(') && (m_ctoke == delimiter))
{
// Jump in parentheses, get the first unit in parentheses
IF (getToken () == true)
{
// Recursive call, complete expressions within parentheses
IF (Level2 (RESULT)! = TRUE
Return False;
// The current symbol should be ')', otherwise an error
IF (* m_strtoken! = ')')
{
m_ierrflag = 3;
Return False;
}
// Skip symbol ')'
IF (gettoken ()! = TRUE)
{
m_ierrflag = 3;
Return False;
}
}
Else
{
m_ierrflag = 2; // m_ierrflag = 1; Return False;
}
}
/ / Otherwise, it must be variables or constants
Else
{
// Number of variables or constants
IF (Primitive (Result)! = TRUE)
{
m_ierrflag = 2;
Return False;
}
Else
Return True;
}
Return True;
}
Bool Cexpression :: getFunIndex (const char * name, int * index)
{
INT I;
For (i = 0; i { IF (strCMP (FunnameTable [i], name) == 0) { * index = i; Return True; } } Return False; } // Remove the expression to TOKEN, call in Level1. Void CEXPRESSION :: Putback () { CHAR * T; // Turn token to the expression T = m_STRTOKEN; For (; * t; t ) m_strexp--; } //Negate Void CEXPID :: Unary (Char O, Double * R) { IF (o == '-') * r = - (* r); } Bool CEXPIRESSION :: Arith (Char O, Double * R, Double * H) { Int T; Double EX; Switch (O) { Case '-': * r = * r - * h; Break; Case ' ': * r = * r * h; Break; Case '*': * r = * r * * h; Break; Case '/': IF (Fabs (* H) <0.00000001) { Message ("The division is zero!"); // Return False; } * r = (* r) / (* h); Break; Case '%': T = (int) ((* r) / (* h)); * r = * r- t * (* h); Break; Case '^': // Original processing If the index is a decimal, the result is very large. EX = * r; IF (FABS (* H) <1e-9) { * r = 1.0; Break; } IF (Fabs (* h - floor (* h)) <0.01 || Fabs (* H - CEIL (* H)) <0.01) { For (t = (int) (* h) - 1; t> 0; t -) * r = (* r) * EX; } Else * r = POW (* r, * h); Break; } Return True; } // Take variables or constant values BOOL CEXPIRESSION :: Primitive (double * result) { IF (strcmp (m_strtoken, ") == 0) Return True; //constant IF (m_ctokentype == number) { / Saunch transformation into real numbers * Result = ATOF (m_strtoken); // get the next unit IF (gettoken ()! = TRUE) Return False; Return True; } //variable Else if (m_ctoke == variable) { IF (GetVarvalue (M_STRTOKEN, RESULT)! = TRUE) Return False; // get the next unit IF (gettoken ()! = TRUE) Return False; Return True; } Return False; } Bool Cexpression :: getVarvalue (const char * n, double * result) { List For (iter = m_varlist.m_varlist.begin (); it! = m_varlist.m_varlist.end (); iter ) { IF (* ip) -> m_strname == n) { * Result = (* ip) -> m_dvalue; Return True; } } Return False; } / / Get the index value of the variable in the variable table Bool Cexpression :: getvarindex (const char * name, int * index) { INT i = 0; List For (iter = m_varlist.m_varlist.begin (); it! = m_varlist.m_varlist.end (); iter ) { IF ((* ip) -> m_strname == name) { * index = i; Return True; } i ; } Return False; } Bool CEXPIRESSION :: UpdateslaveVar () { Bool Bret = True; List For (iter = m_varlist.m_varlist.begin (); it! = m_varlist.m_varlist.end (); iter ) { IF ((* iter) -> m_strslave! = "") { Double Dresult = m_dresult; Char * strexp = m_strexp; String str = (* ip) -> m_strslave; m_strexp = (char *) Str.c_str (); (* iTer) -> m_strslave = ""; Bret = CALEXP (); IF (Bret == False) { String prompt = (* ip) -> m_strname; PROMPT = "Definition Error!"; Message (prompt.c_str ()); Return False; Else { (* iTer) -> m_dvalue = m_dresult; } m_dresult = DRESULT; m_strexp = strexp; } } Return True; }