protected virtual int EvaluateInternal(IWarriorParser parser, int currentAddress)
        {
            string fullName = GetFullName(parser, currentAddress);

            if (parser.Variables.ContainsKey(fullName))
            {
                Expression ex = parser.Variables[fullName];
                if (ex == this)
                {
                    parser.WriteError("Label not yet resolved: " + fullName + " at " + Location, Location);
                    return(0);
                }
                return(ex.Evaluate(parser, currentAddress));
            }
            else
            {
                parser.WriteError("Label not defined: " + fullName + " at " + Location, Location);
                return(0);
            }
        }
        public override Mode GetMode(IWarriorParser parser, int currentAddress)
        {
            string fullName = GetFullName(parser, currentAddress);

            if (parser.Variables.ContainsKey(fullName))
            {
                Expression ex = parser.Variables[fullName];
                if (ex == this)
                {
                    parser.WriteError("Label not yet resolved: " + fullName + " at " + Location, Location);
                    return(0);
                }
                return(ex.GetMode(parser, currentAddress));
            }
            else
            {
                parser.WriteError("Label not defined: " + fullName + " at " + Location, Location);
                return(0);
            }
        }
Esempio n. 3
0
 public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress,
                                       int coreSize, bool evaluate)
 {
     if (!evaluate)
     {
         return;
     }
     if (expression.Evaluate(parser, currentAddress) == 0)
     {
         parser.WriteError("Assert failed : " + this + " at : " + Location, Location);
     }
 }
 public override int Evaluate(IWarriorParser parser, int currentAddress)
 {
     if (inEval)
     {
         parser.WriteError("Cyclic definition of function : " + name + " at " + Location, Location);
         return(0);
     }
     try
     {
         return(EvaluateInternal(parser, currentAddress));
     }
     finally
     {
         inEval = false;
     }
 }
        public override int Evaluate(IWarriorParser parser, int currentAddress)
        {
            int l = left.Evaluate(parser, currentAddress);
            int r = right.Evaluate(parser, currentAddress);

            switch (operation)
            {
            case BinaryOperation.Plus:
                return(l + r);

            case BinaryOperation.Minus:
                return(l - r);

            case BinaryOperation.Multiply:
                return(l * r);

            case BinaryOperation.Divide:
                if (r == 0)
                {
                    parser.WriteError("Divide by zero during evaluation of " + ToString() + " at " + Location, Location);
                    return(0);
                }
                return(l / r);

            case BinaryOperation.Modulo:
                if (r == 0)
                {
                    parser.WriteError("Divide by zero during evaluation of " + ToString() + " at " + Location, Location);
                    return(0);
                }
                return(l % r);

            case BinaryOperation.BinOr:
                return(l | r);

            case BinaryOperation.BinXor:
                return(l ^ r);

            case BinaryOperation.BinAnd:
                return(l & r);

            case BinaryOperation.Shl:
                return(l << r);

            case BinaryOperation.Shr:
                return(l >> r);

            case BinaryOperation.Or:
                return(((l != 0) || (r != 0)) ? 1 : 0);

            case BinaryOperation.And:
                return(((l != 0) && (r != 0)) ? 1 : 0);

            case BinaryOperation.CompareGt:
                return((l > r) ? 1 : 0);

            case BinaryOperation.CompareGe:
                return((l >= r) ? 1 : 0);

            case BinaryOperation.CompareLe:
                return((l <= r) ? 1 : 0);

            case BinaryOperation.CompareLt:
                return((l < r) ? 1 : 0);

            case BinaryOperation.CompareEq:
                return((l == r) ? 1 : 0);

            case BinaryOperation.CompareNe:
                return((l != r) ? 1 : 0);

            default:
                throw new InvalidOperationException();
            }
        }