protected override void TranslateIfStatement(List<string> output, IfStatement ifStatement) { output.Add(this.CurrentTabIndention); output.Add(this.Shorten("if (")); this.TranslateExpression(output, ifStatement.Condition); if (isEgyptian) { output.Add(this.Shorten(") {") + this.NL); } else { output.Add(this.Shorten(")")); output.Add(this.NL); output.Add(this.CurrentTabIndention); output.Add("{"); output.Add(this.NL); } this.CurrentIndention++; this.Translate(output, ifStatement.TrueCode); this.CurrentIndention--; output.Add(this.CurrentTabIndention); output.Add("}"); if (ifStatement.FalseCode.Length > 0) { if (this.isEgyptian) { output.Add(this.Shorten(" else {") + this.NL); } else { output.Add(this.NL); output.Add(this.CurrentTabIndention); output.Add("else"); output.Add(this.NL); output.Add(this.CurrentTabIndention); output.Add("{"); output.Add(this.NL); } this.CurrentIndention++; this.Translate(output, ifStatement.FalseCode); this.CurrentIndention--; output.Add(this.CurrentTabIndention); output.Add("}"); } output.Add(this.NL); }
private void CompileIfStatement(Parser parser, ByteBuffer buffer, IfStatement ifStatement) { this.CompileExpression(parser, buffer, ifStatement.Condition, true); ByteBuffer trueCode = new ByteBuffer(); this.Compile(parser, trueCode, ifStatement.TrueCode); ByteBuffer falseCode = new ByteBuffer(); this.Compile(parser, falseCode, ifStatement.FalseCode); if (falseCode.Size == 0) { if (trueCode.Size == 0) buffer.Add(ifStatement.Condition.FirstToken, OpCode.POP); else { buffer.Add(ifStatement.Condition.FirstToken, OpCode.JUMP_IF_FALSE, trueCode.Size); buffer.Concat(trueCode); } } else { trueCode.Add(null, OpCode.JUMP, falseCode.Size); buffer.Add(ifStatement.Condition.FirstToken, OpCode.JUMP_IF_FALSE, trueCode.Size); buffer.Concat(trueCode); buffer.Concat(falseCode); } }
protected abstract void TranslateIfStatement(List<string> output, IfStatement ifStatement);