当前位置: 首页>>代码示例>>C#>>正文


C# ITokenizer.ReadNextToken方法代码示例

本文整理汇总了C#中ITokenizer.ReadNextToken方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenizer.ReadNextToken方法的具体用法?C# ITokenizer.ReadNextToken怎么用?C# ITokenizer.ReadNextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITokenizer的用法示例。


在下文中一共展示了ITokenizer.ReadNextToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessParameter

        private string ProcessParameter(ITokenizer tokenizer, string parameterName)
        {
            // the following code produces a parameter that supports Guids. For unknown reasons, NH
            // is supplying the parameter value as an unquoted set of alpha numerics, so, here they are processed
            // until the next token is NOT a dash
            int tokenCount = 0;
            string token = "";
            //string regexDateFormat = GetDateFormatRegex();
            tokenizer.SkipWhiteSpace = false;
            do
            {
                if (tokenizer.Current.Type != TokenType.BlockedText)
                {
                    token +=
                        // TODO: the code below will not work until the parser can retain embedded comments
                        //String.Format("/* {0} */ ", parameterName) +
                        tokenizer.Current.Value;

                    if (tokenizer.Current.Type != TokenType.WhiteSpace)
                        tokenCount++;
                }
                tokenizer.ReadNextToken();
            }
            while (tokenizer.HasMoreTokens && !tokenizer.IsNextToken(Constants.Comma));

            tokenizer.SkipWhiteSpace = true;

            return tokenCount > 1 && !token.StartsWith("'") ? String.Format("'{0}'", token.Trim().ToUpper()) : token;
        }
开发者ID:Bigjono,项目名称:sqlformat,代码行数:29,代码来源:ParameterSubstituter.cs

示例2: DoShuntingYardAlgorithm

        protected string DoShuntingYardAlgorithm(ITokenizer tokenizer)
        {
            // see https://en.wikipedia.org/wiki/Shunting-yard_algorithm for details.

            // - Read a token.
            Token token = tokenizer.ReadNextToken();
            Token lastToken = null;
            bool first = true;
            bool afterOpenParenthesis = false;
            while (token.Type != TokenType.None)
            {
                // - If the token is a number, then add it to the output queue.
                if (IsDigit(token))
                    AddToOutput(token.GetValueAsString());

                // - If the token is a left parenthesis (i.e. "("), then push it onto the stack.
                else if (token.GetValueAsString() == "(")
                    operatorStack.Push(token.GetValueAsString());

                // - If the token is a right parenthesis (i.e. ")"):
                else if (token.GetValueAsString() == ")")
                {
                    //   - Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue.
                    string lastOperation = operatorStack.Peek();
                    while (lastOperation != "(")
                    {
                        AddToOutput(operatorStack.Pop());
                        lastOperation = operatorStack.Peek();
                    }

                    //   - If the stack runs out without finding a left parenthesis, then there are mismatched parenthesis.
                    if (operatorStack.Count == 0)
                        throw new Exception("Invalid Syntax! - Parenthesis mismatch, missing open parenthesis");

                    //   - Pop the left parenthesis from the stack, but not onto the output queue.
                    operatorStack.Pop();

                    // Mark parenthesis flag to avoid false unary operation detection.
                    afterOpenParenthesis = true;
                }

                // - If the token is an operator, o1, then:
                else if (IsOperator(token))
                {
                    string currentOperation = token.GetValueAsString();

                    // check for negation at the beginning of the input formal.
                    if (first && currentOperation == "-")
                    {
                        currentOperation = "m";
                    }
                    // check for plus sign at the beginning of the input formal.
                    else if (first && currentOperation == "+")
                    {
                        currentOperation = "p";
                    }
                    else if (operatorStack.Count > 0)
                    {
                        string lastOperation = operatorStack.Peek();

                        // If parenthesis flag is set avoid false unary operation detection
                        if (!afterOpenParenthesis)
                        {
                            // check for negation direct after a '(' or after another operator.
                            if ((IsOperator(lastOperation) || lastOperation == "(") && currentOperation == "-" && lastOperation != "p" && lastOperation != "m" && !IsDigit(lastToken))
                            {
                                currentOperation = "m";
                            }

                            // check for plus sign direct after a '(' or after another operator.
                            if ((IsOperator(lastOperation) || lastOperation == "(") && currentOperation == "+" && lastOperation != "p" && lastOperation != "m" && !IsDigit(lastToken))
                            {
                                currentOperation = "p";
                            }
                        }

                        //   - while there is an operator token, lastOperation, at the top of the operator stack, and either
                        while (IsOperator(lastOperation))
                        {
                            //     o1 is left-associative and its precedence is less than or equal to that of lastOperation, or
                            //     o1 is right associative, and has precedence less than that of lastOperation,
                            if (IsLeftAssociative(currentOperation) && LessOrEqualPrecedence(currentOperation, lastOperation) ||
                                IsRightAssociative(currentOperation) && LessPrecedence(currentOperation, lastOperation))
                            {
                                //     then pop o2 off the operator stack, onto the output queue;
                                AddToOutput(operatorStack.Pop());

                                if (operatorStack.Count == 0)
                                    break;
                                else
                                    lastOperation = operatorStack.Peek();
                            }
                            else
                                break;
                        }
                    }
                        
                    //   - push o1 onto the operator stack.
                    operatorStack.Push(currentOperation);

//.........这里部分代码省略.........
开发者ID:MacTee,项目名称:Shunting-Yard-Algorithm,代码行数:101,代码来源:InfixToPostfixConverter.cs


注:本文中的ITokenizer.ReadNextToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。