public const_node create_double_const(string text, SourceContext sc)
        {
            const_node cn = null;

            try
            {
                System.Globalization.NumberFormatInfo sgnfi = new System.Globalization.NumberFormatInfo();
                sgnfi.NumberDecimalSeparator = ".";
                double val = double.Parse(text, sgnfi);
                cn = new double_const(val);
                cn.source_context = sc;
            }
            catch (Exception)
            {
                errors.Add(new BadFloat(CurrentFileName, sc, null));
            }
            return(cn);
        }
Exemple #2
0
        public virtual const_node create_double_const(string text, LexLocation loc)
        {
            const_node cn = null;

            try
            {
                System.Globalization.NumberFormatInfo sgnfi = new System.Globalization.NumberFormatInfo();
                sgnfi.NumberDecimalSeparator = ".";
                double val = double.Parse(text, sgnfi);
                cn = new double_const(val);
                cn.source_context = GetTokenSourceContext(loc);
            }
            catch (Exception)
            {
                PascalABCCompiler.PythonABCParser.Errors.UnexpectedToken ut = new PascalABCCompiler.PythonABCParser.Errors.UnexpectedToken(GPPGParser.current_file_name, GetTokenSourceContext(loc), new syntax_tree_node());
                GPPGParser.errors.Add(ut);
            }
            return(cn);
        }
Exemple #3
0
        public node math_constant(MathConstantBlock block)
        {
            // Constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
            var  constant = block.getFieldValue("CONSTANT");
            var  math     = new const_node(this, intern("Math"));
            node code;

            switch (constant)
            {
            case "PI":
                return(new colon2_node(this, math, intern("PI")));

            case "E":
                return(new colon2_node(this, math, intern("E")));

            case "GOLDEN_RATIO":
                code = new call_node(this, math, intern("sqrt"), new JsArray <node>()
                {
                    new float_node(this, 5)
                }, null);
                code = new call_node(this, new float_node(this, 1), intern("+"), code);
                code = new call_node(this, new begin_node(this, code, true), intern("/"), new float_node(this, 2));
                return(code);

            case "SQRT2":
                return(new call_node(this, math, intern("sqrt"), new JsArray <node>()
                {
                    new float_node(this, 2)
                }, null));

            case "SQRT1_2":
                code = new call_node(this, new float_node(this, 1), intern("/"), new float_node(this, 2));
                return(new call_node(this, math, intern("sqrt"), new JsArray <node>()
                {
                    code
                }, null));

            case "INFINITY":
                return(new call_node(this, new float_node(this, 1), intern("/"), new float_node(this, 0)));
            }
            return(null);
        }
 public override void visit(const_node _const_node)
 {
 }
 public virtual void visit(const_node _const_node)
 {
     DefaultVisit(_const_node);
 }
		public virtual void post_do_visit(const_node _const_node)
		{
		}
		public override void visit(const_node _const_node)
		{
			DefaultVisit(_const_node);
			pre_do_visit(_const_node);
			post_do_visit(_const_node);
		}
Exemple #8
0
 public virtual void visit(const_node _const_node)
 {
 }
Exemple #9
0
 public override void visit(const_node _const_node)
 {
     throw new NotImplementedException();
 }
Exemple #10
0
        public node math_single(Block block)
        {
            // Math operators with single operand.
            var  @operator = block.getFieldValue("OP");
            node code      = null;
            node arg;

            if (@operator == "NEG")
            {
                // Negation is a special case given its different operator precedence.
                code = valueToCode(block, "NUM");
                if (code == null)
                {
                    code = new int_node(this, 0);
                }
                return(new call_node(this, code, intern("-@"), (node)null));
            }
            if (@operator == "SIN" || @operator == "COS" || @operator == "TAN")
            {
                arg = valueToCode(block, "NUM");
                if (arg == null)
                {
                    arg = new int_node(this, 0);
                }
            }
            else
            {
                arg = valueToCode(block, "NUM");
                if (arg == null)
                {
                    arg = new int_node(this, 0);
                }
            }
            // First, handle cases which generate values that don't need parentheses
            // wrapping the code.
            var math = new const_node(this, intern("Math"));

            switch (@operator)
            {
            case "ABS":
                code = new call_node(this, arg, intern("abs"));
                break;

            case "ROOT":
                code = new call_node(this, math, intern("sqrt"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "LN":
                code = new call_node(this, math, intern("log"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "LOG10":
                code = new call_node(this, math, intern("log10"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "EXP":
                code = new call_node(this, math, intern("exp"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "POW10":
                code = new call_node(this, new int_node(this, 10), intern("exp"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "ROUND":
                code = new call_node(this, arg, intern("round"));
                break;

            case "ROUNDUP":
                code = new call_node(this, arg, intern("ceil"));
                break;

            case "ROUNDDOWN":
                code = new call_node(this, arg, intern("floor"));
                break;

            case "SIN":
                arg  = new call_node(this, arg, intern("/"), new float_node(this, 180.0));
                arg  = new call_node(this, arg, intern("*"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, math, intern("sin"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "COS":
                arg  = new call_node(this, arg, intern("/"), new float_node(this, 180.0));
                arg  = new call_node(this, arg, intern("*"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, math, intern("cos"), new JsArray <node>()
                {
                    arg
                }, null);
                break;

            case "TAN":
                arg  = new call_node(this, arg, intern("/"), new float_node(this, 180.0));
                arg  = new call_node(this, arg, intern("*"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, math, intern("tan"), new JsArray <node>()
                {
                    arg
                }, null);
                break;
            }
            if (code != null)
            {
                return(code);
            }
            // Second, handle cases which generate values that may need parentheses
            // wrapping the code.
            switch (@operator)
            {
            case "ASIN":
                code = new call_node(this, math, intern("asin"), new JsArray <node>()
                {
                    arg
                }, null);
                code = new call_node(this, code, intern("/"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, code, intern("*"), new float_node(this, 180.0));
                break;

            case "ACOS":
                code = new call_node(this, math, intern("acos"), new JsArray <node>()
                {
                    arg
                }, null);
                code = new call_node(this, code, intern("/"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, code, intern("*"), new float_node(this, 180.0));
                break;

            case "ATAN":
                code = new call_node(this, math, intern("atan"), new JsArray <node>()
                {
                    arg
                }, null);
                code = new call_node(this, code, intern("/"), new colon2_node(this, math, intern("PI")));
                code = new call_node(this, code, intern("*"), new float_node(this, 180.0));
                break;

            default:
                throw new Exception("Unknown math operator: " + @operator);
            }
            return(new begin_node(this, code, true));
        }
		public virtual void visit(const_node _const_node)
		{
		}
		public virtual void visit(const_node _const_node)
		{
			DefaultVisit(_const_node);
		}
		public override void visit(const_node _const_node)
		{
			executer.visit(_const_node);
			if (_const_node.attributes != null)
				this.visit((dynamic)_const_node.attributes);
		}