Esempio n. 1
0
        public void RegenInterpreter()
        {
            if (Interpreter != null)
            {
                Interpreter.Dispose();
            }

            Interpreter = new AzBaseInterpreter(ExtensionHandler.GetExtensions(), this, false)
            {
                HandleWrite = HandleWrite, HandleDebugMsg = HandleDebugMsg, HandleException = HandleException, HandleNonEvaluatedLine = HandleNonEvaluatedLine, HandleDoneExecuting = HandleDoneExecuting, HandleReturn = HandleReturn
            };
        }
Esempio n. 2
0
        public static KeyedVariable Serialize(string Key, string rawVar, AzBaseInterpreter interpreter, string file, int line, bool debugEnabled)
        {
            AnonymousVariable anonvar = AnonymousVariable.Serialize(rawVar, interpreter, file, line, debugEnabled);

            return(new KeyedVariable(Key, anonvar.Value, anonvar.Type));
        }
Esempio n. 3
0
        public static AnonymousVariable Serialize(string rawVariable, AzBaseInterpreter interpreter, string file, int line, bool debugEnabled)
        {
            Expression test = new Expression(rawVariable);

            if (debugEnabled)
            {
                interpreter.HandleDebugMsg("new expression: " + rawVariable);
            }

            test.EvaluateFunction  += interpreter.HandleAMethods;
            test.EvaluateParameter += interpreter.HandleAParameters;

            object result = null;

            result = test.Evaluate();

            if (debugEnabled)
            {
                interpreter.HandleDebugMsg("eval: " + result);
            }

            if (result == null)
            {
                interpreter.HandleException(new Exception(file, line, "Unknown anonymous variable or function", "'" + rawVariable + "' was unable to be identified as an anonymous variable, keyed variable, function, or an expression.  " + test.Error, ""));

                return(new AnonymousVariable(new Undefined(), typeof(Undefined))
                {
                    RawVariable = rawVariable
                });
            }
            else if (result.GetType() == typeof(AnonymousVariable) || result.GetType() == typeof(KeyedVariable) || result.GetType() == typeof(Undefined))
            {
                return((AnonymousVariable)result);
            }
            else
            {
                return new AnonymousVariable(result, result.GetType())
                       {
                           RawVariable = rawVariable
                       }
            };

            /*if (rawVariable.StartsWith("\""))
             * {
             *  if (rawVariable.EndsWith("\""))
             *  {
             *      return new AnonymousVariable(rawVariable.Trim(new char[] { '"' }), DataType.String);
             *  }
             *  else
             *  {
             *      interpreter.HandleException(new Exception(file, line, "Expexted '\"'", "", "End the string value with '\"'"));
             *      return null;
             *  }
             * }
             * else
             * {
             *  if (rawVariable == "true" || rawVariable == "false")
             *  {
             *      return new AnonymousVariable(bool.Parse(rawVariable), DataType.Bool);
             *  }
             *  else
             *  {
             *      int n;
             *      bool isNumeric = int.TryParse(rawVariable, out n);
             *
             *      if (isNumeric)
             *      {
             *          return new AnonymousVariable(n, DataType.Int);
             *      }
             *      else
             *      {
             *          if (interpreter.Variables.ContainsKey(rawVariable))
             *          {
             *              return interpreter.Variables[rawVariable];
             *          }
             *          else
             *          {
             *              Expression test = new Expression(rawVariable);
             *
             *              interpreter.Variables.ToList().ForEach(x => test.Parameters.Add(x.Key, x.Value));
             *
             *              object result = null;
             *
             *              try
             *              {
             *                  result = test.Evaluate();
             *              }
             *              catch
             *              {
             *
             *              }
             *
             *              if (result != null)
             *              {
             *
             *              }
             *              else
             *              {
             *                  interpreter.HandleException(new Exception(file, line, "Unknown anonymous variable", "'" + rawVariable + "' was unable to be identifier as an anonymous variable, keyed variable, or an expression.", ""));
             *                  return null;
             *              }
             *
             *              //test.Parameters = interpreter.Variables.ToDictionary(item => item.Key, item => (object)item.Value);
             *
             *
             *          }
             *      }
             *  }
             * }*/
        }