Exemple #1
0
        public ktXML(ktList List)
            : this()
        {
            if (List == null)
            {
                return;
            }

            if (List.Node != null)
            {
                m_Node = new ktXMLNode(List.Node);
            }
            else
            {
                m_Node = new ktXMLNode("post");
            }
            //ktDebug.Log( "POST:" + List.Get_R( "\t", true ) + "=###=#==#=#==##==#=#=#=");

            List.Reset();
            foreach (ktList L in List)
            {
                if (L != null)
                {
                    AddList(new ktXML(L));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Add values to the integer (changes the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to add to the integer</param>
        /// <returns>The sum of all the arguments and the internal integer</returns>
        public ktValue Add(ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't add nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Try to convert the argument to an int and add it to the internal integer
                m_value += GetAsInt((ktValue)L.Node.Value);
            }

            // Wrap this object in a ktValue ...
            Value = new ktValue("return", "ktInt", this, m_HardType, true);

            // ... and return it
            return Value;
        }
        public ktValue Run(ktList Arguments)
        {
            if (m_function == null)
            {
                throw new ktError("No function defined in ktFunction wrapper class!", ktERR.NOTDEF);
            }

            return m_function.Run(Arguments);
        }
Exemple #4
0
 public ktContext(ktString Name)
     : base("ktContext", 0)
 {
     m_Name = Name;
     m_Parent = null;
     m_Aliases = null;
     m_Variables = null;
     m_Functions = null;
     m_AddIfNotSet = true;
 }
Exemple #5
0
 public override int Compare(ktString op, ktList arguments)
 {
     if (arguments.Count == 1)
     {
         return Compare(op, (ktValue)arguments.FirstNode.Value);
     }
     else
     {
         throw new ktError("Compare for more than 1 value is not implemented in '" + this.m_Name + "'!");
     }
 }
Exemple #6
0
 public ktContext(ktString Name, ktString Aliases, ktList Classes,
     ktList Variables, ktList Functions, ktContext Parent,
     bool AddIfNotSet)
     : base("ktContext", 0)
 {
     m_Name = Name;
     m_Parent = Parent;
     m_Aliases = Aliases;
     m_Variables = Variables;
     m_Functions = Functions;
     m_AddIfNotSet = AddIfNotSet;
 }
Exemple #7
0
 public ktClass(ktString Name, ktClass Parent, ktList Properties, ktList Methods,
                bool AddIfNotSet, bool IsClass_, bool HardType = false, bool IsConstant = false)
     : base("ktClass", 0)
 {
     m_Name = Name;
     m_Parent = Parent;
     m_Properties = Properties;
     m_Methods = Methods;
     m_AddIfNotSet = AddIfNotSet;
     m_IsClass = IsClass_;
     m_HardType = HardType;
     m_IsConstant = IsConstant;
 }
Exemple #8
0
        }/*
		public ktBlock( ktBlock Block ) : this()
		{
			SetBlock( Block );
		}*/


        public bool SetLines(ktList Lines)
        {
            if (Lines == null)
            {
                return false;
            }

            /* * /
            m_Lines = new ktList( Lines );/*/
            m_Lines = Lines;/* */

            return true;
        }
Exemple #9
0
        public bool AddContext(ktContext Context)
        {
            if (Context == null)
            {
                return false;
            }

            if (m_Contexts == null)
            {
                m_Contexts = new ktList();
            }

            return m_Contexts.Add(Context.Name, Context);
        }
Exemple #10
0
        /// <summary>
        /// Assign a value to the float
        /// </summary>
        /// <param name="Arguments">The value to assign</param>
        /// <returns>ktValue with the current object</returns>
        public ktValue Assign(ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            // Can't assign nothing..
            if ((Arguments.IsEmpty()) || ((ktValue)Arguments.First.Node.Value).IsNull())
            {
                throw new ktError("Can't assign nothing (null) to a float!", ktERR.NOTDEF);
            }

            // Store the first value given as argument (ignore the rest)
            m_value = GetAsFloat((ktValue)Arguments.First.Node.Value);

            // Return this object wrapped in a ktValue
            return new ktValue(this.Name, "ktFloat", this, m_HardType, false);
        }
Exemple #11
0
        public ktDelegateFunction(ktString Name, ktFunction_Double_Delegate Delegate)
            : base(Name, null, null, ktValue.Null)
        {
            m_Arguments = new ktList();
            m_Arguments.Add(new ktValue("D", "double",
                                              kacTalk.Main.GetClass("double"),
                                              true, true));

            m_Delegate = delegate(ktList Args)
            {
                if ((Args == null) || (Args.FirstNode == null) ||
                    (Args.FirstNode.Value == null))
                {
                    throw new ktError("Didn't get an argument for '" +
                                      Name + "'!", ktERR.MISSING);
                }
                //ktDebug.Log( "ktDF::DOUBLE(" +Args.FirstNode.Value.ToString() + ")" );
                ktString S_In = new ktString(Args.FirstNode.Value.ToString());
                double D_In = 0.0;
                double D_Out = 0.0;

                try
                {
                    if (System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator == ",")
                    {
                        S_In.Replace(".", ",", true);
                    }

                    D_In = S_In.ToDouble();
                }
                catch (Exception E)
                {
                    if (E.GetType() == typeof(System.FormatException) && !S_In.IsEmpty())
                    {
                        throw new ktError("ktDouble::CreateObject: Cant make '" + S_In + "' into an double", ktERR.WRONGTYPE);
                    }
                }
                ktDebug.Log("D_In: " + D_In.ToString());
                D_Out = Delegate(D_In);
                ktDebug.Log("D_Out: " + D_Out.ToString());

                return new ktValue("return", "double",
                                   kacTalk.Main.MakeObjectOf("double", D_Out),
                                   true, true);
            };
        }
        public static ktValue Output( ktList Arguments )
        {
            string str, ret = "";
            foreach (ktList L in Arguments)
            {
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                str = L.Node.ValueToString();
                ret += str;
                Console.WriteLine("OUTPUT:" + str );

                try
                {
                    Form1.LogText( str );
                } catch (Exception) {}
            }

            return new ktValue("return", "ktString", new ktStringClass(ret), true, true);
        }
        public override ktValue _RunMethod(ktString Name, ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            switch (Name.AsLower())
            {
                case "run":
                case "_run":
                case "execute":
                case "_execute":
                case "_func_call":
                    {
                        Value = Run( Arguments );
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          Name + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            return Value;
        }
 public ktRunStatement(ktList Statement, ktBlock Block)
     : base("ktRunStatement", 0)
 {
     m_Statement = Statement;
     m_Block = Block;
 }
Exemple #15
0
        /// <summary>
        /// Run a method
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Arguments"></param>
        /// <returns></returns>
        public override ktValue _RunMethod(ktString Name, ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            //ktDebug.Log("ktInt::" + Name);

            // Check the name of the method to call and call appropriate method
            switch (Name.AsLower())
            {
                case "_add":
                case "op+":
                case "operator+":
                    {
                        Value = _Add(Arguments);
                        break;
                    }
                case "add":
                case "op+=":
                case "operator+=":
                case "_append":
                    {
                        CheckIfConstant(Name);
                        Value = Add(Arguments);
                        break;
                    }
                case "increase":
                case "op++":
                case "operator++":
                case "_increase":
                    {
                        CheckIfConstant(Name);
                        Value = Increase();
                        break;
                    }
                case "_subtract":
                case "op-":
                case "operator-":
                    {
                        Value = _Subtract(Arguments);
                        break;
                    }
                case "op-=":
                case "operator-=":
                case "subtract":
                    {
                        CheckIfConstant(Name);
                        Value = Subtract(Arguments);
                        break;
                    }
                case "decrease":
                case "op--":
                case "operator--":
                case "_decrease":
                    {
                        CheckIfConstant(Name);
                        Value = Decrease();
                        break;
                    }
                case "_multiply":
                case "_times":
                case "op*":
                case "operator*":
                    {
                        Value = _Multiply(Arguments);
                        break;
                    }
                case "multiply":
                case "times":
                case "op*=":
                case "operator*=":
                    {
                        CheckIfConstant(Name);
                        Value = Multiply(Arguments);
                        break;
                    }
                case "_divide":
                case "op/":
                case "operator/":
                    {
                        Value = _Divide(Arguments);
                        break;
                    }
                case "op/=":
                case "operator/=":
                case "divide":
                    {
                        CheckIfConstant(Name);
                        Value = Divide(Arguments);
                        break;
                    }
                case "_mod":
                case "_modulus":
                case "op%":
                case "operator%":
                    {
                        Value = _Modulus(Arguments);
                        break;
                    }
                case "op%=":
                case "operator%=":
                case "modulus":
                    {
                        CheckIfConstant(Name);
                        Value = Modulus(Arguments);
                        break;
                    }
                case "_power":
                case "_pow":
                case "op**":
                case "operator**":
                    {
                        Value = _Power(Arguments);
                        break;
                    }
                case "op^":
                case "operator^":
                    {
                        if (kacTalk.Main.MathMode)
                        {
                            Value = _Power(Arguments);
                        }
                        else
                        {
                            Value = _ExclusiveOr(Arguments);
                        }
                        break;
                    }
                case "op^=":
                case "operator^=":
                    {
                        CheckIfConstant(Name);
                        if (kacTalk.Main.MathMode)
                        {
                            Value = Power(Arguments);
                        }
                        else
                        {
                            Value = ExclusiveOr(Arguments);
                        }
                        break;
                    }
                case "power":
                case "pow":
                    {
                        CheckIfConstant(Name);
                        Value = Power(Arguments);
                        break;
                    }
                case "_assign":
                case "op=":
                case "operator=":
                case "assign":
                    {
                        CheckIfConstant(Name);
                        Value = Assign(Arguments);
                        break;
                    }
                case "tobase":
                    {
                        Value = ToBase(Arguments);
                        break;
                    }
                case "tobinary":
                    {
                        Value = _ToBase(2);
                        break;
                    }
                /*case "toint":
                    {
                        Value = new ktValue("return", "ktInt", new ktInt(m_value), true, true);
                        break;
                    }*/
                case "tobool":
                    {
                        Value = _ToBool();
                        break;
                    }
                case "tooct":
                    {
                        Value = _ToBase(8);
                        break;
                    }
                case "tohex":
                    {
                        Value = _ToBase(16);
                        break;
                    }
                case "frombase":
                    {
                        Value = FromBase(Arguments);
                        break;
                    }
                case "frombinary":
                    {
                        Value = FromBase(Arguments, 2);
                        break;
                    }
                case "fromoct":
                    {
                        Value = FromBase(Arguments, 8);
                        break;
                    }
                case "fromhex":
                    {
                        Value = FromBase(Arguments, 16);
                        break;
                    }
                case ">":
                case "op>":
                case "operator>":
                case "mt":
                case "gt":
                case "greater":
                case "greaterthan":
                case "more":
                case "morethan":
                case "isgreater":
                case "isgreaterthan":
                case "ismore":
                case "ismorethan":
                case ">=":
                case "op>=":
                case "operator>=":
                case "mte":
                case "gte":
                case "greaterorequal":
                case "greaterthanorequal":
                case "moreorequal":
                case "morethanorequal":
                case "isgreaterorequal":
                case "isgreaterthanorequal":
                case "ismoreorequal":
                case "ismorethanorequal":
                case "<":
                case "op<":
                case "operator<":
                case "lt":
                case "less":
                case "lessthan":
                case "isless":
                case "islessthan":
                case "<=":
                case "op<=":
                case "operator<=":
                case "lte":
                case "lessorequal":
                case "lessthanorequal":
                case "islessorequal":
                case "islessthanorequal":
                case "<>":
                case "!=":
                case "op<>":
                case "op!=":
                case "operator<>":
                case "operator!=":
                case "ne":
                case "isnotequal":
                case "notequal":
                case "==":
                case "op==":
                case "operator==":
                case "isequal":
                case "equal":
                case "eq":
                case "compare":
                    {
                        Value = _Compare(Name,Arguments);
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          Name + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            // Done...
            return Value;
        }
Exemple #16
0
        /// <summary>
        /// Calculate the value of the integer raised to the power of the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to raise the integer with</param>
        /// <returns>The value of the internal integer to the power of the arguments</returns>
        public ktValue _Power(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't raise an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Raise it to the power of the argument
                res = (int)Math.Pow((double)res,(double)a);
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Exemple #17
0
        /// <summary>
        /// Multiply values with the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to multiply with the integer</param>
        /// <returns>The product of all the arguments and the internal integer</returns>
        public ktValue _Multiply(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't multiply nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Multiply with the current argument
                res *= GetAsInt((ktValue)L.Node.Value);
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Exemple #18
0
        /// <summary>
        /// Calculate the modulus of the integer and the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to multiply with the integer</param>
        /// <returns>The product of all the arguments and the internal integer</returns>
        public ktValue _Modulus(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            ktValue Arg = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Do modulus with the current argument
                res %= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }
Exemple #19
0
        /// <summary>
        /// Calculate the value of the integer XOR with the power of the arguments (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to XOR the integer with</param>
        public ktValue _ExclusiveOr(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Perform an XOR-operation
                res ^= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), false, true);

            return Value;
        }
Exemple #20
0
        public void Initiate()
        {
            if (m_Channel == null)
            {
                throw new ktError("ktTalker::Initiate failed due to the lack of a Channel!");
            }
            m_AvailableObjects = new ktList();

            m_Channel.Initiate( m_URI, m_APIKey );

            Console.WriteLine(m_AvailableObjects.Get_R());
        }
 public ktRunStatement(ktList Statement)
     : this(Statement, new ktBlock())
 {
 }
        public override ktList GetMethods()
        {
            ktList List = new ktList();

            List.Add("Export", CreateObject("0"));

            return List;
        }
        public override ktList GetProperties()
        {
            ktValue This = new ktValue(m_Name, "int", this, true, false);
            ktList List = new ktList();

            List.Add("_", This);
            List.Add("this", This);
            List.Add("_this", This);
            List.Add("object", This);
            List.Add("_object", This);

            List.Add("MathMode", This);

            return List;
        }
Exemple #24
0
        /// <summary>
        /// Convert from decimal to another base
        /// </summary>
        /// <param name="tobase">The base to convert from (We only use the first argument in the list)</param>
        /// <returns></returns>
        public ktValue ToBase(ktList Arguments)
        {
            ktValue Arg = ktValue.Null;
            int tobase = 0;

            // If we didn't get any arguments ...
            if (Arguments.IsEmpty())
            {
                // ... we use base 2 as a default value
                tobase = 2;
            }
            // We got arguments
            else
            {
                // Get the first value
                Arg = (ktValue)Arguments.First.Node.Value;
                // Convert the argument to an int
                tobase = Arg.ToInt();
            }

            // Convert
            return _ToBase( tobase );
        }
        public override ktValue _RunMethod(ktString Name, ktList Arguments)
        {
            if (Name.IsEmpty())
            {
                throw new ktError("Didn't get the name of the method to run in class '" +
                                m_Name + "'.", ktERR.NOTSET);
            }
            //ktDebug.Log( ";Name::"+ Name + ";;;;_\n" );
            if (Name == "_PropertyChanged")
            {
                if ((Arguments == null) || (Arguments.GetCount() != 2))
                {
                    throw new ktError("kactalk::_PropertyChanged() : Didn't get the two nnede arguments!",
                                      ktERR.MISSING);
                }
            #if Debug
            ktDebug.Log( "Args::" + Arguments.Get_R( "\t", true ) );
            #endif

                Name = Arguments.Get("Name").Node.Value.ToString();
                ktValue Value = (ktValue)Arguments.Get("Value").Node.Value;

                SetProperty(Name, Value);

                return ktValue.Null;
            }
            else /*if (Name.StartsWith( "operator", out Name )) {
                return HandleOperator( Name, Arguments );
            } else */
            {
                throw new ktError("Couldn't find the method '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
            }
        }
Exemple #26
0
        /// <summary>
        /// Add values to the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to add to the integer</param>
        /// <returns>The sum of all the arguments and the internal integer</returns>
        public ktValue _Add(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = 0;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't add nothing (null) to an integer!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }
                // Try to convert the argument to an int and add it to the sum
                res += GetAsInt((ktValue)L.Node.Value);
            }
            // Add the current sum to the internal integer, create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(m_value + res), true, true);

            // Return the result
            return Value;
        }
Exemple #27
0
        internal void AddAvailableObject(ktString o)
        {
            if (m_AvailableObjects == null)
                m_AvailableObjects = new ktList();

            m_AvailableObjects.Add(o);
        }
Exemple #28
0
        /// <summary>
        /// Compare the integer with the given value
        /// </summary>
        /// <param name="op">The operator to use for the comparison</param>
        /// <param name="val">The value to compare with (in a list)</param>
        /// <returns>A value representing the comparison (wrapped in a ktValue)</returns>
        public ktValue _Compare(ktString Name, ktList Arguments)
        {
            // Do the comparison
            int ret = Compare(Name, Arguments);

            // Wrap the result in a ktValue
            return new ktValue("return", "ktInt", new ktInt(ret), false, true);
        }
Exemple #29
0
        public static ktXML FromList(ktList List)
        {
            ktXML XML = new ktXML(List);

            return XML;
        }
Exemple #30
0
        /// <summary>
        /// Divide values with the integer (doesn't change the value of the object)
        /// </summary>
        /// <param name="Arguments">A list of values to divide the integer with</param>
        /// <returns>The quotient of all the arguments and the internal integer</returns>
        public ktValue _Divide(ktList Arguments)
        {
            ktValue Value = ktValue.Null;
            int res = m_value;
            int a = 1;

            // Check so we actually got some arguments
            if (Arguments.IsEmpty())
            {
                throw new ktError("Can't divide an integer with nothing (null)!", ktERR.NOTDEF);
            }

            // Go through the list of arguments
            foreach (ktList L in Arguments)
            {
                // If there's nothing in this argument
                if ((L.Node == null) || (L.Node.Value == null))
                {
                    continue;
                }

                // Get the argument as an integer
                a = GetAsInt((ktValue)L.Node.Value);
                // Check so it isn't zero
                if (a == 0)
                {
                    // Oops, can't do that!!!
                    throw new ktError("You can't divide by zero!", ktERR.DIV_BY_ZERO);
                }
                // Divide with the current argument
                res /= a;
            }
            // Create a new ktInt and wrap it in a ktValue
            Value = new ktValue("return", "ktInt", new ktInt(res), true, true);

            return Value;
        }