示例#1
0
        /// <summary>
        /// Executing element. For most of the elements in the program it is element itself,
        /// but for the list it is result of executing operation that is mentioned in the head
        /// of the list.
        /// </summary>
        /// <param name="E"></param>
        /// <returns></returns>
        public GSCore ExecuteElement(GSCore E)
        {
            if (E is GSList)
            {
                GSList L = (GSList)E;
                if (L.Count == 0)
                {
                    return(GSVoid.Void);
                }
                else if (L.Count == 1)
                {
                    return(ExecuteElement(L[0]));
                }
                else
                {
                    GSCore result  = null;
                    GSCore target  = ExecuteElement(L.Parts[0]);
                    string message = (L.Parts[1] is GSToken ? (L.Parts[1] as GSToken).Token : L.Parts[1].getStringValue());
                    if (target != null)
                    {
                        result = target.ExecuteMessage(message, L.Parts.getEvaluatedSublist(this, 2));
                    }

                    if (result == null)
                    {
                        return(new GSString());
                    }
                    return(result);
                }
            }
            else if (E is GSToken)
            {
                GSToken t = E as GSToken;
                if (t.Token.StartsWith("#"))
                {
                    return(new GSString(t.Token));
                }
                return(EvaluateProperty(((GSToken)E).Token));
            }
            else
            {
                return(E);
            }
        }
示例#2
0
        private GSCore execMessage(GSCoreCollection args)
        {
            GSCore result = GSVoid.Void;

            // first is token, name of variable, object
            // second is token, message name
            // third etc are arguments
            if (args.Count >= 2 && args.getSafe(0) is GSToken && args.getSafe(1) is GSToken)
            {
                // evaluate the remaining portion of list
                GSCoreCollection subArgs = getNativeValues(args.getSublist(2));
                // first and second tokens
                GSToken t1 = args.getSafe(0) as GSToken;
                GSToken t2 = args.getSafe(1) as GSToken;
                // evaluate reference to object
                GSCore obj = ExecuteElement(t1);
                // execute message in the object
                result = obj.ExecuteMessage(t2.Token, subArgs);
            }

            return(result);
        }
示例#3
0
        public override GSCore ExecuteMessage(string token, GSCoreCollection args)
        {
            GSCore result = null;

            if (token.Equals("print"))
            {
                result = execPrint(args, false);
            }
            else if (token.Equals("println"))
            {
                result = execPrint(args, true);
            }
            else if (token.Equals("if"))
            {
                result = execIf(args);
            }
            else if (token.Equals("while"))
            {
                result = execWhile(args);
            }
            else if (token.Equals("foreach"))
            {
                result = execForeach(args);
            }
            else if (token.Equals("x"))
            {
                result = execMessage(args);
            }
            else if (token.Equals("do"))
            {
                result = execDo(args);
            }
            else if (token.Equals("return"))
            {
                result = new GSReturn(args.getSafe(0));
            }
            else if (token.Equals("break"))
            {
                result = new GSReturn(GSReturn.TYPE_BREAK);
            }
            else if (token.Equals("continue"))
            {
                result = new GSReturn(GSReturn.TYPE_CONTINUE);
            }
            else if (token.Equals("set") && args.Count > 1)
            {
                result = execSet(args[0], args[1]);
            }
            else if (token.Equals("random"))
            {
                result = execRandom(args);
            }
            else
            {
                if (token.IndexOf('.') >= 0)
                {
                    string[] tp  = token.Split('.');
                    GSCore   obj = this;
                    for (int a = 0; a < tp.Length - 1; a++)
                    {
                        if (obj == null)
                        {
                            break;
                        }
                        obj = obj.GetPropertyValue(tp[a]);
                    }
                    if (obj != null)
                    {
                        return(obj.ExecuteMessage(tp[tp.Length - 1], args));
                    }
                }

                Debugger.Log(0, "", "UNKNOWN MESSAGE: " + token + " ");
            }

            return(result);
        }