Exemplo n.º 1
0
 public Method(string name, string typeI, NList param)
 {
     Name       = name;
     type       = (Type)Enum.Parse(typeof(Type), typeI + "_type");
     this.param = param;
     CalcHash();
     id = Id.METHOD;
 }
Exemplo n.º 2
0
        public void Add(string t, string p)
        {
            NList temp = this;

            while (true)
            {
                if (temp.next == null)
                {
                    temp.next = new NList(t, p); break;
                }
                temp = temp.next;
            }
        }
Exemplo n.º 3
0
        public void Add(string t, string p)
        {
            //добавление в список
            //создаю локальную переменную, которая хранит ссылку, на текущее значение, чтобы не испортить значение в классе(если просто использовать переменную next то мы не сможем вернуться к первоночальному значению(мы его сотрем))
            NList temp = this;

            //из-за ссылки у нас изменения в temp типа добавить в next или изменить где-то значение будут влиять на первоначальную переменную
            while (true)
            {
                if (temp.next == null)
                {
                    temp.next = new NList(t, p); break;
                }
                temp = temp.next;
            }
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            string s    = "";
            NList  temp = this;

            while (true)
            {
                if (temp == null)
                {
                    break;
                }
                s   += temp.method + " " + temp.type + " |";
                temp = temp.next;
            }
            s = s.Remove(s.Length - 1);
            return(s);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Tree         tree   = new Tree();
            StreamReader Reader = new StreamReader("input.txt");
            string       varReg = @"(int||sbyte||short||long||byte||ushort||uint||ulong||char||float||double||decimal||bool||object||string)";
            Regex        vars   = new Regex(@"^" + varReg + @"(\[\]||\[\,\])(\s)\D\w*(\;)");
            Regex        type   = new Regex(varReg);
            Regex        var    = new Regex(@"\D\w*\s*\=\s*\d+\;");
            Regex        Class  = new Regex(@"class\s\D\w*\;");
            Regex        method = new Regex(@"(int||sbyte||short||long||byte||ushort||uint||ulong||char||float||double||decimal||bool||object||string||void)\s\D\w*\(((\s*((ref||out)\s)*" + varReg + @"\s\D\w*\,)*(\s((ref||out)\s)*" + varReg + @"\s\D\w*))?\)\;");

            while (true)
            {
                string   line = line = Reader.ReadLine();
                string[] masLine;
                try
                {
                    masLine = line.Split(' ');
                }
                catch
                {
                    break;
                }
                masLine[masLine.Length - 1] = masLine[masLine.Length - 1].Remove(masLine[masLine.Length - 1].Length - 1);
                if (vars.IsMatch(line))
                {
                    tree.Add(new Var(masLine[1], masLine[0]));
                }
                else
                {
                    if (masLine[0] == "const")
                    {
                        if (type.IsMatch(masLine[1]))
                        {
                            string s = "";
                            for (int i = 2; i < masLine.Length; i++)
                            {
                                s += masLine[i];
                            }
                            tree.Add(new Const(masLine[2], masLine[1], masLine[masLine.Length - 1]));
                        }
                    }
                    else
                    if (Class.IsMatch(line))
                    {
                        tree.Add(new Class(masLine[1]));
                    }
                    else
                    {
                        if (method.IsMatch(line))
                        {
                            string   methodType = masLine[0];
                            string   name       = line.Split(' ', '(')[1];
                            string[] paraMs     = line.Split('(', ',', ')');
                            string[] temp       = new string[paraMs.Length - 2];
                            NList    paramsMet;
                            for (int i = 1; i < paraMs.Length - 1; i++)
                            {
                                temp[i - 1] = paraMs[i];
                            }
                            if (temp[0] != "")
                            {
                                string[] s = temp[0].Split(' ');
                                if (s.Length == 3)
                                {
                                    paramsMet = new NList(s[0], s[1]);
                                }
                                else
                                {
                                    paramsMet = new NList("var", s[1]);
                                }
                                for (int i = 1; i < temp.Length; i++)
                                {
                                    string[] s1 = temp[i].Split(' ');
                                    if (s1.Length == 4)
                                    {
                                        paramsMet.Add(s1[1], s1[2]);
                                    }
                                    else
                                    {
                                        paramsMet.Add("var", s1[1]);
                                    }
                                }
                                tree.Add(new Method(name, methodType, paramsMet));
                            }
                            else
                            {
                                tree.Add(new Method(name, methodType));
                            }
                        }
                        else
                        {
                            Console.WriteLine("Найдено не совпадение");
                        }
                    }
                }
            }
            Reader.Close();
        }