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


C# Parser.AcceptToken方法代码示例

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


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

示例1: parseAssignment

        private static AstNode parseAssignment(Parser parser)
        {
            AstNode left = parseAdditive(parser);

            if (parser.AcceptToken(TokenType.Assignment))
                return new BinaryOpNode(BinaryOperation.Assignment, left, parseAssignment(parser));
            else if (parser.AcceptToken(TokenType.Comparison, "=="))
                return new BinaryOpNode(BinaryOperation.Equals, left, parseAssignment(parser));
            else
                return left;
        }
开发者ID:JacobMisirian,项目名称:LittleBASIC,代码行数:11,代码来源:ExpressionNode.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: Parse

        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "try");
            AstNode tryBody = StatementNode.Parse(parser);
            parser.ExpectToken(TokenType.Identifier, "catch");
            AstNode catchBody = StatementNode.Parse(parser);

            if (parser.AcceptToken(TokenType.Identifier, "finally"))
            {
                AstNode finallyBody = StatementNode.Parse(parser);
                return new TryNode(tryBody, catchBody, finallyBody);
            }

            return new TryNode(tryBody, catchBody);
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:15,代码来源:TryNode.cs

示例5: Parse

        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "while");
            parser.ExpectToken(TokenType.Parentheses, "(");
            AstNode predicate = ExpressionNode.Parse(parser);
            parser.ExpectToken(TokenType.Parentheses, ")");
            AstNode whileBody = StatementNode.Parse(parser);
            if (parser.AcceptToken(TokenType.Identifier, "else"))
            {
                AstNode elseBody = StatementNode.Parse(parser);
                return new WhileNode(predicate, whileBody, elseBody);
            }

            return new WhileNode(predicate, whileBody);
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:15,代码来源:WhileNode.cs

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

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

示例8: ParseAdditive

        private static AstNode ParseAdditive(Parser.Parser parser)
        {
            AstNode left = ParseMultiplicative(parser);

            if (parser.AcceptToken(TokenType.Operation, "+"))
            {
                AstNode right = ParseAdditive(parser);
                return new BinOpNode(BinaryOperation.Addition, left, right);
            }
            else if (parser.AcceptToken(TokenType.Operation, "-"))
            {
                AstNode right = ParseAdditive(parser);
                return new BinOpNode(BinaryOperation.Subtraction, left, right);
            }
            else
            {
                return left;
            }
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:19,代码来源:ExpressionNode.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: 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

示例11: ParseFunctionCall

 private static AstNode ParseFunctionCall(Parser.Parser parser, AstNode left)
 {
     if (parser.AcceptToken(TokenType.Parentheses, "("))
     {
         return ParseFunctionCall(parser, new FunctionCallNode(left, ArgListNode.Parse(parser)));
     }
     else if (parser.AcceptToken(TokenType.Bracket, "["))
     {
         return ParseFunctionCall(parser, new ArrayGetNode(left, ArrayIndexerNode.Parse(parser)));
     }
     else
     {
         return left;
     }
 }
开发者ID:zdimension,项目名称:Hassium,代码行数:15,代码来源:ExpressionNode.cs

示例12: ParseMultiplicative

        private static AstNode ParseMultiplicative(Parser.Parser parser)
        {
            AstNode left = ParseUnary(parser);

            if (parser.AcceptToken(TokenType.Operation, "*"))
            {
                AstNode right = ParseMultiplicative(parser);
                return new BinOpNode(BinaryOperation.Multiplication, left, right);
            }
            else if (parser.AcceptToken(TokenType.Operation, "/"))
            {
                AstNode right = ParseMultiplicative(parser);
                return new BinOpNode(BinaryOperation.Division, left, right);
            }
            else  if (parser.AcceptToken(TokenType.Operation, "%"))
            {
                AstNode right = ParseMultiplicative(parser);
                return new BinOpNode(BinaryOperation.Modulus, left, right);
            }
            else
            {
                return left;
            }
        }
开发者ID:zdimension,项目名称:Hassium,代码行数:24,代码来源: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 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

示例15: ParseUnary

 private static AstNode ParseUnary(Parser.Parser parser)
 {
     if (parser.AcceptToken(TokenType.UnaryOperation, "!"))
     {
         return new UnaryOpNode(UnaryOperation.Not, ParseUnary(parser));
     }
     else if (parser.AcceptToken(TokenType.Operation, "-"))
     {
         return new UnaryOpNode(UnaryOperation.Negate, ParseUnary(parser));
     }
     else if (parser.AcceptToken(TokenType.UnaryOperation, "~"))
     {
         return new UnaryOpNode(UnaryOperation.Complement, ParseUnary(parser));
     }
     else
     {
         return ParseFunctionCall(parser);
     }
 }
开发者ID:zdimension,项目名称:Hassium,代码行数:19,代码来源:ExpressionNode.cs


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