Exemplo n.º 1
0
        public override bool Smaller(LangObject other)
        {
            if (other.objectType != ObjectType.CLASS)
            {
                throw new InterpreterException("Invalid operation 'class' < '" + Convert.ToString(other.objectType) + "'");
            }
            LangClass right = (LangClass)other;

            if (right.name != this.name)
            {
                throw new InterpreterException("Invalid Operation '" + this.name + "' < '" + right.name + "'");
            }
            if (this.methods.Value.ContainsKey("__operator_smaller"))
            {
                FunctionStatement stat = (FunctionStatement)(((ArrayList)this.methods.Value["__operator_smaller"])[0]);
                LangObject        obj  = handler.RunClassOperator(stat, this, right);
                if (obj.objectType == ObjectType.NUMBER)
                {
                    return(((LangNumber)obj).numberValue.Value == 1);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                throw new InterpreterException("No overloaded function for '" + this.name + "' < '" + right.name + "'");
            }
        }
Exemplo n.º 2
0
 public override bool Smaller(LangObject other)
 {
     if (other.objectType == ObjectType.STRING)
     {
         string _stringValue = ((LangString)(other)).stringValue.Value;
         if (stringValue.Value.Length < _stringValue.Length)
         {
             return(true);
         }
         else if (stringValue.Value.Length > _stringValue.Length)
         {
             return(false);
         }
         for (int i = 0; i < stringValue.Value.Length; i++)
         {
             if (stringValue.Value[i] != _stringValue[i])
             {
                 return(stringValue.Value[i] < _stringValue[i]);
             }
         }
         return(false);
     }
     else
     {
         throw new InterpreterException("Invalid logical operation on types 'string' and '" + Convert.ToString(other.objectType).ToLower() + "'");
     }
 }
Exemplo n.º 3
0
 public override LangObject Mod(LangObject other)
 {
     if (other.objectType == ObjectType.NUMBER)
     {
         return(new LangNumber(numberValue.Value % ((LangNumber)other).numberValue.Value, handler));
     }
     throw new InterpreterException("Invalid operation 'number' % '" + Convert.ToString(other.objectType).ToLower() + "'");
 }
Exemplo n.º 4
0
        public override bool Smaller(LangObject other)
        {
            switch (other.objectType)
            {
            case ObjectType.NUMBER:
                return(numberValue.Value < ((LangNumber)(other)).numberValue.Value);

            default:
                throw new InterpreterException("Invalid operation 'number' < '" + Convert.ToString(other.objectType) + "'");
            }
        }
Exemplo n.º 5
0
        public override LangObject Pow(LangObject other)
        {
            switch (other.objectType)
            {
            case ObjectType.NUMBER:
                return(new LangNumber(Math.Pow(numberValue.Value, ((LangNumber)(other)).numberValue.Value), handler));

            default:
                throw new InterpreterException("Invalid operation 'number' ^ '" + Convert.ToString(other.objectType) + "'");
            }
        }
Exemplo n.º 6
0
 public override LangObject Plus(LangObject other)
 {
     if (other.objectType == ObjectType.MAP)
     {
         LangMap ret = (LangMap)this.Clone();
         foreach (DictionaryEntry dic in arrayValue.Value)
         {
             ret.arrayValue.Value[dic.Key] = dic.Value;
         }
         return(ret);
     }
     throw new InterpreterException();
 }
Exemplo n.º 7
0
        public override LangObject Plus(LangObject other)
        {
            switch (other.objectType)
            {
            case ObjectType.STRING:
                return(new LangString(stringValue.Value + ((LangString)other).stringValue.Value, handler));

            case ObjectType.NUMBER:
                return(new LangString(stringValue.Value + Convert.ToString(((LangNumber)other).numberValue.Value), handler));

            default:
                throw new InterpreterException("Invalid operation '" + Convert.ToString(this.objectType) + "' + '" + Convert.ToString(other.objectType) + "'");
            }
        }
Exemplo n.º 8
0
        public override LangObject Multiply(LangObject other)
        {
            switch (other.objectType)
            {
            case ObjectType.STRING:
                return(((LangString)(other)).Multiply(this));

            case ObjectType.NUMBER:
                return(new LangNumber(numberValue.Value * ((LangNumber)(other)).numberValue.Value, handler));

            default:
                throw new InterpreterException("Invalid operation 'number' * '" + Convert.ToString(other.objectType) + "'");
            }
        }
Exemplo n.º 9
0
 public override LangObject Multiply(LangObject other)
 {
     if (other.objectType == ObjectType.NUMBER)
     {
         string     _otherValue = "";
         LangNumber langNumber  = (LangNumber)other;
         for (int i = 0; i < langNumber.numberValue.Value; i++)
         {
             _otherValue += stringValue.Value;
         }
         return(new LangString(_otherValue, handler));
     }
     else
     {
         throw new InterpreterException("Invalid operation 'string' * '" + Convert.ToString(other.objectType).ToLower() + "'");
     }
 }
Exemplo n.º 10
0
        public override LangObject Mod(LangObject other)
        {
            if (other.objectType != ObjectType.CLASS)
            {
                throw new InterpreterException("Invalid operation 'class' % '" + Convert.ToString(other.objectType) + "'");
            }
            LangClass right = (LangClass)other;

            if (right.name != this.name)
            {
                throw new InterpreterException("Invalid Operation '" + this.name + "' % '" + right.name + "'");
            }
            if (this.methods.Value.ContainsKey("__operator_plus"))
            {
                FunctionStatement stat = (FunctionStatement)((ArrayList)this.methods.Value["__operator_mod"])[0];
                return(handler.RunClassOperator(stat, this, right));
            }
            else
            {
                throw new InterpreterException("No overloaded function for '" + this.name + "' % '" + right.name + "'");
            }
        }
Exemplo n.º 11
0
 public override bool Smaller(LangObject other)
 {
     throw new InterpreterException();
 }
Exemplo n.º 12
0
 public override LangObject Multiply(LangObject other)
 {
     throw new InterpreterException();
 }
Exemplo n.º 13
0
 public bool NotEqual(LangObject other)
 {
     return(this.Smaller(other) || other.Smaller(this));
 }
Exemplo n.º 14
0
 public LangState(string _message, LangObject _optional, Interpreter _inter)
     : base(ObjectType.STATE, _inter)
 {
     message         = _message;
     optionalMessage = _optional;
 }
Exemplo n.º 15
0
 public bool GreaterEqual(LangObject other)
 {
     return(!this.Smaller(other));
 }
Exemplo n.º 16
0
 abstract public bool Smaller(LangObject other);
Exemplo n.º 17
0
 public bool SmallerEqual(LangObject other)
 {
     return(!other.Smaller(this));
 }
Exemplo n.º 18
0
 public override LangObject Mod(LangObject other)
 {
     throw new InterpreterException("Invalid operation 'string' % '" + Convert.ToString(other.objectType).ToLower() + "'");
 }
Exemplo n.º 19
0
 abstract public LangObject Mod(LangObject other);
Exemplo n.º 20
0
 abstract public LangObject Divide(LangObject other);
Exemplo n.º 21
0
 abstract public LangObject Multiply(LangObject other);
Exemplo n.º 22
0
 abstract public LangObject Minus(LangObject other);
Exemplo n.º 23
0
 public override LangObject Plus(LangObject other)
 {
     throw new InterpreterException();
 }
Exemplo n.º 24
0
 public bool Greater(LangObject other)
 {
     return(!(this.Smaller(other) || this.Equal(other)));
 }
Exemplo n.º 25
0
 abstract public LangObject Pow(LangObject other);
Exemplo n.º 26
0
 abstract public LangObject Plus(LangObject other);