예제 #1
0
        public override void Print(Output output)
        {
            output.Print("else");

            if (m_statements.Count == 1 && m_statements[0] is IfThenEndBlock)
            {    
                m_statements[0].Print(output);
            }
            else if (m_statements.Count == 2 && m_statements[0] is IfThenElseBlock && m_statements[1] is ElseEndBlock)
            {
                m_statements[0].Print(output);
                m_statements[1].Print(output);
            }
            else
            {
                output.PrintLine();

                output.IncreaseIndent();

                Statement.PrintSequence(output, m_statements);

                output.DecreaseIndent();
                
                output.Print("end");
            }
        }
예제 #2
0
        public override void Print(Output output)
        {
            output.Print("for ");
            m_r.GetTarget(m_register + 3, Begin - 1).Print(output);
            output.Print(" = ");
            m_r.GetValue(m_register, Begin - 1).Print(output);
            output.Print(", ");
            m_r.GetValue(m_register + 1, Begin - 1).Print(output);

            var step = m_r.GetValue(m_register + 2, Begin - 1);

            if (!step.IsInteger || step.AsInteger() != 1)
            {
                output.Print(", ");
                step.Print(output);
            }

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("end");
        }
예제 #3
0
        public override void Print(Output output)
        {
            output.Print("if ");

            m_branch.AsExpression(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 (m_statements.Count == 1 && m_statements[0] is Break)
            {
                var b = m_statements[0] as Break;

                if (b.Target == m_loopback)
                {
                    output.DecreaseIndent();
                    return;
                }
            }

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            if (m_emptyElse)
            {
                output.PrintLine("else");
                output.PrintLine("end");
            }
        }
예제 #4
0
        public override void Print(Output output)
        {
            output.PrintLine("while true do");
            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();
            output.Print("end");
        }
예제 #5
0
        public override void Print(Output output)
        {
            output.Print("repeat");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("until ");
            m_branch.AsExpression(m_r).Print(output);
        }
예제 #6
0
        public override void Print(Output output)
        {
            /* extra return statement */
            var last = m_statements.Count - 1;

            if (last < 0 || !(m_statements[last] is Return))
            {
                throw new InvalidOperationException(m_statements[last].ToString());
            }

            // this doesn't seem like appropriate behavior???
            m_statements.RemoveAt(last);

            Statement.PrintSequence(output, m_statements);
        }
예제 #7
0
        public override void Print(Output output)
        {
            output.Print("for ");

            m_r.GetTarget(m_register + 3, Begin - 1).Print(output);

            var n = m_register + 2 + m_length;

            for (int r1 = m_register + 4; r1 <= n; r1++)
            {
                output.Print(", ");
                m_r.GetTarget(r1, Begin - 1).Print(output);
            }

            output.Print(" in ");

            Expression value = null;

            value = m_r.GetValue(m_register, Begin - 1);
            value.Print(output);

            // TODO: Optimize code
            if (!value.IsMultiple)
            {
                output.Print(", ");

                value = m_r.GetValue(m_register + 1, Begin - 1);
                value.Print(output);

                if (!value.IsMultiple)
                {
                    output.Print(", ");

                    value = m_r.GetValue(m_register + 2, Begin - 1);
                    value.Print(output);
                }
            }

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();
            output.Print("end");
        }
예제 #8
0
        public override void Print(Output output)
        {
            output.Print("while ");

            m_branch.AsExpression(m_registers).Print(output);

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("end");
        }