Esempio n. 1
0
        public ASTResult GetAST(string path)
        {
            string program = File.ReadAllText(path);

            AntlrInputStream  input  = new AntlrInputStream(program);
            QLMainLexer       lexer  = new QLMainLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            QLMainParser      parser = new QLMainParser(tokens);

            //remove standard Error Listener
            parser.RemoveErrorListeners();

            //Detect more errors (like ambiguousness errors)
            //parser.AddErrorListener(new DiagnosticErrorListener());

            //add standard error listener
            parser.AddErrorListener(new ParserErrorListener());

            IParseTree tree = parser.form();

            Console.WriteLine(tree.ToStringTree(parser));
            FormVisitor visitor = new FormVisitor();
            Form        ast     = visitor.Visit(tree);

            //TypeCheck.TypeChecker.GetTypeCheckDiagnosis(ast);

            //Evaluate();

            return(new ASTResult(ast));
        }
Esempio n. 2
0
        public ASTResult BuildAST(string filePath)
        {
            string programText = File.ReadAllText(filePath);

            QLMainParser parser = new QLMainParser(
                new CommonTokenStream(
                    new QLMainLexer(
                        new AntlrInputStream(programText)
                        )));

            ParserErrorListener parseErrorListener = new ParserErrorListener();
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new ParserErrorListener());

            Form ast = new FormVisitor().Visit(parser.form());

            return new ASTResult(ast, parseErrorListener.NotificationManager);
        }
        public ASTResult BuildAST(string filePath)
        {
            string programText = File.ReadAllText(filePath);

            QLMainParser parser = new QLMainParser(
                new CommonTokenStream(
                    new QLMainLexer(
                        new AntlrInputStream(programText)
                        )));

            ParserErrorListener parseErrorListener = new ParserErrorListener();

            parser.RemoveErrorListeners();
            parser.AddErrorListener(new ParserErrorListener());

            Form ast = new FormVisitor().Visit(parser.form());

            return(new ASTResult(ast, parseErrorListener.NotificationManager));
        }