public static string TypeToString(Variable.VarType type) { switch (type) { case Variable.VarType.NUMBER: return("NUMBER"); case Variable.VarType.STRING: return("STRING"); case Variable.VarType.ARRAY_STR: case Variable.VarType.ARRAY_NUM: case Variable.VarType.ARRAY: return("ARRAY"); case Variable.VarType.MAP_STR: case Variable.VarType.MAP_NUM: return("MAP"); case Variable.VarType.OBJECT: return("OBJECT"); case Variable.VarType.BREAK: return("BREAK"); case Variable.VarType.CONTINUE: return("CONTINUE"); case Variable.VarType.UNDEFINED: return("UNDEFINED"); default: return("NONE"); } }
public static string[] GetCompiledFunctionSignature(ParsingScript script, out Dictionary <string, Variable> dict) { script.MoveForwardIf(Constants.START_ARG, Constants.SPACE); int endArgs = script.FindFirstOf(Constants.END_ARG.ToString()); if (endArgs < 0) { throw new ArgumentException("Couldn't extract function signature"); } string argStr = script.Substr(script.Pointer, endArgs - script.Pointer); List <string> args = GetCompiledArgs(argStr); //string[] args = argStr.Split(Constants.NEXT_ARG_ARRAY, StringSplitOptions.RemoveEmptyEntries); dict = new Dictionary <string, Variable>(args.Count); var sep = new char [] { ' ' }; for (int i = 0; i < args.Count; i++) { string[] pair = args[i].Trim().Split(sep, StringSplitOptions.RemoveEmptyEntries); Variable.VarType type = pair.Length > 1 ? Constants.StringToType(pair[0]) : Variable.VarType.STRING; dict.Add(pair[pair.Length - 1], new Variable(type)); args[i] = pair[pair.Length - 1]; } string[] result = args.Select(element => element.Trim()).ToArray(); script.Pointer = endArgs + 1; return(result); }
public Precompiler(string functionName, string [] args, Dictionary <string, Variable> argsMap, string cscsCode) { m_functionName = functionName; m_defArgs = args; m_argsMap = argsMap; m_cscsCode = cscsCode; m_returnType = GetReturnType(m_functionName); }
public Precompiler(string functionName, string[] args, Dictionary <string, Variable> argsMap, string cscsCode, ParsingScript parentScript) { m_functionName = functionName; m_defArgs = args; m_argsMap = argsMap; m_cscsCode = cscsCode; m_returnType = GetReturnType(m_functionName); m_parentScript = parentScript; }
public string GetExpressionType(List <string> tokens, string functionName, ref bool addNewVarDef) { if (!tokens[0].Contains("[")) { return(m_depth + "var " + functionName); } bool firstString = tokens[0].Contains("\""); bool secondString = true; for (int i = 1; i < tokens.Count; i++) { string token = tokens[i]; Variable.VarType type = GetVariableType(token); if (type != Variable.VarType.NONE) { secondString = type != Variable.VarType.NUMBER; break; } } string expr = m_depth; string param1 = firstString ? "string" : "double"; string param2 = secondString ? "string" : "double"; if (!firstString) { expr += "List<" + param2 + "> " + functionName + " = new List<" + param2 + "> ();\n"; } else { expr += "Dictionary<string," + param2 + "> " + functionName + " = new Dictionary<string," + param2 + "> ();\n"; } int position = -1; if (m_definitionsMap.TryGetValue(functionName, out position)) { // There was a definition like m={}; sometime before. Now we know what it meant, // so we can insert it: m_converted.Insert(position, expr); expr = ""; } expr += m_depth + tokens[m_tokenId]; while (++m_tokenId < tokens.Count) { string token = tokens[m_tokenId]; string converted = ProcessToken(tokens, m_tokenId, ref addNewVarDef); expr += converted; } m_tokenId = tokens.Count; addNewVarDef = false; return(expr); }
public static Type CSCSTypeToCSType(Variable.VarType type) { switch (type) { case Variable.VarType.NUMBER: return(typeof(double)); case Variable.VarType.STRING: return(typeof(string)); case Variable.VarType.ARRAY: return(typeof(List <Variable>)); default: return(typeof(string)); } }
public static string TypeToString(Variable.VarType type) { switch (type) { case Variable.VarType.NUMBER: return "NUMBER"; case Variable.VarType.STRING: return "STRING"; case Variable.VarType.ARRAY_STR: case Variable.VarType.ARRAY_NUM: case Variable.VarType.ARRAY: return "ARRAY"; case Variable.VarType.MAP_STR: case Variable.VarType.MAP_NUM: return "MAP"; case Variable.VarType.OBJECT: return "OBJECT"; case Variable.VarType.BREAK: return "BREAK"; case Variable.VarType.CONTINUE: return "CONTINUE"; default: return "NONE"; } }
public static string TypeToCSString(Variable.VarType type) { switch (type) { case Variable.VarType.NUMBER: return("double"); case Variable.VarType.STRING: return("string"); case Variable.VarType.ARRAY: return("List<Variable>"); case Variable.VarType.BREAK: return("break"); case Variable.VarType.CONTINUE: return("continue"); default: return("string"); } }
public static string TypeToString(Variable.VarType type) { switch (type) { case Variable.VarType.NUMBER: return("NUMBER"); case Variable.VarType.STRING: return("STRING"); case Variable.VarType.ARRAY: return("ARRAY"); case Variable.VarType.BREAK: return("BREAK"); case Variable.VarType.CONTINUE: return("CONTINUE"); default: return("NONE"); } }
public VariableProperty(Variable.VarType variableType) { this.SetupVariables(); switch (variableType) { case Variable.VarType.GlobalVariable: this.variableType = GetVarType.GlobalVariable; break; case Variable.VarType.LocalVariable: this.variableType = GetVarType.LocalVariable; break; case Variable.VarType.ListVariable: this.variableType = GetVarType.ListVariable; break; } }
/// <summary> /// Creates new variable /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <param name=""></param> /// <param name="pValue"></param> public static Variable NewVariable(string pName, Variable.VarType pType, string pValue) { if (Interpreter.IsBreakpoint) { return(null); } // rise error if variable allready exists if (Graphics.Variables.ContainsKey(pName)) { Interpreter.AddError(string.Format("Variable [{0}] already exists", pName)); return(null); } else { Variable v = new Variable(pName, pType, pValue); Graphics.Variables.Add(pName, v); return(v); } }
/// <summary> /// Set variable value /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <param name="pType"></param> /// <param name="pValue"></param> public static void SetVariable(string pName, Variable.VarType pType, string pValue) { if (!Interpreter.IsBreakpoint) { if (Graphics.Variables.ContainsKey(pName)) { if (Graphics.Variables[pName].type == pType) { Graphics.Variables[pName].value = pValue; } else { Interpreter.AddError(string.Format("You cannot change data type of variable [{0}]. Actual type is [{1}].", pName, pType)); } } else { Graphics.NewVariable(pName, pType, pValue); } } }
public static Variable.VarType GetReturnType(string functionName) { Variable.VarType retType = Variable.VarType.NONE; m_returnTypes.TryGetValue(functionName, out retType); return(retType); }
public Value(string value, Variable.VarType type) { FloatValue = float.NaN; Type = type; StringValue = value; }
public Value(float value, Variable.VarType type) { FloatValue = value; Type = type; StringValue = string.Empty; }
public VariableProperty(Variable.VarType variableType) { this.SetupVariables(); this.variableType = variableType; }