Пример #1
0
        public node logic_operation(LogicOperationBlock block)
        {
            // Operations 'and', 'or'.
            var @operator = (block.getFieldValue("OP") == "AND") ? "&&" : "||";
            var argument0 = valueToCode(block, "A");
            var argument1 = valueToCode(block, "B");

            if (argument0 == null && argument1 == null)
            {
                // If there are no arguments, then the return value is false.
                argument0 = new false_node(this);
                argument1 = new false_node(this);
            }
            else
            {
                // Single missing arguments have no effect on the return value.
                var defaultArgument = (@operator == "&&") ? (node) new true_node(this) : (node) new false_node(this);
                if (argument0 == null)
                {
                    argument0 = defaultArgument;
                }
                if (argument1 == null)
                {
                    argument1 = defaultArgument;
                }
            }
            if (@operator == "&&")
            {
                return(new and_node(this, argument0, argument1));
            }
            else
            {
                return(new or_node(this, argument0, argument1));
            }
        }
Пример #2
0
        public node controls_if(ControlsIfBlock block)
        {
            // If/elseif/else condition.
            node code = null;

            if (block.elseCount_ != 0)
            {
                code = statementToCode(block, "ELSE");
                if (code == null)
                {
                    code = new nil_node(this);
                }
            }
            for (var n = block.elseifCount_; n >= 0; n--)
            {
                var argument = valueToCode(block, "IF" + n);
                if (argument == null)
                {
                    argument = new false_node(this);
                }
                var branch = statementToCode(block, "DO" + n);
                code = new if_node(this, argument, branch, code, false);
            }
            return(code);
        }
Пример #3
0
        public node procedures_ifreturn(ProceduresIfreturnBlock block)
        {
            // Conditionally return value from a procedure.
            var condition = valueToCode(block, "CONDITION");

            if (condition == null)
            {
                condition = new false_node(this);
            }
            node code = null;

            if (block.hasReturnValue_)
            {
                var value = valueToCode(block, "VALUE");
                if (value == null)
                {
                    value = new nil_node(this);
                }
                code = new return_node(this, value);
            }
            else
            {
                code = new return_node(this, null);
            }
            return(new if_node(this, condition, code, null, false));
        }
Пример #4
0
        public node controls_whileUntil(ControlsWhileUntilBlock block)
        {
            // Do while/until loop.
            var until     = block.getFieldValue("MODE") == "UNTIL";
            var argument0 = valueToCode(block, "BOOL");

            if (argument0 == null)
            {
                argument0 = new false_node(this);
            }
            var branch = statementToCode(block, "DO");

            if (until)
            {
                return(new until_node(this, argument0, branch));
            }
            else
            {
                return(new while_node(this, argument0, branch));
            }
        }
Пример #5
0
        public node logic_ternary(LogicTernaryBlock block)
        {
            // Ternary operator.
            var value_if = valueToCode(block, "IF");

            if (value_if == null)
            {
                value_if = new false_node(this);
            }
            var value_then = valueToCode(block, "THEN");

            if (value_then == null)
            {
                value_then = new nil_node(this);
            }
            var value_else = valueToCode(block, "ELSE");

            if (value_else == null)
            {
                value_else = new nil_node(this);
            }
            return(new if_node(this, value_if, value_then, value_else, true));
        }