예제 #1
0
        public static ThreadNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "thread");
            AstNode node = StatementNode.Parse(parser);

            return(new ThreadNode(node));
        }
예제 #2
0
        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "for");
            parser.ExpectToken(TokenType.Parentheses, "(");
            AstNode left      = StatementNode.Parse(parser);
            AstNode predicate = StatementNode.Parse(parser);
            AstNode right     = StatementNode.Parse(parser);

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

            return(new ForNode(left, predicate, right, forBody));
        }
예제 #3
0
        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "foreach");
            parser.ExpectToken(TokenType.Parentheses, "(");
            AstNode needle = StatementNode.Parse(parser);

            parser.ExpectToken(TokenType.Identifier, "in");
            AstNode haystack = StatementNode.Parse(parser);

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

            return(new ForEachNode(needle, haystack, forBody));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
        }
예제 #6
0
        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier, "if");
            parser.ExpectToken(TokenType.Parentheses, "(");
            AstNode predicate = ExpressionNode.Parse(parser);

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

            if (parser.AcceptToken(TokenType.Identifier, "else"))
            {
                AstNode elseBody = StatementNode.Parse(parser);
                return(new IfNode(predicate, ifBody, elseBody));
            }

            return(new IfNode(predicate, ifBody));
        }
예제 #7
0
        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));
        }
예제 #8
0
        public static AstNode Parse(Parser.Parser parser)
        {
            parser.ExpectToken(TokenType.Identifier);

            return(new ReturnNode(StatementNode.Parse(parser)));
        }