Example #1
0
        public static eeObject Add(eeObject exp1, eeObject exp2)
        {
            // if both are lists
            if (exp1.type == eeObjectType.LIST && exp2.type == eeObjectType.LIST)
            {
                // concat the lists

                // TO DO: Make this use our already defined eeListObject methods.
                ((List <eeObject>)exp1.value).AddRange(exp2.AsList());
                return(exp1);
            }
            // if at least one is a list
            else if (exp1.type == eeObjectType.LIST ^ exp2.type == eeObjectType.LIST)
            {
                // append/prepend the nonlist to the list

                if (exp1.type == eeObjectType.LIST) //append
                {
                    ((List <eeObject>)exp1.value).Add(exp2);
                    return(exp1);
                }
                else // prepend
                {
                    ((List <eeObject>)exp2.value).Insert(0, exp1);
                    return(exp2);
                }
            }
            else
            {
                throw new Exception("This shouldn't happen");
            }
        }
Example #2
0
        public static eeObject Multiply(eeObject exp1, eeObject exp2)
        {
            bool isExp1 = false;

            List <eeObject> list;
            eeObject        nonlist;

            if (exp1.type == eeObjectType.LIST && exp2.type == eeObjectType.NUMBER)
            {
                isExp1  = true;
                list    = (List <eeObject>)exp1.value;
                nonlist = exp2;
            }
            else if (exp1.type == eeObjectType.NUMBER && exp2.type == eeObjectType.LIST)
            {
                list    = (List <eeObject>)exp2.value;
                nonlist = exp1;
            }
            else
            {
                throw new Exception("This shouldn't happen");
            }

            var listCount = list.Count();

            for (eeNumber i = new eeNumber(0); i < nonlist.AsNumber(); i += new eeNumber(1))
            {
                for (int j = 0; j < listCount; j++)
                {
                    list.Add(list[j]);
                }
            }

            return(isExp1 ? exp1 : exp2);
        }
Example #3
0
 public eeListNode(eeObject obj, eeNumber index, eeListNode prev, eeListNode next)
 {
     this.obj   = obj;
     this.index = index;
     this.prev  = prev;
     this.next  = next;
 }
Example #4
0
        /* String Subtraction:
         * If right is not a substring(s) of left, then the subtraction is invalid.
         * If it is, then said substring will be removed from the lefthand string in its last occurence.
         * eg: "abcde123fgh123" - "123" -> abcde123fgh"
         * eg: "abc" - "d" -> Error: invalid string subtraction
         *
         * This function will return null if it is an invalid subtraction,
         * otherwise it will return the "difference"
         */
        public static eeObject Subtract(eeObject exp1, eeObject exp2)
        {
            string left = exp1.AsString(), right = exp2.AsString();

            if (!left.Contains(right))
            {
                throw new Exception("Cannot subtract two strings where one is not a substring of the other");
            }

            var chArry = right.ToCharArray();
            int pos    = left.LastIndexOfAny(chArry);

            return(eeObject.newStringObject(left.Remove(pos - chArry.Length + 1, chArry.Length)));
        }
Example #5
0
        public void Append(eeObject obj)
        {
            _count += eeNumber.ONE;
            if (LastNode == null) // if this is the second object to enter the list
            {
                var node = new eeListNode(obj.Copy(), _count.Copy(), HeadNode, null);
                LastNode      = node;
                HeadNode.next = node;
                return;
            }

            var newNode = new eeListNode(obj.Copy(), _count.Copy(), LastNode, null);

            this.LastNode.next = newNode;
            this.LastNode      = newNode;
        }
Example #6
0
        /* List Subtraction:
         * If left and right are both lists, and every element in b is contained in a, all common elements (including duplicates) are removed from a.
         * If left is a list and right is a nonlist, right is removed from left assuming it exists, errors otherwise.
         * Errors if left is a nonlist and right is a list
         */
        public static eeObject Subtract(eeObject exp1, eeObject exp2)
        {
            // if both are lists
            if (exp1.type == eeObjectType.LIST && exp2.type == eeObjectType.LIST)
            {
                List <eeObject> left  = exp1.AsList(),
                                right = exp2.AsList();

                // make sure every element in right is contained in left
                if (right.All(i => left.Contains(i)))
                {
                    // uses a linq query to filter out all matches
                    return(eeObject.newListObject(
                               (from elmt in left
                                where !right.Contains(elmt)
                                select elmt).ToList()
                               ));
                }
                else
                {
                    throw new Exception("Cannot subtract two lists where one is not a subset of the other or where the subtrahend is longer than the minuend");
                }
            }
            // if left is list and right is nonlist
            else if (exp1.type == eeObjectType.LIST)
            {
                var left = (List <eeObject>)exp1.value;

                if (!left.Contains(exp2))
                {
                    throw new Exception("Cannot subtract an object from a list which it is not contained in.");
                }

                // remove all matches
                left.RemoveAll(new Predicate <eeObject>((a) => a == exp2));
                return(exp1);
            }
            else
            {
                throw new Exception("This shouldn't happen");
            }
        }
Example #7
0
        public static eeObject Multiply(eeObject exp1, eeObject exp2)
        {
            if (!
                ((exp1.type == eeObjectType.STRING && exp2.type == eeObjectType.NUMBER) ||
                 (exp1.type == eeObjectType.NUMBER && exp2.type == eeObjectType.STRING))
                )
            {
                throw new Exception("String multiplication factors must be of type string and number.");
            }

            // Figure out which one is a string and which one is a num
            string   str = exp1.type == eeObjectType.NUMBER ? exp2.AsString() : exp1.AsString();
            eeNumber num = exp1.type == eeObjectType.NUMBER ? exp1.AsNumber() : exp2.AsNumber();

            // Copy string n times
            string concat = "";

            for (eeNumber i = new eeNumber(0); i < num; i += new eeNumber(1))
            {
                concat += str;
            }

            return(eeObject.newStringObject(concat));
        }
Example #8
0
 /* First will check for length, the longer one will win.
  * If they're the same length, the one alphabetically earlier will win.
  * Returns bool as opposed to a eeBoolObject because the eeObject method also returns a bool directly.
  */
 public static bool GreaterThan(eeObject exp1, eeObject exp2)
 {
     return(exp1.AsString().CompareTo(exp2.AsString()) < 0);
 }
Example #9
0
        public static eeObject Add(eeObject exp1, eeObject exp2)
        {
            string left = exp1.AsString(), right = exp2.AsString();

            return(eeObject.newStringObject(left + right));
        }
Example #10
0
 // Returns bool as opposed to a eeBoolObject because the eeObject method also returns a bool directly.
 public static bool GreaterThan(eeObject exp1, eeObject exp2)
 {
     return(exp1.AsList().Count > exp2.AsList().Count);
 }
Example #11
0
        public eeList(eeObject firstObject)
        {
            var firstNode = new eeListNode(firstObject, _count.Copy(), null, null);

            this.HeadNode = firstNode;
        }