public override void Print(Output output) { output.Print("if "); this.m_branch.AsExpression(this.m_r).Print(output); output.Print(" then"); output.PrintLine(); output.IncreaseIndent(); // Handle the case where the "then" is empty in if-then-else. // The jump over the else block is falsely detected as a break. if (this.m_statements.Count == 1 && this.m_statements[0] is Break) { var b = this.m_statements[0] as Break; if (b.Target == this.m_loopback) { output.DecreaseIndent(); return; } } PrintSequence(output, this.m_statements); output.DecreaseIndent(); if (this.m_emptyElse) { output.PrintLine("else"); output.PrintLine("end"); } }
public override void Print(Output output) { output.Print("repeat"); output.PrintLine(); output.IncreaseIndent(); PrintSequence(output, this.m_statements); output.DecreaseIndent(); output.Print("until "); this.m_branch.AsExpression(this.m_r).Print(output); }
public override void Print(Output output) { output.Print("while "); this.m_branch.AsExpression(this.m_registers).Print(output); output.Print(" do"); output.PrintLine(); output.IncreaseIndent(); PrintSequence(output, this.m_statements); output.DecreaseIndent(); output.Print("end"); }
public override void Print(Output output) { output.Print("for "); this.m_r.GetTarget(this.m_register + 3, this.Begin - 1).Print(output); output.Print(" = "); this.m_r.GetValue(this.m_register, this.Begin - 1).Print(output); output.Print(", "); this.m_r.GetValue(this.m_register + 1, this.Begin - 1).Print(output); var step = this.m_r.GetValue(this.m_register + 2, this.Begin - 1); if (!step.IsInteger || step.AsInteger() != 1) { output.Print(", "); step.Print(output); } output.Print(" do"); output.PrintLine(); output.IncreaseIndent(); PrintSequence(output, this.m_statements); output.DecreaseIndent(); output.Print("end"); }
public override void Print(Output output) { output.Print("for "); this.m_r.GetTarget(this.m_register + 3, this.Begin - 1).Print(output); var n = this.m_register + 2 + this.m_length; for (var r1 = this.m_register + 4; r1 <= n; r1++) { output.Print(", "); this.m_r.GetTarget(r1, this.Begin - 1).Print(output); } output.Print(" in "); // TODO: Optimize code this.PrintRecurse(this.m_r.GetValue(this.m_register, this.Begin - 1), output, 1); output.Print(" do"); output.PrintLine(); output.IncreaseIndent(); PrintSequence(output, this.m_statements); output.DecreaseIndent(); output.Print("end"); }
public override void Print(Output output) { this.m_entries.Sort(); this.m_listLength = 1; if (this.m_entries.Count == 0) { output.Print("{}"); } else { var lineBreak = (this.m_isList && this.m_entries.Count > 5) || (this.m_isObject && this.m_entries.Count > 2) || (!this.m_isObject); if (!lineBreak) { foreach (var entry in this.m_entries) { var value = entry.Value; if (!value.IsBrief) { lineBreak = true; break; } } } output.Print("{"); if (lineBreak) { output.PrintLine(); output.IncreaseIndent(); } this.PrintEntry(0, output); if (!this.m_entries[0].Value.IsMultiple) { for (var i = 1; i < this.m_entries.Count; i++) { output.Print(","); if (lineBreak) { output.PrintLine(); } else { output.Print(" "); } this.PrintEntry(i, output); if (this.m_entries[i].Value.IsMultiple) { break; } } } if (lineBreak) { output.PrintLine(); output.DecreaseIndent(); } output.Print("}"); } }