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


C# Parser.Consume方法代码示例

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


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

示例1: Parse

        public override Statement Parse(Parser parser, Lexer.Token current)
        {
            string name = null;

            if (parser.Peek().Type == "IDENTIFIER")
            {
                name = parser.Current.Lexeme;
                parser.Consume("IDENTIFIER");
            }

            parser.Consume("LEFTPAREN");
            var parameters = ParseParameterList(parser).ToArray();
            parser.Consume("RIGHTPAREN");

            var token = parser.Peek();

            if (token.Type == "LEFTBRACE")
            {
                var body = parser.ParseNext();
                return new FunctionDefinitionExpr(new IdentifierExpr(name), parameters, (Statement)body,
                    new IdentifierExpr("UNKNOWN"));
            }
            else if (token.Type == "RIGHTARROW")
            {
                parser.Consume("RIGHTARROW");
                var body = parser.ParseExpression(0);
                parser.Consume("SEMICOLON");
                return new LambdaDefinitionExpr(new IdentifierExpr(name), parameters, body,
                    new IdentifierExpr("UNKNOWN"));
            }

            throw new ParseException("Malformed function defintion");
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:33,代码来源:FunctionDefinitionParselet.cs

示例2: ParseTypeSpecified

        private string ParseTypeSpecified(Parser parser)
        {
            parser.Consume("COLON");

            var type = parser.Current.Lexeme;

            parser.Consume("IDENTIFIER");

            return type;
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:10,代码来源:VariableDeclarationParselet.cs

示例3: Parse

        public override Statement Parse(Parser parser, Lexer.Token current)
        {
            parser.Consume("LEFTPAREN");
            var condition = parser.ParseExpression(0);
            parser.Consume("RIGHTPAREN");

            var trueBlock = ParseStatement(parser);

            var falseBlock = parser.ConsumeOptional("ELSE") ? ParseStatement(parser) : null;

            return new IfStmt(condition, trueBlock, falseBlock);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:12,代码来源:IfParselet.cs

示例4: Parse

        public override Statement Parse(Parser parser, Lexer.Token current)
        {
            string name = parser.Current.Lexeme;
            parser.Consume("IDENTIFIER");

            parser.Consume("LEFTBRACE");

            var statements = parser.ParseNext();

            parser.Consume("RIGHTBRACE");

            return new ClassDefinitionStmt(new IdentifierExpr(name), statements);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:13,代码来源:ClassDefinitionParselet.cs

示例5: Recover

 /// <summary>
 /// <inheritDoc/>
 /// <p>The default implementation resynchronizes the parser by consuming tokens
 /// until we find one in the resynchronization set--loosely the set of tokens
 /// that can follow the current rule.</p>
 /// </summary>
 public virtual void Recover(Parser recognizer, RecognitionException e)
 {
     //		System.out.println("recover in "+recognizer.getRuleInvocationStack()+
     //						   " index="+recognizer.getInputStream().index()+
     //						   ", lastErrorIndex="+
     //						   lastErrorIndex+
     //						   ", states="+lastErrorStates);
     if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.State))
     {
         // uh oh, another error at same token index and previously-visited
         // state in ATN; must be a case where LT(1) is in the recovery
         // token set so nothing got consumed. Consume a single token
         // at least to prevent an infinite loop; this is a failsafe.
         //			System.err.println("seen error condition before index="+
         //							   lastErrorIndex+", states="+lastErrorStates);
         //			System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
         recognizer.Consume();
     }
     lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index;
     if (lastErrorStates == null)
     {
         lastErrorStates = new IntervalSet();
     }
     lastErrorStates.Add(recognizer.State);
     IntervalSet followSet = GetErrorRecoverySet(recognizer);
     ConsumeUntil(recognizer, followSet);
 }
开发者ID:antlr,项目名称:antlr4,代码行数:33,代码来源:DefaultErrorStrategy.cs

示例6: Parse

        public override Statement Parse(Parser parser, Lexer.Token current)
        {
            parser.Consume("LEFTPAREN");
            var condition = parser.ParseExpression(0);
            parser.Consume("RIGHTPAREN");

            var block = ParseStatement(parser);// parser.ParseNext();

            if (!(block is Statement))
                throw new ParseException("Invalid statement in block.");
            /*
            if (!(block is IBlockStatement))
                parser.Consume("SEMICOLON");
            */
            return new WhileStmt(condition, block as Statement);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:16,代码来源:WhileParselet.cs

示例7: Parse

        public IExpression Parse(Parser parser, IExpression left, Token token)
        {
            var thenArm = parser.ParseExpression();
            parser.Consume(TokenType.Colon);
            var elseArm = parser.ParseExpression(Precedence.Conditional - 1);

            return new ConditionalExpression(left, thenArm, elseArm);
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:8,代码来源:ConditionalParselet.cs

示例8: Parse

        public Expression Parse(Parser parser, Expression lhs, Token current)
        {
            var thenExpression = parser.ParseNext();

            parser.Consume("COLON");

            var elseExpression = parser.ParseExpression(Precedence - 1);

            return new ConditionalExpr(lhs, thenExpression, elseExpression);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:10,代码来源:ConditionalParselet.cs

示例9: Parse

        public Expression Parse(Parser parser, Expression lhs, Token current)
        {
            var functionName = ((IdentifierExpr) lhs);

            // we should already be on the leftparen token.
            var arguments = ParseArguments(parser).ToArray();

            parser.Consume("RIGHTPAREN");

            return new FunctionCallExpr(functionName, arguments);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:11,代码来源:FunctionCallParselet.cs

示例10: Parse

        public override Statement Parse(Parser parser, Lexer.Token current)
        {
            var name = parser.Current.Lexeme;

            parser.Consume("IDENTIFIER");

            string type = null;
            if (parser.Peek().Type == "COLON")
                type = ParseTypeSpecified(parser);

            Expression initialValue = null;
            if (parser.ConsumeOptional("ASSIGNMENT"))
                initialValue = parser.ParseExpression(0);
            else if(_constVariables)
                throw  new ParseException("Const variable declarations must have an initialiser.");

            parser.Consume("SEMICOLON");

            return new VarDefinitionStmt(new IdentifierExpr(name), new IdentifierExpr(type), _constVariables, initialValue);
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:20,代码来源:VariableDeclarationParselet.cs

示例11: ParseArguments

        private IEnumerable<Expression> ParseArguments(Parser parser)
        {
            if (parser.Peek().Type == "RIGHTPAREN")
                yield break;

            while (true)
            {
                yield return parser.ParseExpression(0);

                if (parser.Peek().Type == "RIGHTPAREN")
                    yield break;

                parser.Consume("COMMA");
            }
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:15,代码来源:FunctionCallParselet.cs

示例12: Parse

        public override Expression Parse(Parser p, Expression left, Token t)
        {
            var exp = new CallExpr();
            exp.CallTargetExpr = left;
            exp.Position = left.Position;

            if (p.Match(TokenType.RParen))
                return exp;

            do
            {
                exp.ArgumentExprs.Add(p.ParseExpression());
            } while (p.Match(TokenType.Comma));
            p.Consume(TokenType.RParen);

            return exp;
        }
开发者ID:ben-eirich,项目名称:September,代码行数:17,代码来源:Parselet.cs

示例13: Parse

        public IExpression Parse(Parser parser, IExpression left, Token token)
        {
            // Parse the comma-separated arguments until we hit, ")".
            var args = new List<IExpression>();
    
            // There may be no arguments at all.
            if (!parser.Match(TokenType.RightParen))
            {
                do
                {
                    args.Add(parser.ParseExpression());
                } 
                while (parser.Match(TokenType.Comma));
                
                parser.Consume(TokenType.RightParen);
            }

            return new CallExpression(left, args);
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:19,代码来源:CallParselet.cs

示例14: ParseParameterList

        private List<VarDefinitionStmt> ParseParameterList(Parser parser)
        {
            var parameters = new List<VarDefinitionStmt>();

            if (parser.Peek().Type == "RIGHTPAREN")
                return parameters;

            while (true)
            {
                var name = parser.ParseExpression(0);

                if(!(name is IdentifierExpr))
                    throw new ParseException("Expected parameter name");

                Expression type = null;
                if (parser.ConsumeOptional("COLON"))
                {
                    type = parser.ParseExpression(0);

                    if (!(type is IdentifierExpr))
                        throw new ParseException("Expected parameter type");

                }
                else
                {
                    type = new IdentifierExpr("dynamic");
                }

                parameters.Add(new VarDefinitionStmt((IdentifierExpr)name, (IdentifierExpr)type, false, null));

                if (parser.Peek().Type == "RIGHTPAREN")
                    break;

                parser.Consume("COMMA");
            }

            return parameters;
        }
开发者ID:PeterBassett,项目名称:Parser,代码行数:38,代码来源:FunctionDefinitionParselet.cs

示例15: ConsumeUntil

 /// <summary>Consume tokens until one matches the given token set.</summary>
 protected internal virtual void ConsumeUntil(Parser recognizer, IntervalSet set)
 {
     //		System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
     int ttype = ((ITokenStream)recognizer.InputStream).La(1);
     while (ttype != TokenConstants.Eof && !set.Contains(ttype))
     {
         //System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
         //			recognizer.getInputStream().consume();
         recognizer.Consume();
         ttype = ((ITokenStream)recognizer.InputStream).La(1);
     }
 }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:13,代码来源:DefaultErrorStrategy.cs


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