//--------------------- // Парсер if //--------------------- public static ASTNode ParseIf() { ASTNode branching; GetNextToken(); ASTNode condition = null; if (curTok.token == Tokens.Token.PARENTHESIS_L) { condition = ParseConditionIf(); GetNextToken(); } else { ConsoleHelper.WriteErrorAST("Expected '('", curTok.y, curTok.x); SkipToToken(Tokens.Token.BRACE_L); } ASTNode bodyIf; if (curTok.token == Tokens.Token.BRACE_L) { bodyIf = new BodyMethodAST(ParseBrace(Area.METHOD, isCycleArea)); branching = new ConditionNodeAST(condition, bodyIf); } else { isRawToken = true; bodyIf = MemberMethod(isCycleArea); branching = new ConditionNodeAST(condition, bodyIf); } return(new IfAST(branching)); }
//--------------------- // Парсер while //--------------------- public static ASTNode ParseWhile() { ASTNode condition = null; ASTNode bodyWhile; GetNextToken(); if (curTok.token != Tokens.Token.PARENTHESIS_L) { ConsoleHelper.WriteErrorAST("Expected '('", curTok.y, curTok.x); SkipToToken(Tokens.Token.BRACE_L); } else { condition = ParseConditionIf(); GetNextToken(); } if (curTok.token == Tokens.Token.BRACE_L) { bodyWhile = new BodyMethodAST(ParseBrace(Area.METHOD, true)); } else { bodyWhile = MemberMethod(true); CheckupClosedToken(Tokens.Token.SEMILICON); } return(new WhileAST(condition, bodyWhile)); }
//--------------------- // Парсер for //--------------------- public static ASTNode ParseFor() { GetNextToken(); List <ASTNode> declaredVar = new List <ASTNode>(); ASTNode condition = null; ASTNode postCondition = null; ASTNode body; if (curTok.token == Tokens.Token.PARENTHESIS_L) { declaredVar = ParseDeclaredVarInFor(); condition = ParseConditionFor(); postCondition = ParsePostConditionFor(); } else { ConsoleHelper.WriteErrorAST("Expected '('", curTok.y, curTok.x); } if (curTok.token != Tokens.Token.PARENTHESIS_R) { ConsoleHelper.WriteErrorAST("Expected ')'", curTok.y, curTok.x); } GetNextToken(); if (curTok.token == Tokens.Token.BRACE_L) { body = new BodyMethodAST(ParseBrace(Area.METHOD, true)); } else { body = MemberMethod(false); if (curTok.token != Tokens.Token.SEMILICON) { ConsoleHelper.WriteErrorAST("Expected ';'", curTok.y, curTok.x); } } return(new ForAST(declaredVar, new ConditionNodeAST(condition, body), postCondition)); }