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); }
public static CompoundStaNode Parse(TokenString tStr, ref int index) { if (!tStr.Match(index, TokenType.cBraceOpen)) { return(null); } index++; CompoundStaNode node = new CompoundStaNode(); while (!tStr.Match(index, TokenType.cBraceClose)) { var statementNode = Sta.Parse(tStr, ref index); if (statementNode != null) { node.AddStatement(statementNode); } else { index++; } } index++; return(node); }
public static DoLoopStaNode Parse(TokenString tStr, ref int index) { int startIndex = index; if (!tStr.Match(index, TokenType.doStatement, TokenType.cBraceOpen)) { return(null); } index++; StatementNode body = Sta.Parse(tStr, ref index); if (!tStr.Match(index, TokenType.whileStatement, TokenType.rBraceOpen)) { index = startIndex; return(null); } index++; ExpressionNode condition = Exp.Parse(tStr.GetRangeInBrackets(ref index)); if (!tStr.Match(index, TokenType.lineEnd)) { index = startIndex; return(null); } index++; DoLoopStaNode node = new DoLoopStaNode(condition, body); return(node); }
public static ForLoopStaNode Parse(TokenString tStr, ref int index) { int startIndex = index; if (!tStr.Match(index, TokenType.forStatement, TokenType.rBraceOpen)) { return(null); } index++; var forDef = tStr.GetRangeInBrackets(ref index).Split(false, TokenType.lineEnd); if (forDef.Count != 3) { index = startIndex; return(null); } VariableDefExpNode declarations = Exp.Parse(forDef[0]) as VariableDefExpNode; ExpressionNode condition = Exp.Parse(forDef[1]); if (condition == null) { index = startIndex; return(null); } StatementNode body = Sta.Parse(tStr, ref index); ForLoopStaNode node = new ForLoopStaNode(declarations, condition, body); var exps = forDef[2].Split(false, TokenType.comma); foreach (var exp in exps) { node.AddExpression(Exp.Parse(exp)); } return(node); }