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


C# Parser.MatchToken方法代码示例

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


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

示例1: Parse

 public static AstNode Parse(Parser parser)
 {
     parser.ExpectToken(Lexer.TokenType.Identifier, "PAUSE");
     if (parser.MatchToken(Lexer.TokenType.String) || parser.MatchToken(Lexer.TokenType.Number))
         return new PauseNode((string)parser.ReadToken().Value);
     else
         return new PauseNode("PRESS ANY KEY TO CONTINUE...");
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:8,代码来源:PauseNode.cs

示例2: Parse

 public static AstNode Parse(Parser.Parser parser)
 {
     if (parser.MatchToken(TokenType.Identifier, "if"))
         return IfNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "while"))
         return WhileNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "for"))
         return ForNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "foreach"))
         return ForEachNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "try"))
         return TryNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "func"))
         return FuncNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "thread"))
         return ThreadNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Identifier, "return"))
         return ReturnNode.Parse(parser);
     else if (parser.MatchToken(TokenType.Brace, "{"))
         return CodeBlock.Parse(parser);
     else
     {
         AstNode expr = ExpressionNode.Parse(parser);
         parser.ExpectToken(TokenType.EndOfLine);
         return expr;
     }
 }
开发者ID:zdimension,项目名称:Hassium,代码行数:27,代码来源:StatementNode.cs

示例3: parseFunctionCall

 private static AstNode parseFunctionCall(Parser parser, AstNode left)
 {
     if (parser.MatchToken(TokenType.Parentheses, "("))
         return parseFunctionCall(parser, new FunctionCallNode(left, ArgListNode.Parse(parser)));
     else
         return left;
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:7,代码来源:ExpressionNode.cs

示例4: Parse

        public static AstNode Parse(Parser parser)
        {
            parser.ExpectToken(Lexer.TokenType.Identifier, "IF");
            AstNode predicate = ExpressionNode.Parse(parser);
            AstNode body = StatementNode.Parse(parser);

            if (parser.MatchToken(Lexer.TokenType.Identifier, "ELSE"))
                return new ConditionalNode(predicate, body, StatementNode.Parse(parser));

            return new ConditionalNode(predicate, body);
        }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:11,代码来源:ConditionalNode.cs

示例5: Parse

        public static ArrayIndexerNode Parse(Parser.Parser parser)
        {
            var ret = new ArrayIndexerNode();
            parser.ExpectToken(TokenType.Bracket, "[");

            while (!parser.MatchToken(TokenType.Bracket, "]"))
            {
                ret.Children.Add(ExpressionNode.Parse(parser));
            }
            parser.ExpectToken(TokenType.Bracket, "]");

            return ret;
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:13,代码来源:ArrayGetNode.cs

示例6: Parse

        public static AstNode Parse(Parser.Parser parser)
        {
            CodeBlock block = new CodeBlock();
            parser.ExpectToken(TokenType.Brace, "{");

            while (!parser.EndOfStream && !parser.MatchToken(TokenType.Brace, "}"))
            {
                block.Children.Add(StatementNode.Parse(parser));
            }

            parser.ExpectToken(TokenType.Brace, "}");
            return block;
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:13,代码来源:CodeBlock.cs

示例7: Parse

        public static ArgListNode Parse(Parser parser)
        {
            ArgListNode ret = new ArgListNode();
            parser.ExpectToken(TokenType.Parentheses, "(");

            while (!parser.MatchToken(TokenType.Parentheses, ")"))
            {
                ret.Children.Add(ExpressionNode.Parse(parser));
                if (!parser.AcceptToken(TokenType.Comma))
                    break;
            }

            parser.ExpectToken(TokenType.Parentheses, ")");

            return ret;
        }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:16,代码来源:ArgListNode.cs

示例8: Parse

        public static ArrayInitializerNode Parse(Parser parser)
        {
            var ret = new ArrayInitializerNode();
            parser.ExpectToken(TokenType.Bracket, "[");

            while (!parser.MatchToken(TokenType.Bracket, "]"))
            {
                ret.Children.Add(ExpressionNode.Parse(parser));
                if (!parser.AcceptToken(TokenType.Comma))
                {
                    break;
                }
            }
            parser.ExpectToken(TokenType.Bracket, "]");

            return ret;
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:17,代码来源:ArrayInitializerNode.cs

示例9: Parse

        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "func");
            string name = parser.ExpectToken(TokenType.Identifier).Value.ToString();
            parser.ExpectToken(TokenType.Parentheses, "(");

            List<string> result = new List<string>();
            while (parser.MatchToken(TokenType.Identifier))
            {
                result.Add(parser.ExpectToken(TokenType.Identifier).Value.ToString());
                if (!parser.AcceptToken(TokenType.Comma))
                    break;
            }

            parser.ExpectToken(TokenType.Parentheses, ")");
            AstNode body = StatementNode.Parse(parser);

            return new FuncNode(name, result, body);
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:19,代码来源:FuncNode.cs

示例10: Parse

 public static AstNode Parse(Parser parser)
 {
     if (parser.MatchToken(Lexer.TokenType.Identifier, "IF"))
         return ConditionalNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "WHILE"))
         return WhileNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "PRINT"))
         return PrintNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "INPUT"))
         return InputNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "LET"))
         return LetNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "GOTO"))
         return GotoNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "CLS"))
         return ClsNode.Parse(parser);
     else if (parser.MatchToken(Lexer.TokenType.Identifier, "PAUSE"))
         return PauseNode.Parse(parser);
     else
         return ExpressionNode.Parse(parser);
 }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:21,代码来源:StatementNode.cs

示例11: 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

示例12: 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

示例13: 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

示例14: 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

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