Exemple #1
0
    /// <summary>
    /// //sum' -> ADDOP term sum' | MINUS term sum' | lambda
    /// </summary>
    /// <param name="n"></param>
    /// <param name="type1"></param>
    /// <param name="type"></param>
    void sumLL_NodeCode(TreeNode n, VarType type1, out VarType type)
    {
        if (n.Children.Count == 0)
        {
            type = type1;
            return;
        }
        VarType type2;

        termNodeCode(n.Children[1], out type2);
        if (type1 != type2)
        {
            throw new Exception("ICE!!!Type1: " + type1.ToString() + " did not match Type2: " + type2.ToString());
        }
        movTwoVarsTo_xmmRegisters();
        switch (n.Children[0].Token.Lexeme)
        {
        case "+":
            emit("addsd xmm0,xmm1");
            break;

        case "-":
            emit("subsd xmm0,xmm1");
            break;

        default:
            throw new Exception("ICE!!!! Expected ' - ' or ' + ', Recieved: " + n.Children[0].Token.Lexeme);
        }
        mov_xmm_To_rax_andPush();
        type = VarType.NUMBER;
        return;
    }
 public void Construct(VarType input, VarType output)
 {
     this.Construct();
     description = "Casts " + input.ToString() + " to " + output.ToString() + ".";
     valInPins.Add(new ValueInputPin(this, input));
     valOutPins.Add(new ValueOutputPin(this, output));
 }
Exemple #3
0
        public override string ToString()
        {
            StringBuilder declaration = new StringBuilder();

            declaration.Append("DECLARE @" + Name);
            if (Type == StrucType.table)
            {
                declaration.Append(" TABLE ( ");
                string[] serializedColumns = Columns
                                             .Select(c => c.Name + DataTypeToString(c))
                                             .ToArray();
                declaration.Append(string.Join(", ", serializedColumns));
                declaration.Append(" )");
            }
            else
            {
                string[] lens = (Lengths ?? new int[] { }).Select(l => l.ToString()).ToArray();
                if (VarType == Constructor.dbTyp.Custom)
                {
                    declaration.Append(" AS " + (Schema == null ? "" : Schema + ".") + CustomType);
                }
                else
                {
                    declaration.Append(" " + VarType.ToString().ToUpper());
                }
                declaration.Append(lens.Length > 0 ? "(" + string.Join(", ", lens) + ")" : "");
                declaration.Append(Value != null ? " = " + Value.ToString() : "");
            }
            return(declaration.ToString());
        }
Exemple #4
0
        protected static double Step(double cycleVar, double prev, double n, OpType op, VarType step)
        {
            checked
            {
                if (op == OpType.Increase)
                {
                    switch (step)
                    {
                    case VarType.Const:
                        return(cycleVar + 1);

                    case VarType.N:
                        return(cycleVar + n);

                    case VarType.Prev:
                        return(cycleVar + prev);

                    default:
                        throw new NotSupportedException(step.ToString());
                    }
                }
                switch (step)
                {
                case VarType.Const:
                    return(cycleVar * 2);

                case VarType.N:
                    return(cycleVar * n);

                case VarType.Prev:
                    return(cycleVar * Math.Max(2, prev));

                default:
                    throw new NotSupportedException(step.ToString());
                }
            }
        }
Exemple #5
0
        protected static bool Bound(double cycleVar, double prev, double n, VarType bound)
        {
            switch (bound)
            {
            case VarType.N:
                return(cycleVar < n);

            case VarType.Const:
                return(cycleVar < 2);

            case VarType.Prev:
                return(cycleVar < prev);

            default:
                throw new NotSupportedException(bound.ToString());
            }
        }
        public SingleLoopExercise(VarType bound, OpType op,
                                  VarType step, LoopType loop)
        {
            if (bound == VarType.I)
            {
                throw new ArgumentException(bound.ToString());
            }
            if (step == VarType.I)
            {
                throw new ArgumentException(step.ToString());
            }

            Bound = bound;
            Op    = op;
            Step  = step;
            Loop  = loop;
        }
Exemple #7
0
        private void Assign()
        {
            VarType vtype = VarType.Invalid, etype = VarType.Invalid;
            int     varAddress = Variable(ref vtype, ref etype);

            etype = VarType.Invalid;
            if (Tokens[currentToken].Type != TokenType.Assign)
            {
                WriteError("Expected Assign Statement", Tokens[currentToken]);
            }
            AdvanceToken();
            Expr(0, ref etype);
            if (vtype != etype)
            {
                WriteErrorLine("Invalid Type Operation for assignment" + etype.ToString(), Tokens[currentToken]);
            }
            assembler.EmitStore(varAddress);
        }
Exemple #8
0
        public override string ToString()
        {
            StringBuilder declaration = new StringBuilder();

            declaration.Append("DECLARE @" + Name);
            if (Type == StrucType.table)
            {
                declaration.Append(" TABLE ( ");
                string[] serializedColumns = Columns
                                             .Select(c => c.Name + DataTypeToString(c))
                                             .ToArray();
                declaration.Append(string.Join(", ", serializedColumns));
                declaration.Append(" )");
            }
            else
            {
                string[] lens = Lengths.Select(l => l.ToString()).ToArray();
                declaration.Append(" " + VarType.ToString().ToUpper());
                declaration.Append(lens.Length > 0 ? "(" + string.Join(", ", lens) + ")" : "");
                declaration.Append(Value != null ? " = " + Value.ToString() : "");
            }
            return(declaration.ToString());
        }
