Exemple #1
0
 protected ASTvariable FindOriginalVariable()
 {
     if (variable != null)
     {
         return(variable);
     }
     if (a as BinarySummatic != null)
     {
         ASTvariable    var    = (a as BinarySummatic).FindVariable();
         GetValByAdress deeper = (a as BinarySummatic).Deep();
         if (var == null)
         {
             return(deeper.FindOriginalVariable());
         }
         return(var);
     }
     return(null);
 }
Exemple #2
0
        public static IOperation ParseFrom(string s)
        {
            if (s.IndexOf('{') == 0 && s.LastIndexOf('}') == s.Length - 1)
            {
                return(new StructureDefine(MISC.getIn(s, 0)));
            }
            if (s.IndexOf('(') == 0 && s.LastIndexOf(')') == s.Length - 1)
            {
                return(BinaryOperation.ParseFrom(MISC.breakBrackets(s)));
            }


            if (s.Length > 2 && s.IndexOf("--") == s.Length - 2)
            {
                return(new Dscr(ParseFrom(s.Substring(0, s.Length - 2))));
            }

            if (s.Length > 2 && s.IndexOf("++") == s.Length - 2)
            {
                return(new Incr(ParseFrom(s.Substring(0, s.Length - 2))));
            }

            if (s.IndexOf("-") == 0)
            {
                return(new Mins(ParseFrom(s.Substring(1, s.Length - 1))));
            }

            if (s.IndexOf("!") == 0)
            {
                return(new Nega(ParseFrom(s.Substring(1, s.Length - 1))));
            }

            if (s.IndexOf("&") == 0)
            {
                IOperation gettingAdressOf = ParseFrom(s.Substring(1, s.Length - 1));

                return(new Adrs(gettingAdressOf));
            }
            if (s.IndexOf("*") == 0)
            {
                IOperation pointTo = ParseFrom(s.Substring(1, s.Length - 1));
                return(new GetValByAdress(pointTo, (pointTo).returnTypes()));

                throw new Exception("Invalid pointer selected!");
            }
            if (s.LastIndexOf("]") == s.Length - 1 && s.IndexOf("[") > 0)
            {
                string        sContainBrackets = s.Substring(s.IndexOf("["));
                List <string> getedBrs         = MISC.splitByQuad(sContainBrackets);

                IOperation resOper = ParseFrom(s.Substring(0, s.IndexOf('[')));

                for (int o = 0; o < getedBrs.Count; o++)
                {
                    IOperation currentBrsOp = BinaryOperation.ParseFrom(getedBrs[o]);
                    resOper = new GetValByAdress(new Summ(resOper, currentBrsOp), resOper.returnTypes());
                }
                return(resOper);
            }
            try
            {
                return(new ASTFunctionCall(s));
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf("is not a function") < 0)
                {
                    throw new Exception(e.Message);
                }
            }

            int varType = Math.Max((s.IndexOf("int") >= 0) ? 2 : -1, Math.Max((s.IndexOf("double") >= 0) ? 5 : -1, Math.Max((s.IndexOf("char") >= 0) ? 3 : -1,
                                                                                                                            Math.Max((s.IndexOf("string") >= 0) ? 5 : -1, (s.IndexOf("bool") >= 0) ? 3 : -1))));

            if (varType >= 0)
            {
                s = s.Insert(varType + 1, "$");
                return(new Define(s));
            }


            //f (s.IndexOf('(') == 0 && s.LastIndexOf(')') == s.Length - 1)
            //return ParseFrom(MISC.breakBrackets(s));



            try
            {
                return(new ASTvalue(s));
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf("GetAddr") == 0)
                {
                    int newAdress = int.Parse(e.Message.Split('_')[1]);
                    return(new GetValByAdress(new ASTvalue(new ValueType(VT.Cadress), (object)newAdress),
                                              ASTTree.variables[newAdress].getValueType));
                }
                throw new Exception(e.Message);
            }
        }