Ejemplo n.º 1
0
 public static string Format(Unit unit)
 {
     if (unit.HasUnit)
         return "[" + unit + "]";
     else
         return "";
 }
Ejemplo n.º 2
0
 public static Unit operator *(Unit a, Unit b)
 {
     var c = new Unit();
     foreach (var e in a.Exponent)
         c.AddExponent(e.Key, e.Value);
     foreach (var e in b.Exponent)
         c.AddExponent(e.Key, e.Value);
     return c;
 }
Ejemplo n.º 3
0
 public static Unit operator /(Unit a, Unit b)
 {
     var c = new Unit();
     foreach (var e in a.Exponent)
         c.AddExponent(e.Key, e.Value); //Above the division
     foreach (var e in b.Exponent)
         c.AddExponent(e.Key, -e.Value);//Below the division
     return c;
 }
Ejemplo n.º 4
0
 public LaxType(DataType type, Unit unit)
 {
     Type = type;
     Unit = unit;
 }
Ejemplo n.º 5
0
        static Unit GetUnit(Unit left, BinaryOp op, Unit right)
        {
            switch (op.Operator)
            {
                case "+":
                case "-":
                case "and":
                case "or":
                    if (left != right)
                        throw new SemanticError(op, "Unit mismatch: " + left + op.Operator + right);
                    return left;

                case "*":
                    return left * right;

                case "/":
                    return left / right;

                default:
                    throw new NotImplementedException(op.Operator);
            }
        }