Exemplo n.º 1
0
        public static Node Parse(Parser parser)
        {
            ForNode ret = new ForNode();

            parser.ExpectToken(TokenType.Keyword, "for");
            parser.ExpectToken(TokenType.Parentheses, "(");
            ret.Children.Add(ExpressionNode.Parse(parser));
            parser.ExpectToken(TokenType.Semicolon);
            ret.Children.Add(ExpressionNode.Parse(parser));
            parser.ExpectToken(TokenType.Semicolon);
            ret.Children.Add(ExpressionNode.Parse(parser));
            parser.ExpectToken(TokenType.Parentheses, ")");
            ret.Children.Add(StatementNode.Parse(parser));
            return(ret);
        }
Exemplo n.º 2
0
 public static Node Parse(Parser parser)
 {
     if (parser.MatchToken(TokenType.Keyword, "class"))
     {
         return(ClassDeclarationNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "function"))
     {
         return(FunctionDeclarationNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "if"))
     {
         return(IfNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "while"))
     {
         return(WhileNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "for"))
     {
         return(ForNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "return"))
     {
         return(ReturnNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "incfile"))
     {
         return(UseNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Keyword, "enum"))
     {
         return(EnumDeclarationNode.Parse(parser));
     }
     else if (parser.MatchToken(TokenType.Brace, "{"))
     {
         return(ScopeNode.Parse(parser));
     }
     else
     {
         ExpressionNode expr = new ExpressionNode(ExpressionNode.Parse(parser));
         parser.ExpectToken(TokenType.Semicolon);
         return(expr);
     }
 }