コード例 #1
0
        public node text_prompt(TextPromptBlock block)
        {
            // Prompt function.
            var  msg  = new str_node(this, block.getFieldValue("TEXT"));
            node code = new fcall_node(this, intern("text_prompt"), new JsArray <node>()
            {
                msg
            }, null);
            var toNumber = block.getFieldValue("TYPE") == "NUMBER";

            if (toNumber)
            {
                code = new call_node(this, code, intern("to_f"));
            }
            return(code);
        }
コード例 #2
0
        node var_reference(node lhs)
        {
            node n;

            var lvar = lhs as lvar_node;

            if (lvar != null)
            {
                if (!local_var_p(lvar.name))
                {
                    n = new fcall_node(this, lvar.name, null);
                    return(n);
                }
            }

            return(lhs);
        }
コード例 #3
0
        public node text_changeCase(TextChangeCaseBlock block)
        {
            // Change capitalization.
            var OPERATORS = new Dictionary <string, string>()
            {
                { "UPPERCASE", "upcase" },
                { "LOWERCASE", "downcase" },
                { "TITLECASE", null }
            };
            node code;
            var  @operator = OPERATORS[block.getFieldValue("CASE")];

            if (!String.IsNullOrEmpty(@operator))
            {
                @operator = OPERATORS[block.getFieldValue("CASE")];
                var argument0 = valueToCode(block, "TEXT");
                if (argument0 == null)
                {
                    argument0 = new str_node(this, "");
                }
                code = new call_node(this, argument0, intern(@operator));
            }
            else
            {
                // Title case is not a native Ruby function. Define one.
                var argument0 = valueToCode(block, "TEXT");
                if (argument0 == null)
                {
                    argument0 = new str_node(this, "");
                }
                code = new fcall_node(this, intern("text_to_title_case"), new JsArray <node>()
                {
                    argument0
                }, null);
            }
            return(code);
        }
コード例 #4
0
ファイル: Math.cs プロジェクト: h7ga40/BlockFactory
        public node math_constrain(MathConstrainBlock block)
        {
            // Constrain a number between two limits.
            var argument0 = valueToCode(block, "VALUE");

            if (argument0 == null)
            {
                argument0 = new int_node(this, 0);
            }
            var argument1 = valueToCode(block, "LOW");

            if (argument1 == null)
            {
                argument1 = new int_node(this, 0);
            }
            var argument2 = valueToCode(block, "HIGH");

            if (argument2 == null)
            {
                argument2 = new fcall_node(this, intern("Float"), new JsArray <node>()
                {
                    new str_node(this, "inf")
                }, null);
            }
            node code = new array_node(this, new JsArray <node>()
            {
                argument0, argument1
            });

            code = new call_node(this, code, intern("max"));
            code = new array_node(this, new JsArray <node>()
            {
                code, argument2
            });
            return(new call_node(this, code, intern("min")));
        }
コード例 #5
0
ファイル: Math.cs プロジェクト: h7ga40/BlockFactory
        public node math_on_list(MathOnListBlock block)
        {
            // Math functions for lists.
            var func = block.getFieldValue("OP");
            var list = valueToCode(block, "LIST");

            if (list == null)
            {
                list = new array_node(this, new JsArray <node>());
            }
            node code;

            switch (func)
            {
            case "SUM":
                code = new call_node(this, list, intern("sum"));
                break;

            case "MIN":
                code = new call_node(this, list, intern("numbers"));
                code = new call_node(this, code, intern("min"));
                break;

            case "MAX":
                code = new call_node(this, list, intern("numbers"));
                code = new call_node(this, code, intern("max"));
                break;

            case "AVERAGE":
                code = new call_node(this, list, intern("average"));
                break;

            case "MEDIAN":
                code = new call_node(this, list, intern("median"));
                break;

            case "MODE":
                // As a list of numbers can contain more than one mode,
                // the returned result is provided as an array.
                // Mode of [3, "x", "x", 1, 1, 2, "3"] -> ["x", 1].
                code = new fcall_node(this, intern("math_modes"), new JsArray <node>()
                {
                    list
                }, null);
                break;

            case "STD_DEV":
                code = new call_node(this, list, intern("standard_deviation"));
                break;

            case "RANDOM":
                code = new call_node(this, list, intern("size"));
                code = new fcall_node(this, intern("rand"), new JsArray <node>()
                {
                    code
                }, null);
                code = new call_node(this, list, intern("[]"), new JsArray <node>()
                {
                    code
                }, null);
                break;

            default:
                throw new Exception("Unknown operator: " + func);
            }
            return(code);
        }