Exemplo n.º 1
0
        static bool debug_new_class(string text)
        {
            var  root = BuildAST_Cool.BUILD(text);
            var  v0   = new CheckClassesVisitor();
            bool r    = true;

            return(v0.Visit(root));

            try
            {
                r = v0.Visit(root);
                Console.WriteLine(r);
            }
            catch (Exception)
            {
                Console.WriteLine("Se partio debug class");
            }

            Console.WriteLine(r + "class");
            return(r);

            //Debug_ITree(text);
            //Debug_AST(text);
            //Debug_SemanticTypes(text);
            Debug_ASTCIL(text);
            //Debug_CILProgram(text);
        }
Exemplo n.º 2
0
        public static void Debug_SemanticTypes(string text)
        {
            var root = BuildAST_Cool.BUILD(text);

            foreach (var item in SemanticType.BuildAllType(root.class_list))
            {
                Console.WriteLine("-----------------------");
                Console.WriteLine("Type : {0} <- {1} ( lvl : {2} )", item.Value.Name, item.Value.Father, item.Value.Level);
                Console.WriteLine("> ATTRS:");

                foreach (var attr in item.Value.GetAllAttr())
                {
                    Console.WriteLine(attr);
                }

                Console.WriteLine("> METHODS:");
                foreach (var meth in item.Value.GetAllMethods())
                {
                    Console.Write("{0} : {1} (", meth.Name, meth.ReturnType.Name);
                    foreach (var attr in meth.AttrParams)
                    {
                        Console.Write("{0}, ", attr);
                    }
                    Console.WriteLine(")");
                }

                Console.WriteLine("-----------------------");
            }
        }
Exemplo n.º 3
0
        static bool debug_new_types(string text)
        {
            var root = BuildAST_Cool.BUILD(text);
            var v0   = new CheckTypesVisitor();

            return(v0.Visit(root));

            bool r = true;

            try
            {
                r = v0.Visit(root);
                Console.WriteLine(r);
            }
            catch (Exception)
            {
                Console.WriteLine("Se partio debug types");
            }
            Console.WriteLine(r + "types");
            if (!r)
            {
                foreach (var item in v0.CurrErrorLoger.Log)
                {
                    Console.WriteLine(item);
                }
            }
            return(r);
        }
Exemplo n.º 4
0
        public void AST_Build_test()
        {
            string   text = @"1+1; (2+4)*3 + 1; true + false -1;";
            AST_Root r    = BuildAST_Cool.BUILD(text);

            Assert.IsNotNull(r);
            Assert.AreEqual(r.Children[0].Children.Count, 3);
        }
Exemplo n.º 5
0
        public void AST_Asignation_test()
        {
            string   text             = @"b <- 11; a <- b + 2; b <- 1; a + b + 1;";
            AST_Root r                = BuildAST_Cool.BUILD(text);
            AST_Execute_Interpreter v = new AST_Execute_Interpreter();

            Assert.IsNotNull(r);
            Assert.AreEqual(v.Visit(r), 15);
        }
Exemplo n.º 6
0
        public static void Debug_CILProgram(string text)
        {
            var root     = BuildAST_Cool.BUILD(text);
            var cil_root = CILCompiler.Build(root);
            var sem      = SemanticType.BuildAllType(root.class_list);
            var solve    = CIL_Execute.Execute(cil_root, sem);

            Console.WriteLine(solve);
        }
Exemplo n.º 7
0
        public void AST_If_Else_test()
        {
            string   text             = @"a <- 0; if a = 1 then { a <- 2; } else {a <- 3} fi; a * 2;";
            AST_Root r                = BuildAST_Cool.BUILD(text);
            AST_Execute_Interpreter v = new AST_Execute_Interpreter();

            Assert.IsNotNull(r);
            Assert.AreEqual(v.Visit(r), 6);
        }
Exemplo n.º 8
0
        public void AST_STRCte()
        {
            string   text = "id <- \"string separate space\"; a <- \"other\nstr\n\";";
            AST_Root r    = BuildAST_Cool.BUILD(text);
            var      v    = (AST_StringCte)r.Children[0].Children[0].Children[0];
            var      v2   = (AST_StringCte)r.Children[0].Children[1].Children[0];

            Assert.AreEqual("string separate space", v.ToString());
            Assert.AreEqual("other\nstr\n", v2.ToString());
        }
Exemplo n.º 9
0
        public static void Debug_ASTCIL(string text, string path = "cil.il")
        {
            var    root     = BuildAST_Cool.BUILD(text);
            var    cil_root = CILCompiler.Build(root);
            string s        = cil_root.ToString();
            var    w        = new StreamWriter(path);

            w.Write(s);
            w.Close();
        }
Exemplo n.º 10
0
        public static void Debug_Mips(string text, string path = "mips.s")
        {
            var root     = BuildAST_Cool.BUILD(text);
            var cil_root = CILCompiler.Build(root);
            var sem      = SemanticType.BuildAllType(root.class_list);
            //var solve = CIL_Execute.Execute(cil_root, sem);
            var    prog = new MipsCompiler(cil_root, sem);
            string s    = (prog.Visit(cil_root));
            //Console.WriteLine(s);
            var w = new StreamWriter(path);

            w.Write(s);
            w.Close();
        }
