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


C# Parser.ParseExpession方法代码示例

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


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

示例1: Parse

        public Expression Parse(Parser parser, Expression left, Token token)
        {
            var trueExpr = parser.ParseExpession();
            parser.Take(TokenType.Colon);
            var falseExpr = parser.ParseExpession();

            return new TernaryExpression(token, left, trueExpr, falseExpr);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:8,代码来源:ConditionalParselet.cs

示例2: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = false;

            parser.Take(TokenType.LeftParen);

            var expression = parser.ParseExpession();

            parser.Take(TokenType.RightParen);
            parser.Take(TokenType.LeftBrace);

            var branches = new List<SwitchExpression.Branch>();
            BlockExpression defaultBlock = null;

            while (!parser.Match(TokenType.RightBrace))
            {
                var conditions = new List<Expression>();

                while (parser.MatchAndTake(TokenType.Case))
                {
                    var condition = parser.ParseExpession();
                    conditions.Add(condition);

                    parser.Take(TokenType.Colon);
                }

                if (conditions.Count > 0)
                {
                    var block = ParseBlock(parser);
                    var branch = new SwitchExpression.Branch(conditions, block);
                    branches.Add(branch);
                    continue;
                }

                if (parser.MatchAndTake(TokenType.Default))
                {
                    parser.Take(TokenType.Colon);

                    var block = ParseBlock(parser);
                    defaultBlock = block;
                    break;
                }

                var errorToken = parser.Peek();
                throw new MondCompilerException(errorToken.FileName, errorToken.Line, "Expected Case or Default but got {0}", errorToken.Type);
            }

            parser.Take(TokenType.RightBrace);

            return new SwitchExpression(token, expression, branches, defaultBlock);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:51,代码来源:SwitchParselet.cs

示例3: Parse

        public Expression Parse(Parser parser, Token token)
        {
            var values = new List<KeyValuePair<string, Expression>>();

            while (!parser.Match(TokenType.RightBrace))
            {
                var identifier = parser.Take(TokenType.Identifier);

                Expression value;

                if (parser.Match(TokenType.Comma) || parser.Match(TokenType.RightBrace))
                {
                    value = new IdentifierExpression(identifier);
                }
                else
                {
                    parser.Take(TokenType.Colon);
                    value = parser.ParseExpession();
                }

                values.Add(new KeyValuePair<string, Expression>(identifier.Contents, value));

                if (!parser.Match(TokenType.Comma))
                    break;

                parser.Take(TokenType.Comma);
            }

            parser.Take(TokenType.RightBrace);

            return new ObjectExpression(token, values);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:32,代码来源:ObjectParselet.cs

示例4: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            Expression value = null;
            if (!parser.Match(TokenType.Semicolon))
                value = parser.ParseExpession();

            return new ReturnExpression(token, value);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:10,代码来源:ReturnParselet.cs

示例5: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = false;

            parser.Take(TokenType.LeftParen);

            var condition = parser.ParseExpession();

            parser.Take(TokenType.RightParen);

            var block = new ScopeExpression(parser.ParseBlock());
            return new WhileExpression(token, condition, block);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:13,代码来源:WhileParselet.cs

示例6: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = false;

            string name = null;
            var arguments = new List<string>();
            BlockExpression body;

            // optional name
            if (parser.Match(TokenType.Identifier))
            {
                name = parser.Take(TokenType.Identifier).Contents;
            }

            // parse argument list
            parser.Take(TokenType.LeftParen);

            if (!parser.Match(TokenType.RightParen))
            {
                while (true)
                {
                    var identifier = parser.Take(TokenType.Identifier);
                    arguments.Add(identifier.Contents);

                    if (parser.Match(TokenType.RightParen))
                        break;

                    parser.Take(TokenType.Comma);
                }
            }

            parser.Take(TokenType.RightParen);

            // parse body
            if (parser.MatchAndTake(TokenType.Pointy))
            {
                body = new BlockExpression(new List<Expression>
                {
                    new ReturnExpression(token, parser.ParseExpession())
                });
            }
            else
            {
                body = parser.ParseBlock(false);
            }

            return new FunctionExpression(token, name, arguments, body);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:48,代码来源:FunctionParselet.cs

示例7: Parse

        public Expression Parse(Parser parser, Expression left, Token token)
        {
            var args = new List<Expression>();

            if (!parser.MatchAndTake(TokenType.RightParen))
            {
                do
                {
                    args.Add(parser.ParseExpession());
                } while (parser.MatchAndTake(TokenType.Comma));

                parser.Take(TokenType.RightParen);
            }

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

示例8: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = false;

            parser.Take(TokenType.LeftParen);

            Expression initializer = null;
            if (!parser.Match(TokenType.Semicolon))
                initializer = parser.ParseStatement(false);

            if (initializer is IBlockStatementExpression)
                throw new MondCompilerException(token.FileName, token.Line, "For loop initializer can not be block statement");

            parser.Take(TokenType.Semicolon);

            Expression condition = null;
            if (!parser.Match(TokenType.Semicolon))
                condition = parser.ParseExpession();

            parser.Take(TokenType.Semicolon);

            BlockExpression increment = null;
            if (!parser.Match(TokenType.RightParen))
            {
                var statements = new List<Expression>();

                do
                {
                    statements.Add(parser.ParseStatement(false));

                    if (!parser.Match(TokenType.Comma))
                        break;

                    parser.Take(TokenType.Comma);
                } while (true);

                increment = new BlockExpression(token, statements);
            }

            parser.Take(TokenType.RightParen);

            var block = new ScopeExpression(parser.ParseBlock());

            return new ForExpression(token, initializer, condition, increment, block);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:45,代码来源:ForParselet.cs

示例9: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var declarations = new List<VarExpression.Declaration>();

            do
            {
                var identifier = parser.Take(TokenType.Identifier);
                Expression initializer = null;

                if (parser.MatchAndTake(TokenType.Assign))
                {
                    initializer = parser.ParseExpession();
                }

                var declaration = new VarExpression.Declaration(identifier.Contents, initializer);
                declarations.Add(declaration);
            } while (parser.MatchAndTake(TokenType.Comma));

            return new VarExpression(token, declarations);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:22,代码来源:VarParselet.cs

示例10: Parse

        public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
        {
            trailingSemicolon = false;

            var first = true;
            var branches = new List<IfExpression.Branch>();
            IfExpression.Branch elseBranch = null;

            do
            {
                var isDefaultBlock = !first && !parser.MatchAndTake(TokenType.If);
                first = false;

                Expression condition = null;
                if (!isDefaultBlock)
                {
                    parser.Take(TokenType.LeftParen);

                    condition = parser.ParseExpession();

                    parser.Take(TokenType.RightParen);
                }

                var block = new ScopeExpression(parser.ParseBlock());
                var branch = new IfExpression.Branch(condition, block);

                if (isDefaultBlock)
                    elseBranch = branch;
                else
                    branches.Add(branch);

                if (isDefaultBlock)
                    break;
            } while (parser.MatchAndTake(TokenType.Else));

            return new IfExpression(token, branches, elseBranch);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:37,代码来源:IfParselet.cs

示例11: Parse

 public Expression Parse(Parser parser, Token token)
 {
     var expression = parser.ParseExpession();
     parser.Take(TokenType.RightParen);
     return expression;
 }
开发者ID:krixalis,项目名称:Mond,代码行数:6,代码来源:GroupParselet.cs

示例12: Parse

 public Expression Parse(Parser parser, Token token)
 {
     var right = parser.ParseExpession(_precedence);
     return new PrefixOperatorExpression(token, right);
 }
开发者ID:krixalis,项目名称:Mond,代码行数:5,代码来源:PrefixOperatorParselet.cs

示例13: Parse

 public Expression Parse(Parser parser, Expression left, Token token)
 {
     var index = parser.ParseExpession();
     parser.Take(TokenType.RightSquare);
     return new IndexerExpression(token, left, index);
 }
开发者ID:krixalis,项目名称:Mond,代码行数:6,代码来源:IndexerParselet.cs

示例14: Parse

 public Expression Parse(Parser parser, Expression left, Token token)
 {
     var right = parser.ParseExpession(Precedence - (_isRight ? 1 : 0));
     return new BinaryOperatorExpression(token, left, right);
 }
开发者ID:krixalis,项目名称:Mond,代码行数:5,代码来源:BinaryOperatorParselet.cs


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