Example #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 + "'");
            }
        }
Example #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() + "'");
     }
 }
Example #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() + "'");
 }
Example #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) + "'");
            }
        }
Example #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) + "'");
            }
        }
Example #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();
 }
Example #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) + "'");
            }
        }
Example #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) + "'");
            }
        }
Example #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() + "'");
     }
 }
Example #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 + "'");
            }
        }
Example #11
0
 public override bool Smaller(LangObject other)
 {
     throw new InterpreterException();
 }
Example #12
0
 public override LangObject Multiply(LangObject other)
 {
     throw new InterpreterException();
 }
Example #13
0
 public bool NotEqual(LangObject other)
 {
     return(this.Smaller(other) || other.Smaller(this));
 }
Example #14
0
 public LangState(string _message, LangObject _optional, Interpreter _inter)
     : base(ObjectType.STATE, _inter)
 {
     message         = _message;
     optionalMessage = _optional;
 }
Example #15
0
 public bool GreaterEqual(LangObject other)
 {
     return(!this.Smaller(other));
 }
Example #16
0
 abstract public bool Smaller(LangObject other);
Example #17
0
 public bool SmallerEqual(LangObject other)
 {
     return(!other.Smaller(this));
 }
Example #18
0
 public override LangObject Mod(LangObject other)
 {
     throw new InterpreterException("Invalid operation 'string' % '" + Convert.ToString(other.objectType).ToLower() + "'");
 }
Example #19
0
 abstract public LangObject Mod(LangObject other);
Example #20
0
 abstract public LangObject Divide(LangObject other);
Example #21
0
 abstract public LangObject Multiply(LangObject other);
Example #22
0
 abstract public LangObject Minus(LangObject other);
Example #23
0
 public override LangObject Plus(LangObject other)
 {
     throw new InterpreterException();
 }
Example #24
0
 public bool Greater(LangObject other)
 {
     return(!(this.Smaller(other) || this.Equal(other)));
 }
Example #25
0
 abstract public LangObject Pow(LangObject other);
Example #26
0
 abstract public LangObject Plus(LangObject other);