⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 token.cs

📁 字符串表达式的计算。本程序是一个Window Forms应用程序
💻 CS
📖 第 1 页 / 共 5 页
字号:

                                    }
                                    else
                                    {
                                        // we found a square bracket but we don't have an operand function
                                        lastErrorMessage = "Error in Rule Syntax: Found an open square parenthesis without an operand function";
                                        return;
                                    }
                                    #endregion
                                }
                                else if (c == ']')
                                {
                                    #region Operand Function Handling

                                    squareMatch--;

                                    // we found the end of an operator function
                                    CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;

                                    // add the stop operand token
                                    tokenItems.Add(new TokenItem("]", TokenType.Token_Operand_Function_Stop, true));

                                    // decrement the operand depth
                                    operandFunctionDepth--;

                                    // set the parse states
                                    //opFuncParseState = ParseState.Parse_State_Operand;
                                    opFuncParseState = ParseState.Parse_State_Operator;

                                    // check if we are done with operand function and now need an operator
                                    if (operandFunctionDepth <= 0)
                                    {
                                        operandFunctionDepth = 0;
                                        parseState = ParseState.Parse_State_Operator;
                                    }

                                    // reset the current token
                                    currentToken = "";

                                    #endregion
                                }
                                else if (c == ',')
                                {
                                    #region Command Handling
                                    // create a toke
                                    CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;

                                    // add the delimiter token
                                    tokenItems.Add(new TokenItem(",", TokenType.Token_Operand_Function_Delimiter, true));

                                    // reset the token
                                    currentToken = "";

                                    opFuncParseState = ParseState.Parse_State_Operand;
                                    #endregion
                                }
                                else if (c == '-')
                                {
                                    #region Negative operands
                                    if (String.IsNullOrEmpty(currentToken.Trim()) == true)
                                    {
                                        // we found a negative sign
                                        currentToken += c;
                                    }
                                    else
                                    {
                                        // try and create the new token
                                        currentToken += c;
                                        tokenCreated = CreateTokenItem(currentToken, true, true, out tempParseState, out isError, out lastErrorMessage);
                                        if (isError == true) return;
                                        if (tokenCreated == true)
                                        {
                                            // the new tokens were created

                                            // reset the current token
                                            currentToken = "";

                                            // set the next parse state
                                            opFuncParseState = tempParseState;
                                        }
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region Other Handling
                                    // try and create the new token
                                    currentToken += c;

                                    tokenCreated = CreateTokenItem(currentToken, true, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;

                                    if (tokenCreated  == true)
                                    {
                                        // the new tokens were created

                                        // reset the current token
                                        currentToken = "";

                                        // set the next parse state
                                        opFuncParseState = tempParseState;

                                    }
                                    #endregion
                                }

                                #endregion
                                break;

                            case ParseState.Parse_State_Operator:
                                #region Parse_State_OperandFunction, Parse_State_Operator

                                if (c == '"')
                                {
                                    // we found a quote while looking for an operator...this is a problem
                                    lastErrorMessage = "Error in Rule Syntax: Found a double quote (\") while looking for an operator.";
                                    return;
                                }
                                else if (c == ' ')
                                {
                                    // we found a space while looking for an operator...maybe it's just white space
                                    if (String.IsNullOrEmpty(currentToken.Trim()) == true)
                                    {
                                        // yep, it's just white space; it can be ignored.
                                        currentToken = "";
                                    }
                                    else
                                    {
                                        // we found a space while looking for an operator....this is a problem because
                                        // no operators allow for spaces.
                                        lastErrorMessage = "Error with expression syntax: Found a space while looking for an operator";
                                        return;
                                    }
                                }
                                else if (c == '(')
                                {
                                    // we found an opern parenthesis while searching for an operator....that's a problem
                                    lastErrorMessage = "Error in rule syntax: Found an open parenthesis while searching for an operator";
                                    return;
                                }
                                else if (c == ')')
                                {
                                    // add the closed parenthesis and keep looking for the operator
                                    parenthesisMatch--;
                                    tokenItems.Add(new TokenItem(")", TokenType.Token_Close_Parenthesis, true));
                                }
                                else if (c == '[')
                                {
                                    // we found an open parenthesis while searching for an operator....that's a problem
                                    lastErrorMessage = "Error in rule syntax: Found an open square parenthesis while searching for an operator";
                                    return;
                                }
                                else if (c == ']')
                                {
                                    squareMatch--;
                                    // we found the end of an operator function
                                    CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;

                                    // add the stop operand token
                                    tokenItems.Add(new TokenItem("]", TokenType.Token_Operand_Function_Stop, true));

                                    // decrement the operand depth
                                    operandFunctionDepth--;

                                    // set the parse states
                                    opFuncParseState = ParseState.Parse_State_Operand;

                                    // check if we are done with operand function and now need an operator
                                    if (operandFunctionDepth <= 0)
                                    {
                                        operandFunctionDepth = 0;
                                        parseState = ParseState.Parse_State_Operator;
                                    }

                                    // reset the current token
                                    currentToken = "";
                                }
                                else if (c == ',')
                                {
                                    // we found a comma while searching for an operator....that's alright in an operand function
                                    CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;

                                    // add the comma
                                    tokenItems.Add(new TokenItem(",", TokenType.Token_Operand_Function_Delimiter, true));

                                    // reset the token
                                    currentToken = "";

                                    // set the parse state
                                    opFuncParseState = ParseState.Parse_State_Operand;
                                }
                                else
                                {
                                    // try and create the new token
                                    currentToken += c;
                                    tokenCreated = CreateTokenItem(currentToken, true, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;
                                    if (tokenCreated == true)
                                    {
                                        // the new tokens were created

                                        // reset the current token
                                        currentToken = "";

                                        // set the next parse state
                                        opFuncParseState = ParseState.Parse_State_Operand;

                                    }
                                }

                                #endregion
                                break;

                            case ParseState.Parse_State_Quote:
                                #region Parse_State_OperandFunction, Parse_State_Quote

                                if (c == '"')
                                {
                                    quoteMatch--;

                                    // we found the end of the qoute
                                    currentToken += c;
                                    tokenCreated = CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
                                    if (isError == true) return;
                                    if (tokenCreated == true)
                                    {
                                        // set the next parse state
                                        opFuncParseState = tempParseState;

                                        // clear the current token
                                        currentToken = "";
                                    }
                                }
                                else
                                {
                                    currentToken += c;
                                }

                                #endregion
                                break;
                        }
                        #endregion
                        break;

                    case ParseState.Parse_State_Operator:
                        #region Parse_State_Operator
                        if (c == '"')
                        {
                            #region Quote Handling
                            // we found a quote while looking for an operator...this is a problem
                            lastErrorMessage = "Error in Rule Syntax: Found a double quote (\") while looking for an operator.";
                            return;
                            #endregion
                        }
                        else if (c == ' ')
                        {
                            #region Space Handling
                            // we found a space while looking for an operator...maybe it's just white space
                            if (String.IsNullOrEmpty(currentToken.Trim()) == true)
                            {
                                // yep, it's just white space; it can be ignored.
                                currentToken = "";
                            }
                            else
                            {
                                // we found a space while looking for an operator....this is a problem because
                                // no operators allow for spaces.
                                lastErrorMessage = "Error with expression syntax: Found a space while looking for an operator";
                                return;
                            }
                            #endregion
                        }
                        else if (c == '(')
                        {
                            #region Parenthesis Handling
                            // we found an opern parenthesis while searching for an operator....that's a problem
                            lastErrorMessage = "Error in rule syntax: Found an open parenthesis while searching for an operator";
                            return;
                            #endregion
                        }
                        else if (c == ')')
                        {
                            #region Parenthesis Handling

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -