Example #1
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            bool hadErrors = false;

            try { LType = LValue.Process(parser, level + 1); }
            catch (ScriptCriticalErrorException) { hadErrors = true; }

            try { RType = RValue.Process(parser, level + 1); }
            catch (ScriptCriticalErrorException) { hadErrors = true; }

            if (hadErrors)
            {
                throw new ScriptCriticalErrorException();                 // we are not going to try the operator because one of nodes had an error
            }
            dynamic a, b, c;

            a = LType.GetSampleValue();
            b = RType.GetSampleValue();
            try {
                c          = ApplyOperator(a, b);
                ResultType = ScriptVariableTypeExtension.GetScriptVariableType(c);
            }
            catch (UserFriendlyException) {
                throw;
            }
            catch {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.CriticalError, ErrorCode.OperatorCannotBeApplied2, this, LType, RType));
                throw new ScriptCriticalErrorException();
            }

            return(ResultType);
        }
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            CastFromType     = Value.Process(parser, level + 1);
            CastToSystemType = CastToType.GetSystemType();

            dynamic a = CastFromType.GetSampleValue();

            try {
                a = Convert.ChangeType(a, CastToSystemType);
            }
            catch {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.NoExplicitConversion, this, CastFromType, CastToType));
            }

            if (parser.DebugParsing)
            {
                Utils.IndentedOutput(level, "Explicit cast from '{0}' to '{1}' ({2})", CastFromType, CastToType, CastToSystemType);
            }

            return(CastToType);
        }
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            ValueType = Value.Process(parser, level + 1);

            dynamic a, b;

            a = ValueType.GetSampleValue();
            try {
                b          = ApplyOperator(ref a);
                ResultType = ScriptVariableTypeExtension.GetScriptVariableType(b);
            }
            catch (UserFriendlyException) {
                throw;
            }
            catch {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.CriticalError, ErrorCode.OperatorCannotBeApplied1, this, ValueType));
                throw new ScriptCriticalErrorException();
            }

            return(ValueType);
        }