Exemple #1
0
        private static Tuple <bool, bool, bool, bool> Debug_Semantic(string text)
        {
            AST.Program ast = (AST.Program)GetAST.Show(text);
            //Program.DFS(ast);

            bool check_def      = false;
            bool check_types    = false;
            bool check_sym      = false;
            bool check_inherits = false;

            var DefChecker = new DefinitionsChecker();

            check_def = DefChecker.Visit(ast);
            if (check_def)
            {
                Dictionary <string, IType> types = IType.GetAllTypes(ast);
                check_inherits = InheritsChecker.Check(ast, types);
                if (check_inherits)
                {
                    ContextType context    = new ContextType(types);
                    var         SymChecker = new SymCheckerVisitor(context);
                    check_sym = SymChecker.Visit(ast);

                    if (check_sym)
                    {
                        context = new ContextType(types);
                        var TypeCheck = new TypeCheckerVisitor(context);
                        TypeCheck.Visit(ast);
                        check_types = TypeCheck.Logger == "";
                    }
                }
            }

            return(new Tuple <bool, bool, bool, bool>(check_def, check_sym, check_types, check_inherits));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            StreamReader x    = new StreamReader("a.txt");
            string       text = x.ReadToEnd();

            //Debug_Semantic_Files_Success();

            //Debug_Semantic_Files_Fails();

            AST.Program ast = (AST.Program)GetAST.Show(text);
            Program.DFS(ast);

            var  DefChecker = new DefinitionsChecker();
            bool check      = DefChecker.Visit(ast);

            Console.WriteLine(DefChecker.Logger);
            if (check)
            {
                Console.WriteLine("Definiciones OK");
                Dictionary <string, IType> types = IType.GetAllTypes(ast);

                bool check_inherits = InheritsChecker.Check(ast, types);
                if (check_inherits)
                {
                    Console.WriteLine("Herencia OK");
                    ContextType context    = new ContextType(types);
                    var         SymChecker = new SymCheckerVisitor(context);
                    bool        check_sym  = SymChecker.Visit(ast);
                    Console.WriteLine(SymChecker.Logger);

                    if (check_sym)
                    {
                        Console.WriteLine("Simbolos OK");

                        context = new ContextType(types);
                        var TypeCheck = new TypeCheckerVisitor(context);
                        TypeCheck.Visit(ast);
                        Console.WriteLine(TypeCheck.Logger);
                    }
                    else
                    {
                        Console.WriteLine("Simbolos al berro");
                    }
                }
                else
                {
                    Console.WriteLine("Herencia al berro");
                }
            }
            else
            {
                Console.WriteLine("Definiciones al berro");
            }
        }
Exemple #3
0
        public static bool Check(AST.Program ast)
        {
            var  DefChecker = new DefinitionsChecker();
            bool check      = DefChecker.Visit(ast);

            Console.WriteLine(DefChecker.Logger);
            if (check)
            {
                Dictionary <string, IType> types = IType.GetAllTypes(ast);

                bool check_inherits = InheritsChecker.Check(ast, types);
                if (check_inherits)
                {
                    ContextType context    = new ContextType(types);
                    var         SymChecker = new SymCheckerVisitor(context);
                    bool        check_sym  = SymChecker.Visit(ast);

                    if (check_sym)
                    {
                        context = new ContextType(types);
                        var TypeCheck = new TypeCheckerVisitor(context);
                        TypeCheck.Visit(ast);
                        if (TypeCheck.Logger == "")
                        {
                            Console.WriteLine("Chequeo semantico OK \n");
                            return(true);
                        }
                        else
                        {
                            Console.WriteLine(TypeCheck.Logger);
                        }
                    }
                    else
                    {
                        Console.WriteLine(SymChecker.Logger);
                    }
                }
            }
            Console.WriteLine("Falla en el chequeo semantico");
            return(false);
        }