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


C# Lexer.Next方法代码示例

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


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

示例1: ParseBinaryOperationRHS

        // BinaryOperationRHS ::= ('+' primary)*
        private Expression ParseBinaryOperationRHS(Lexer lexer, int previousPrecedence, Expression LHS)
        {
            while (true)
            {
                // get current token and find its precedence
                var currentToken = lexer.Next();
                int currentPrecedence = GetTokenPrecedence(currentToken);

                // if the current precedence is less that the previous, return LHS as it is
                if (currentPrecedence < previousPrecedence)
                {
                    lexer.UnGet(currentToken);
                    return LHS;
                }

                var operation = (currentToken as BinaryOperatorLexToken).Value();
                // otherwise, parse out the RHS
                var RHS = ParsePrimary(lexer);
                if (RHS == null)
                {
                    return null;
                }

                // If BinOp binds less tightly with RHS than the operator after RHS, let
                // the pending operator take RHS as its LHS.
                var tokenAfterRHS = lexer.Next();
                lexer.UnGet(tokenAfterRHS);
                var afterRHSPrecendence = GetTokenPrecedence(tokenAfterRHS);
                if (currentPrecedence < afterRHSPrecendence)
                {
                    RHS = ParseBinaryOperationRHS(lexer, currentPrecedence + 1, RHS);
                }

                // merge LHS and RHS
                LHS = new BinaryOperatorExpression(operation, LHS, RHS);
            }
        }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:38,代码来源:Parser.cs

示例2: ParseParenExpression

 // ParenExpression ::= '(' expression ')'
 public Expression ParseParenExpression(Lexer lexer)
 {
     var current = lexer.Next();
     if (current is LeftParenLexToken)
     {
         // dont put current baack
         var insideParens = ParseExpression(lexer);
         if (insideParens == null)
         {
             throw new SyntaxException("Should have a valid expression inside the parens");
         }
         current = lexer.Next();
         if (current is RightParenLexToken)
         {
             return insideParens;
         }
         else
         {
             throw new SyntaxException("expecting a right paren");
         }
     }
     else
     {
         lexer.UnGet(current);
         return null;
     }
 }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:28,代码来源:Parser.cs

示例3: ParsePrimary

        // Primary
        //   ::= IntegerExpression
        ///   ::= ParenExpression
        ///   ::= IdentifierExpression
        public Expression ParsePrimary(Lexer lexer)
        {
            var current = lexer.Next();
            lexer.UnGet(current);

            if (current == null)
                throw new SyntaxException($"something is wrong here");
            else if (current is NumberLexToken)
                return ParseIntegerExpression(lexer);
            else if (current is LeftParenLexToken)
                return ParseParenExpression(lexer);
            else
                return null;
        }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:18,代码来源:Parser.cs

示例4: ParseIntegerExpression

 // IntegerExpression ::= {integer}
 public IntegerExpression ParseIntegerExpression(Lexer lexer)
 {
     var current = lexer.Next();
     if (current is NumberLexToken)
     {
         return new IntegerExpression((current as NumberLexToken).IntValue());
     }
     else
     {
         lexer.UnGet(current);
         return null;
     }
 }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:14,代码来源:Parser.cs


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