コード例 #1
0
 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");
     }
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 public Symbol(string value, TerminalEnums.varTypes type, TerminalEnums.varStructure structure, int size1, int size2)
 {
     varStructure = structure;
     varType      = type;
     varValue     = value;
     sizex        = size1;
     sizey        = size2;
 }
コード例 #4
0
 public Symbol(string value, TerminalEnums.varTypes type, TerminalEnums.varStructure structure)
 {
     varStructure = structure;
     varType      = type;
     varValue     = value;
     sizex        = -1;
     sizey        = -1;
 }
コード例 #5
0
    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)));
        }
    }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
 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);
 }
コード例 #9
0
    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);
    }
コード例 #10
0
ファイル: TerminalArray.cs プロジェクト: zenetoshl/MazeCode
    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));
    }
コード例 #11
0
ファイル: TerminalArray.cs プロジェクト: zenetoshl/MazeCode
    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);
    }
コード例 #12
0
ファイル: TerminalArray.cs プロジェクト: zenetoshl/MazeCode
    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);
    }
コード例 #13
0
ファイル: TerminalArray.cs プロジェクト: zenetoshl/MazeCode
    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("");
        }
    }
コード例 #14
0
ファイル: TerminalVar.cs プロジェクト: zenetoshl/MazeCode
    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);
    }
コード例 #15
0
 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);
 }
コード例 #16
0
 public static string StartOperation(string input, TerminalEnums.varTypes typeOp, int scope)
 {
     input = ClearVarNames(input, scope);
     return(DoSubOperation(input, typeOp));
 }