public bool ExecuteCommand(string command, Stacker stack)
        {
            switch (command)
            {
                case "!":
                    this.value = !value;
                    return true;
                case "string":
                    stack.Pop();
                    stack.InsertTop(new StackObjectString("" + this.value));
                    return true;
            }

            if (stack.GetSize() > 1)
            if(stack.CheckFromTop(1, this.GetType()))
            {
                switch (command)
                {
                    case "==":
                        EE(stack);
                        return true;
                    case "||":
                        OR(stack);
                        return true;
                    case "&&":
                        AND(stack);
                        return true;
                }
            }

            return false;
        }
        public bool ExecuteCommand(string command, Stacker stack)
        {
            if(stack.GetSize() > 1)
            if (stack.CheckFromTop(1, this.GetType()))
            {
                if (command == "+")
                {
                    Add(stack);
                    return true;
                }
                else
                if (command == "==")
                {
                    CheckEquals(stack);
                }
                
            }

            return false;


        }
 private void Subtract(Stacker stack)
 {
     stack.Pop();
     ((StackObjectNumber)stack.Peek()).ModifyValue(-this.value);
 }
 private void Multiply(Stacker stack)
 {
     stack.Pop();
     ((StackObjectNumber)stack.Peek()).MultiplyValue(this.value);
 }
 private void Modulo(Stacker stack)
 {
     stack.Pop();
     ((StackObjectNumber)stack.Peek()).ModuloValue(this.value);
 }
        private void LessThanOrEqualTo(Stacker stack)
        {
            stack.Pop();
            bool e = ((StackObjectNumber)stack.Peek()).value  <= this.value;
            //push it
            stack.Pop();

            stack.InsertTop(new StackObjectBoolean(e));
        }
        private void GreaterThan(Stacker stack)
        {
            stack.Pop();
            bool e = ((StackObjectNumber)stack.Peek()).value  > this.value ;
            //push it
            stack.Pop();

            stack.InsertTop(new StackObjectBoolean(e));
        }
예제 #8
0
 public TajParser()
 {
     variables = new Dictionary<string, StackObject>();
     stack = new Stacker();
 }
 private void Add(Stacker stack)
 {
     stack.Pop();
     ((StackObjectNumber)stack.Peek()).ModifyValue(this.value);
 }
 private void EE(Stacker stack)
 {
     stack.Pop();
     ((StackObjectBoolean)stack.Peek()).EqualsValue(this.value);
 }
 private void OR(Stacker stack)
 {
     stack.Pop();
     ((StackObjectBoolean)stack.Peek()).OrValue(this.value);
 }
 private void AND(Stacker stack)
 {
     stack.Pop();
     ((StackObjectBoolean)stack.Peek()).AndValue(this.value);
 }
 private void Add(Stacker stack)
 {
     stack.Pop();
     ((StackObjectString)stack.Peek()).AddValue(this.value);
 }
 private void CheckEquals(Stacker stack)
 {
     stack.Pop();
     bool a = ((StackObjectString)stack.Peek()).GetValue() == this.value;
     stack.InsertTop(new StackObjectBoolean(a));
 }
        public bool ExecuteCommand(string command, Stacker stack)
        {
            switch (command)
            {
                case "int":
                    this.value = (int)this.value;
                    return true;
                case "neg":
                    this.value *= -1;
                    return true;
                case "round":
                    this.value = (float)Math.Round(this.value);
                    return true;
                case "floor":
                    this.value = (int)this.value;
                    return true;
                case "abs":
                    this.value = (float)Math.Abs(this.value);
                    return true;
                case "string":
                    stack.Pop();
                    stack.InsertTop(new StackObjectString("" + this.value));
                    return true;
            }

            if (stack.GetSize() > 1)
            if(stack.CheckFromTop(1, this.GetType()))
            {
                switch (command)
                {
                    case "+":
                        Add(stack);
                        break;
                    case "-":
                        Subtract(stack);
                        break;
                    case "*":
                        Multiply(stack);
                        break;
                    case "/":
                        Divide(stack);
                        break;
                    case "%":
                        Modulo(stack);
                        break;
                    case "==":
                        EqualValueCheck(stack);
                        break;
                    case "<":
                        LessThan(stack);
                        break;
                    case ">": //!( <= 5)
                        GreaterThan(stack);
                        break;
                    case "<=": //>
                        LessThanOrEqualTo(stack);
                        break;
                    case ">=": //<
                        GreaterThanOrEqualTo(stack);
                        break;
                    default:
                        return false;
                }
                return true;
            }

            return false;
        }
 private void Divide(Stacker stack)
 {
     stack.Pop();
     ((StackObjectNumber)stack.Peek()).DivideValue(this.value);
 }
예제 #17
0
 public void SetStack(Stacker s)
 {
     this.stack = s;
 }
        private void EqualValueCheck(Stacker stack)
        {
            stack.Pop();
            bool e = ((StackObjectNumber)stack.Peek()).EqualsValue(this.value);
            //push it
            stack.Pop();

            stack.InsertTop(new StackObjectBoolean(e));
        }
        public bool ExecuteCommand(string command, Stacker stack)
        {
            //"ClassicTetris", "RowMode", "SClusterMode", "BClusterMode", "MCluster Mode", "FlashlightMode", "WinGame", "EndGame", "ClearBoard"
            if(command == "ClassicTetris")
            {
                game.SetClassicMode();
            }
            else if (command == "RowMode")
            {
                game.SetRowMode();
            } else if(command == "UsePentaPieces")
            {
                game.AddPentonimoes();
            }
            else if (command == "SClusterMode")
            {
                game.SetClusterMode(9, 100);
            }
            else if (command == "MClusterMode")
            {
                game.SetClusterMode(16, 100);
            }
            else if (command == "BClusterMode")
            {
                game.SetClusterMode(20, 100);
            }
            else if (command == "FlashlightMode")
            {
                //flashlight
                flashLight = true;
                game.SetFlashLight(true);
            }
            else if (command == "WinGame")
            {
                GameEnded = true;
                GameLost = false;
                if(pack != null)
                pack.UnlockNext();
                //win
            }
            else if (command == "SetText")
            {

                if(stack.Peek() is StackObjectString)
                {
                    text = ((StackObjectString)stack.Pop()).GetValue();
                }
                //win
            }
            else if (command == "EndGame")
            {
                GameEnded = GameLost = true;
                //lose
            }
            else if (command == "ClearBoard")
            {
                game.SetBoard(new ByteBoard());
            }

            return false;
        }
예제 #20
0
        private void BuildStacker()
        {
            Stacker stack = new Stacker();
            stack.SetStack(convertArray<StackObject>((Object[])variablesToBuild.Peek()["Stack"]));
            buildStack.Push(stack);

            currentClass.Pop();
            variablesToBuild.Pop();
        }