Exemplo n.º 1
0
        public static InstructionNode UncodifyInstructionFormat(
            int number,
            Var var)
        {
            if (number < 0)
            {
                throw new InvalidOperationException();
            }

            InstructionNode fakeInstruction;

            if (number == 0)
            {
                fakeInstruction = new UnaryExpressionInstructionNode(
                    var.ToString(),
                    -1);
            }
            else if (number == 1 || number == 2)
            {
                fakeInstruction = new BinaryExpressionInstructionNode(
                    var.ToString(),
                    number == 1 ? "+" : "-");
            }
            else
            {
                var codifiedLabel = number - 2;
                var label         = UncodifyLabel(codifiedLabel);
                fakeInstruction = new ConditionalInstructionNode(
                    var.ToString(),
                    label.ToString(),
                    -1);
            }

            return(fakeInstruction);
        }
Exemplo n.º 2
0
        public void UnaryExpressionInstructionFormat()
        {
            var instruction = new UnaryExpressionInstructionNode("X", 1);

            AssertEqualCodifiedFormat(instruction, 0);
        }