Exemplo n.º 11
0
        static void Compilator(string path, string dest, string mips)
        {
            var r = new StreamReader(path);

            var text = r.ReadToEnd();

            var root = BuildAST_Cool.BUILD(text);

            if (root == null)
            {
                return;
            }

            var result = SemanticChecking(root);

            if (result.Item1)
            {
                var    cil_root = CILCompiler.Build(root);
                string s        = cil_root.ToString();
                var    w        = new StreamWriter(dest);
                //Console.WriteLine(s);
                w.Write(s);
                w.Close();
                var sem = SemanticType.BuildAllType(root.class_list);
                //var solve = CIL_Execute.Execute(cil_root, sem);
                var prog = new MipsCompiler(cil_root, sem);
                s = (prog.Visit(cil_root));
                //Console.WriteLine(s);
                var t = new StreamWriter(mips);
                //Console.WriteLine(s);
                t.Write(s);
                t.Close();
            }
            else
            {
                Console.WriteLine("There are some errors!!!");
                foreach (var item in result.Item2.Log)
                {
                    Console.WriteLine(item);
                }
            }
        }
Exemplo n.º 12
0
        public void AST_While_Fib_test()
        {
            string   text             = @"
                                a <- 0; 
                                b <- 1;
                                n <- 2; 
                                while n < 9 loop { 
                                    c <- a + b;
                                    a <- b;
                                    b <- c;
                                    n <- n + 1;
                                    } pool;
                                b;
                                ";
            AST_Root r                = BuildAST_Cool.BUILD(text);
            AST_Execute_Interpreter v = new AST_Execute_Interpreter();

            Assert.IsNotNull(r);
            Assert.AreEqual(v.Visit(r), 21);
        }
Exemplo n.º 13
0
        static bool debug_new_vars(string text)
        {
            var root = BuildAST_Cool.BUILD(text);
            var v0   = new CheckVariablesVisitor();

            return(v0.Visit(root));

            bool r = true;

            try
            {
                r = v0.Visit(root);
                Console.WriteLine(r);
            }
            catch (Exception)
            {
                //Console.WriteLine("Se partio debug shit vars");
            }
            Console.WriteLine(r + "vars");
            return(r);
        }
Exemplo n.º 14
0
        static bool debug_new_shit(string text)
        {
            var root = BuildAST_Cool.BUILD(text);
            var v0   = new CheckIDSandTypeDecVisitor();

            return(v0.Visit(root));

            bool r = true;

            try
            {
                r = v0.Visit(root);
                Console.WriteLine(r);
            }
            catch (Exception)
            {
                Console.WriteLine("Se partio debug shit");
            }
            Console.WriteLine(r + "shit");
            return(r);
        }
Exemplo n.º 15
0
        static void OldMain()
        {
            var f = new StreamReader("main.cl");

            string text = f.ReadToEnd();

            Console.WriteLine(text);
            //Debug_CILProgram(text);
            var root = BuildAST_Cool.BUILD(text);


            //Debug_AST(text);
            //Debug_SemanticTypes(text);
            //Debug_ASTCIL(text);
            //Debug_Mips(text);
            //Console.WriteLine(Debug_Semantic(text));

            #region Debug Folders

            Console.WriteLine("*****Testing Success Files*****");
            Debug_Semantic_Files_Success();
            Console.WriteLine("*****End Success Files*****");
            Console.WriteLine("\n*****Testing Fail Files*****");
            Debug_Semantic_Files_Fail();
            Console.WriteLine("*****End Success Files*****");
            #endregion
            //asd
            #region debug file

            //debug_new_shit(text);
            //debug_new_class(text);
            //debug_new_vars(text);
            //debug_new_types(text);

            #endregion
        }
Exemplo n.º 16
0
        public static Tuple <bool, bool, bool> Debug_Semantic(string text)
        {
            bool ans;
            var  root = BuildAST_Cool.BUILD(text);

            //check variables

            var v1 = new CheckVariablesVisitor();
            //try
            //{
            //    ans = v1.Visit(root);
            //    Console.WriteLine("Checkeo de variables: {0}", ans);
            //    if (!ans)
            //    {
            //        foreach (var item in v1.CurrErrorLoger.Log)
            //        {
            //            Console.WriteLine(item);
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    Console.WriteLine("Se partio el checkeo de variables");
            //}

            //check types
            var v2 = new CheckTypesVisitor();
            //ans = v2.Visit(root);
            //try
            //{
            //    ans = v2.Visit(root);
            //    Console.WriteLine("Checkeo de tipos: {0}", ans);
            //    if (!ans)
            //    {
            //        foreach (var item in v2.CurrErrorLoger.Log)
            //        {
            //            Console.WriteLine(item);
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    Console.WriteLine("Se partio el checkeo de tipos");
            //}

            ////check classes
            var v3 = new CheckClassesVisitor();

            //try
            //{
            //    ans = v3.Visit(root);
            //    Console.WriteLine("Checkeo de classes: {0}", ans);
            //    if (!ans)
            //    {
            //        foreach (var item in v3.CurrErrorLoger.Log)
            //        {
            //            Console.WriteLine(item);
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    Console.WriteLine("Se partio el checkeo de classes");
            //}

            return(new Tuple <bool, bool, bool>(v1.Visit(root), v2.Visit(root), v3.Visit(root)));
        }
Exemplo n.º 17
0
 public static void Debug_AST(string text)
 {
     Travels.DFS(BuildAST_Cool.BUILD(text));
 }