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


C# Parser.CurrentToken方法代码示例

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


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

示例1: Parse

        public static AstNode Parse(Parser parser)
        {
            parser.ExpectToken(Lexer.TokenType.Identifier, "GOTO");

            AstNode position = ExpressionNode.Parse(parser);

            if (position is NumberNode)
                return new GotoNode(Convert.ToString(((NumberNode)position).Value));
            else if (position is IdentifierNode)
                return new GotoNode(((IdentifierNode)position).Identifier);
            else
                throw new Exception("Unknown type " + parser.CurrentToken().TokenType + " " + parser.CurrentToken().Value);
        }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:13,代码来源:GotoNode.cs

示例2: parseComparison

 private static AstNode parseComparison(Parser parser)
 {
     AstNode left = parseFunctionCall(parser);
     while (parser.MatchToken(TokenType.Comparison))
     {
         switch ((string)parser.CurrentToken().Value)
         {
             case ">":
                 parser.AcceptToken(TokenType.Comparison);
                 left = new BinaryOpNode(BinaryOperation.GreaterThan, left, parseFunctionCall(parser));
                 continue;
             case "<":
                 parser.AcceptToken(TokenType.Comparison);
                 left = new BinaryOpNode(BinaryOperation.LessThan, left, parseFunctionCall(parser));
                 continue;
             default:
                 break;
         }
         break;
     }
     return left;
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:22,代码来源:ExpressionNode.cs

示例3: parseAdditive

 private static AstNode parseAdditive(Parser parser)
 {
     AstNode left = parseMultiplicitive(parser);
     while (parser.MatchToken(TokenType.Operation))
     {
         switch ((string)parser.CurrentToken().Value)
         {
             case "+":
                 parser.AcceptToken(TokenType.Operation);
                 left = new BinaryOpNode(BinaryOperation.Addition, left, parseMultiplicitive(parser));
                 continue;
             case "-":
                 parser.AcceptToken(TokenType.Operation);
                 left = new BinaryOpNode(BinaryOperation.Subtraction, left, parseMultiplicitive(parser));
                 continue;
             default:
                 break;
         }
         break;
     }
     return left;
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:22,代码来源:ExpressionNode.cs

示例4: parseMultiplicitive

 private static AstNode parseMultiplicitive(Parser parser)
 {
     AstNode left = parseComparison(parser);
     while (parser.MatchToken(TokenType.Operation))
     {
         switch ((string)parser.CurrentToken().Value)
         {
             case "*":
                 parser.AcceptToken(TokenType.Operation);
                 left = new BinaryOpNode(BinaryOperation.Multiplication, left, parseComparison(parser));
                 continue;
             case "/":
                 parser.AcceptToken(TokenType.Operation);
                 left = new BinaryOpNode(BinaryOperation.Division, left, parseComparison(parser));
                 continue;
             case "%":
                 parser.AcceptToken(TokenType.Operation);
                 left = new BinaryOpNode(BinaryOperation.Modulus, left, parseComparison(parser));
                 continue;
             case "=":
                 parser.AcceptToken(TokenType.Assignment);
                 left = new BinaryOpNode(BinaryOperation.Assignment, left, parseComparison(parser));
                 continue;
             default:
                 break;
         }
         break;
     }
     return left;
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:30,代码来源:ExpressionNode.cs

示例5: parseTerm

        private static AstNode parseTerm(Parser parser)
        {
            if ((string)parser.CurrentToken(1).Value == ":")
            {
                LabelNode lnode;
                if (parser.MatchToken(TokenType.Identifier))
                    lnode = new LabelNode((string)parser.ExpectToken(TokenType.Identifier).Value);
                else if (parser.MatchToken(TokenType.Number))
                    lnode = new LabelNode(Convert.ToString(parser.ExpectToken(TokenType.Number).Value));
                else
                    throw new Exception("Unknown label type " + parser.CurrentToken().TokenType + " " + parser.CurrentToken().Value);

                parser.ExpectToken(TokenType.Identifier, ":");
                return lnode;
            }
            else if (parser.MatchToken(TokenType.Number))
                return new NumberNode(Convert.ToDouble(parser.ExpectToken(TokenType.Number).Value));
            else if (parser.AcceptToken(TokenType.Parentheses, "("))
            {
                AstNode statement = ExpressionNode.Parse(parser);
                parser.ExpectToken(TokenType.Parentheses, ")");
                return statement;
            }
            else if (parser.MatchToken(TokenType.Identifier, "THEN"))
            {
                CodeBlockNode block = new CodeBlockNode();
                parser.ExpectToken(TokenType.Identifier, "THEN");

                while (!parser.EndOfStream && !parser.MatchToken(TokenType.Identifier, "ENDIF") && !parser.MatchToken(TokenType.Identifier, "ELSE"))
                    block.Children.Add(StatementNode.Parse(parser));

                if (parser.MatchToken(TokenType.Identifier, "ELSE"))
                    return block;

                parser.ExpectToken(TokenType.Identifier, "ENDIF");

                return block;
            }
            else if (parser.MatchToken(TokenType.Identifier, "ELSE"))
            {
                parser.ExpectToken(TokenType.Identifier, "ELSE");
                return StatementNode.Parse(parser);
            }
            else if (parser.MatchToken(TokenType.Identifier, "DO"))
            {
                CodeBlockNode block = new CodeBlockNode();
                parser.ExpectToken(TokenType.Identifier, "DO");

                while (!parser.EndOfStream && !parser.MatchToken(TokenType.Identifier, "WEND"))
                    block.Children.Add(StatementNode.Parse(parser));

                parser.ExpectToken(TokenType.Identifier, "WEND");

                return block;
            }
            else if (parser.AcceptToken(TokenType.Identifier, "END"))
            {
                if (parser.MatchToken(TokenType.Number))
                    return new EndNode(Convert.ToInt32(parser.ExpectToken(TokenType.Number).Value));
                else
                    return new EndNode();
            }
            else if (parser.MatchToken(TokenType.String))
                return new StringNode((string)parser.ExpectToken(TokenType.String).Value);
            else if (parser.MatchToken(TokenType.Identifier))
                return new IdentifierNode((string)parser.ExpectToken(TokenType.Identifier).Value);
            else
                throw new Exception("Unexpected " + parser.CurrentToken().TokenType + " in Parser: " + parser.CurrentToken().Value + ".");
        }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:69,代码来源:ExpressionNode.cs

示例6: ParseTerm

 private static AstNode ParseTerm(Parser.Parser parser)
 {
     if (parser.MatchToken(TokenType.Number))
     {
         return new NumberNode(Convert.ToDouble(parser.ExpectToken(TokenType.Number).Value));
     }
     else if (parser.AcceptToken(TokenType.Parentheses, "("))
     {
         AstNode statement = ExpressionNode.Parse(parser);
         parser.ExpectToken(TokenType.Parentheses, ")");
         return statement;
     }
     else if (parser.AcceptToken(TokenType.Bracket, "["))
     {
         AstNode statement = ArrayInitializerNode.Parse(parser);
         parser.ExpectToken(TokenType.Bracket, "]");
         return statement;
     }
     else if (parser.MatchToken(TokenType.String))
     {
         return new StringNode(parser.ExpectToken(TokenType.String).Value.ToString());
     }
     else if (parser.MatchToken(TokenType.Identifier))
     {
         return new IdentifierNode(parser.ExpectToken(TokenType.Identifier).Value.ToString());
     }
     else
     {
         throw new Exception("Unexpected in Parser: " + parser.CurrentToken().Value);
     }
 }
开发者ID:zdimension,项目名称:Hassium,代码行数:31,代码来源:ExpressionNode.cs


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