Beispiel #1
0
        static void Main(string[] args)
        {
            string source = "if(someshit) cw; else cw";

            var processor = new ScriptProcessor();
            var statements = StatementProcessor.GetStatements(processor, source);
        }
Beispiel #2
0
 internal ScriptContext(ScriptProcessor processor, ScriptContext parent)
 {
     _processor = processor;
     Parent = parent;
 }
Beispiel #3
0
 public ErrorHandler(ScriptProcessor processor)
 {
     _processor = processor;
 }
Beispiel #4
0
        private SObject ExecuteExecutable(ScriptStatement statement)
        {
            if (statement.IsCompoundStatement)
            {
                ScriptProcessor processor = new ScriptProcessor(Context);

                // Remove { and }:
                string code = statement.Code.Remove(0, 1);
                code = code.Remove(code.Length - 1, 1);

                var returnObject = processor.Run(code);

                _breakIssued = processor._breakIssued;
                _continueIssued = processor._continueIssued;
                _returnIssued = processor._returnIssued;

                return returnObject;
            }
            else
            {
                string exp = ResolveParentheses(statement.Code).Trim();

                #region QuickConvert

                // have quick conversions for small statements here
                // parameter statements are much faster that way:
                if (exp == SObject.LITERAL_BOOL_TRUE)
                {
                    return CreateBool(true);
                }
                else if (exp == SObject.LITERAL_BOOL_FALSE)
                {
                    return CreateBool(false);
                }
                else if (exp == SObject.LITERAL_UNDEFINED)
                {
                    return Undefined;
                }
                else if (exp == SObject.LITERAL_NULL)
                {
                    return Null;
                }
                else if (exp.StartsWith("\"") && exp.EndsWith("\"") && !exp.Remove(exp.Length - 1, 1).Remove(0, 1).Contains("\""))
                {
                    return CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 1));
                }

                #endregion

                if (exp.Contains("."))
                    exp = EvaluateOperatorLeftToRight(exp, ".");
                if (exp.Contains("++"))
                    exp = EvaluateOperatorLeftToRight(exp, "++");
                if (exp.Contains("--"))
                    exp = EvaluateOperatorLeftToRight(exp, "--");
                if (exp.Contains("**"))
                    exp = EvaluateOperatorLeftToRight(exp, "**");
                if (exp.Contains("*"))
                    exp = EvaluateOperatorLeftToRight(exp, "*");
                if (exp.Contains("/"))
                    exp = EvaluateOperatorLeftToRight(exp, "/");
                if (exp.Contains("%"))
                    exp = EvaluateOperatorLeftToRight(exp, "%");
                if (exp.Contains("+"))
                    exp = EvaluateOperatorLeftToRight(exp, "+");
                if (exp.Contains("-"))
                    exp = EvaluateOperatorLeftToRight(exp, "-");
                if (exp.Contains("<="))
                    exp = EvaluateOperatorLeftToRight(exp, "<=");
                if (exp.Contains(">="))
                    exp = EvaluateOperatorLeftToRight(exp, ">=");
                if (exp.Contains("<"))
                    exp = EvaluateOperatorLeftToRight(exp, "<");
                if (exp.Contains(">"))
                    exp = EvaluateOperatorLeftToRight(exp, ">");
                if (exp.Contains("==="))
                    exp = EvaluateOperatorLeftToRight(exp, "===");
                if (exp.Contains("!=="))
                    exp = EvaluateOperatorLeftToRight(exp, "!==");
                if (exp.Contains("=="))
                    exp = EvaluateOperatorLeftToRight(exp, "==");
                if (exp.Contains("!="))
                    exp = EvaluateOperatorLeftToRight(exp, "!=");
                if (exp.Contains("&&"))
                    exp = EvaluateOperatorLeftToRight(exp, "&&");
                if (exp.Contains("||"))
                    exp = EvaluateOperatorLeftToRight(exp, "||");

                return ToScriptObject(exp);
            }
        }