static string CalculateBoolOp(string op, TerminalEnums.varTypes typeOp, char _) { string[] items = op.Split(' '); if (items.Length < 3) { if (items[0] != "") { return(items[0]); } if (items[1] != "") { return(items[1]); } else { return(""); } } else if (typeOp == TerminalEnums.varTypes.Bool) { return(CalculateBool(items[0], items[1], items[2])); } else { return("True"); } }
static string CalculateOp(string op, TerminalEnums.varTypes typeOp, char _) { string[] items = op.Split(' '); Debug.Log(op); if (items.Length < 3) { if (items[0] != "") { return(items[0]); } if (items[1] != "") { return(items[1]); } else { return(""); } } else if (typeOp == TerminalEnums.varTypes.Int) { return(CalculateInt(Convert.ToInt32(double.Parse(items[0], CultureInfo.InvariantCulture)), items[1], Convert.ToInt32(double.Parse(items[2], CultureInfo.InvariantCulture)))); } else if (typeOp == TerminalEnums.varTypes.Double) { return(CalculateDouble(double.Parse(items[0], CultureInfo.InvariantCulture), items[1], double.Parse(items[2], CultureInfo.InvariantCulture))); } else { return(items[0] + " " + items[2]); } return(null); }
public Symbol(string value, TerminalEnums.varTypes type, TerminalEnums.varStructure structure, int size1, int size2) { varStructure = structure; varType = type; varValue = value; sizex = size1; sizey = size2; }
public Symbol(string value, TerminalEnums.varTypes type, TerminalEnums.varStructure structure) { varStructure = structure; varType = type; varValue = value; sizex = -1; sizey = -1; }
private static string DoSubOperation(string input, TerminalEnums.varTypes typeOp) { Dictionary <char, char> bracketPairs = new Dictionary <char, char> () { { '(', ')' } }; Stack <char> brackets = new Stack <char> (); input = RemoveSpaces(input); int init = -1; // Iterate through each character in the input string for (int i = 0; i < input.Length; i++) { // check if the character is one of the 'opening' brackets if (input[i] == '(') { if (brackets.Count == 0) { init = i; } // if yes, push to stack brackets.Push(input[i]); } else // check if the character is one of the 'closing' brackets if (brackets.Count > 0) { // check if the closing bracket matches the 'latest' 'opening' bracket if (input[i] == ')') { brackets.Pop(); if (brackets.Count == 0) { input = ReplaceOp(input, init, i - init, DoSubOperation(RemoveSpaces(input.Substring(init + 1, i - init - 1)), typeOp)); i = -1; continue; } } } else { continue; } } // Ensure all brackets are closed Debug.Log(typeOp); if (typeOp == TerminalEnums.varTypes.Bool) { return(RemoveSpaces(ResolveBoolOp(input, typeOp))); } else { return(RemoveSpaces(ResolveOp(input, typeOp))); } }
public bool CreateVar(int scope, string name, string value, TerminalEnums.varTypes type, TerminalEnums.varStructure structure) { if (scope < symbolTable.Count) { return(symbolTable[scope].CreateVar(name, value, type)); } else { return(false); } }
public bool CreateVar(string name, string value, TerminalEnums.varTypes type, int i, int j) { try { scope.Add(name, new Symbol(value, type, TerminalEnums.varStructure.Matrix, i, j)); return(true); } catch (Exception) { scope[name] = new Symbol(value, type, TerminalEnums.varStructure.Matrix, i, j); return(true); } return(false); }
static string ResolveOp(string op, TerminalEnums.varTypes typeOp) { for (int i = 0; i < op.Length; i++) { if ((op[i] == '*' || op[i] == '/' || op[i] == '%')) { if (i < op.Length - 1) { if (op[i + 1] == ' ') { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateOp(RemoveSpaces(subOp), typeOp, op[i])); i = -1; } } else { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateOp(RemoveSpaces(subOp), typeOp, op[i])); i = -1; } } } for (int i = 0; i < op.Length; i++) { if ((op[i] == '+' || op[i] == '-')) { if (i < op.Length - 1) { if (op[i + 1] == ' ') { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateOp(RemoveSpaces(subOp), typeOp, op[i])); i = -1; } } else { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateOp(RemoveSpaces(subOp), typeOp, op[i])); i = -1; } } } return(op); }
public TerminalEnums.varTypes GetVarType(string name, int startScope) { int searchScope = startScope; while (searchScope >= 0) { TerminalEnums.varTypes s = symbolTable[searchScope].GetVarType(name); if (s != TerminalEnums.varTypes.Null) { return(s); } else { searchScope = symbolTable[searchScope].parent; } } return(TerminalEnums.varTypes.Null); }
public override IEnumerator RunBlock() { if (TerminalCancelManager.instance.cancel) { yield return(null); } MarkExec(); newType = GetNewType(oldType); st.symbolTable[scopeId].CreateVar(name, CreateInitArray(GetInitValue(newType), sizex), newType, sizex); yield return(new WaitForSeconds(ExecTimeManager.instance.execTime)); //call Next if (nextBlock != null && !TerminalCancelManager.instance.cancel) { nextBlock.scopeId = scopeId; yield return(StartCoroutine(nextBlock.RunBlock())); } yield return(new WaitForSeconds(ExecTimeManager.instance.execTime)); }
TerminalEnums.varTypes GetNewType(string t) { TerminalEnums.varTypes newType; switch (t) { case "Float": newType = TerminalEnums.varTypes.Double; break; case "Int": newType = TerminalEnums.varTypes.Int; break; default: newType = TerminalEnums.varTypes.Bool; break; } return(newType); }
VariableManager.Type GetType(string t) { VariableManager.Type newType; switch (t) { case "Float": newType = VariableManager.Type.Float; break; case "Int": newType = VariableManager.Type.Int; break; default: newType = VariableManager.Type.Bool; break; } return(newType); }
private string GetInitValue(TerminalEnums.varTypes t) { switch (t) { case TerminalEnums.varTypes.String: return("\"\""); case TerminalEnums.varTypes.Int: return("0"); case TerminalEnums.varTypes.Double: return("0.0"); case TerminalEnums.varTypes.Bool: return("_True"); default: return(""); } }
public override IEnumerator RunBlock() { if (TerminalCancelManager.instance.cancel) { yield return(null); } Debug.Log("Inicializando " + name + "..."); MarkExec(); newType = GetNewType(oldType); st.symbolTable[scopeId].CreateVar(name, GetInitValue(newType), newType); yield return(new WaitForSeconds(ExecTimeManager.instance.execTime)); if (nextBlock != null && !TerminalCancelManager.instance.cancel) { nextBlock.scopeId = scopeId; yield return(StartCoroutine(nextBlock.RunBlock())); } AfterExec(); yield return(null); }
static string ResolveBoolOp(string op, TerminalEnums.varTypes typeOp) { for (int i = 0; i < op.Length; i++) { if ((op[i] == '>' || op[i] == '<' || op[i] == '=')) { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateBoolOp(subOp, typeOp, op[i])); i = -1; } } for (int i = 0; i < op.Length; i++) { if ((op[i] == '|' || op[i] == '&')) { string subOp = FindOp(i, op); op = op.Replace(RemoveSpaces(subOp), CalculateBoolOp(RemoveSpaces(subOp), typeOp, op[i])); i = -1; } } return(op); }
public static string StartOperation(string input, TerminalEnums.varTypes typeOp, int scope) { input = ClearVarNames(input, scope); return(DoSubOperation(input, typeOp)); }