Exemple #9
0
 public Type(VarType s, Tag t, int size, int line, int pos) : this(s.ToString(), t, size, line, pos)
 {
 }
Exemple #10
0
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("Name", Name);

            var culture = new CultureInfo("en-US");

            VarType type = VarType.Double;

            var valtype = Value.GetType();

            if (valtype == typeof(double))
            {
                type = VarType.Double;
            }
            else if (valtype == typeof(Complex))
            {
                type = VarType.Complex;
            }
            else if (valtype == typeof(Fraction))
            {
                type = VarType.Fraction;
            }
            else if (valtype == typeof(Matrix))
            {
                type = VarType.Matrix;
            }
            else if (valtype == typeof(Vector))
            {
                type = VarType.Vector;
            }
            else if (valtype == typeof(Set))
            {
                type = VarType.Set;
            }
            else if (valtype == typeof(string))
            {
                type = VarType.String;
            }
            else if (valtype == typeof(Time))
            {
                type = VarType.Time;
            }

            writer.WriteAttributeString("Type", type.ToString());

            string xml = null;
            var    sb  = new StringBuilder();

            switch (type)
            {
            case VarType.Double:
                xml = (Convert.ToDouble(Value)).ToString("G17", culture);
                writer.WriteElementString("Content", xml);
                break;

            case VarType.Complex:
                var r = ((Complex)Value).Real.ToString("G17", culture);
                var i = ((Complex)Value).Imaginary.ToString("G17", culture);
                xml = string.Format("{0};{1}", r, i);
                writer.WriteElementString("Content", xml);
                break;

            case VarType.Fraction:
                var n = ((Fraction)Value).Numerator.ToString(culture);
                var d = ((Fraction)Value).Denominator.ToString(culture);
                xml = string.Format("{0};{1}", n, d);
                writer.WriteElementString("Content", xml);
                break;

            case VarType.Matrix:
                Matrix m = ((Matrix)Value);
                writer.WriteAttributeString("Rows", m.Rows.ToString());
                writer.WriteAttributeString("Columns", m.Columns.ToString());
                for (int row = 0; row < m.Rows; row++)
                {
                    sb.Append("[");
                    for (int column = 0; column < m.Columns; column++)
                    {
                        sb.AppendFormat("{0};", m[row, column].ToString("G17", culture));
                    }
                    sb.Append("]\n");
                }
                writer.WriteElementString("Content", sb.ToString());
                break;

            case VarType.Vector:
                var v = (Vector)Value;
                writer.WriteAttributeString("Dimensions", v.Dimensions.ToString());
                if (v.Dimensions == 2)
                {
                    xml = string.Format("{0};{1}", v.X.ToString("G17", culture),
                                        v.Y.ToString("G17", culture));
                }
                else
                {
                    xml = string.Format("{0};{1};{2}", v.X.ToString("G17", culture),
                                        v.Y.ToString("G17", culture),
                                        ((double)v.Z).ToString("G17", culture));
                }
                writer.WriteElementString("Content", xml);
                break;

            case VarType.Set:
                var s = (Set)Value;
                writer.WriteAttributeString("Items", s.Count.ToString());
                sb.Clear();
                foreach (var item in s)
                {
                    sb.AppendFormat("{0};", item.ToString("G17", culture));
                }
                writer.WriteElementString("Content", sb.ToString());
                break;

            case VarType.String:
                writer.WriteElementString("Content", Value.ToString());
                break;

            case VarType.Time:
                Time t = (Time)Value;
                xml = (Convert.ToDouble(t.TotalSeconds).ToString("G17", culture));
                writer.WriteElementString("Content", xml);
                break;
            }
        }
Exemple #11
0
 /// <summary>
 /// Provides an simple string representation of the contained data and type.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                          "{0}: {1}", Value, VarType.ToString()));
 }
        public override string ToString()
        {
            if ((ReferenceAlleleString == null || ReferenceAlleleString == "") && (SecondAlleleString == null || SecondAlleleString == ""))
            {
                return(ChromosomeID + ":" + OneBasedStart.ToString() + "-" + OneBasedEnd.ToString() + "[" + VarType.ToString() + "]");
            }

            return(ChromosomeID                     //
                   + ":" + OneBasedStart.ToString() //
                   + "_" + ReferenceAlleleString    //
                   + "/" + SecondAlleleString
                   + "_" + Genotype.Type.ToString());
        }
Exemple #13
0
 /// <summary>
 /// 把一个VarType枚举匹配成C类型
 /// </summary>
 /// <param name="parEnum">待匹配VarType</param>
 /// <returns>该VarType对应等价的C类型字符串</returns>
 public static string parseVarTypeToCType(VarType parEnum)
 {
     return(parEnum.ToString().ToLower().Replace('_', ' '));
 }