YStatement ProcessStatement(IfStatementSyntax ifStatement) { YExpr condition = ProcessExpr(ifStatement.Condition); YStatement statement = ProcessStatement(ifStatement.Statement); YStatement elseStatement = ProcessStatement(ifStatement.Else.Statement); return(new YIf(condition, statement, elseStatement)); }
/// <summary> /// Unwrap statement to string. /// </summary> static public void AppendEx(this StringBuilder builder, YStatement statement) { if (statement is YBlock) { var block = (YBlock)statement; builder.Append("{"); foreach (var s in block.Statements) { AppendEx(builder, s); } builder.Append("}"); } else if (statement is YReturn) { var @return = (YReturn)statement; builder.Append("return "); AppendEx(builder, @return.Value); builder.Append(";"); } else if (statement is YExprStatement) { AppendEx(builder, ((YExprStatement)statement).Expression); builder.Append(";"); } else if (statement is YIf) { var @if = (YIf)statement; builder.Append("if ("); AppendEx(builder, @if.Condition); builder.Append(")"); AppendEx(builder, @if.Statement); if (@if.ElseStatement != null) { builder.Append(" else "); AppendEx(builder, @if.ElseStatement); } } }
public YIf(YExpr condition, YStatement statement, YStatement elseStatement) { Condition = condition; Statement = statement; ElseStatement = elseStatement; }