public static StatementNode Parse(TokenString tStr, ref int index) { switch (tStr[index].Type) { case TokenType.cBraceOpen: return(CompoundStaNode.Parse(tStr, ref index)); case TokenType.ifStatement: return(ConditionalStaNode.Parse(tStr, ref index)); case TokenType.doStatement: return(DoLoopStaNode.Parse(tStr, ref index)); case TokenType.whileStatement: return(WhileLoopStaNode.Parse(tStr, ref index)); case TokenType.forStatement: return(ForLoopStaNode.Parse(tStr, ref index)); case TokenType.returnStatement: return(ReturnStaNode.Parse(tStr, ref index)); case TokenType.lineEnd: return(NopStaNode.Parse(tStr, ref index)); default: return(ExpressionStaNode.Parse(tStr, ref index)); } }
public static ConditionalStaNode Parse(TokenString tStr, ref int index) { int startIndex = index; if (!tStr.Match(index, TokenType.ifStatement, TokenType.rBraceOpen)) { return(null); } index++; ExpressionNode condition = Exp.Parse(tStr.GetRangeInBrackets(ref index)); StatementNode ifTrue = Sta.Parse(tStr, ref index); StatementNode ifFalse = null; if (tStr.Match(index, TokenType.elseStatement)) { index++; ifFalse = Sta.Parse(tStr, ref index); } ConditionalStaNode node = new ConditionalStaNode(condition, ifTrue, ifFalse); return(node); }