Esempio n. 1
0
        public CommonTree BuildAST(string script)
        {
            var input = new ANTLRStringStream(script);
            var lexer = new NPortugolLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new NPortugolParser(tokens);
            var ast = parser.script();

            return (CommonTree) ast.Tree;
        }
        public Module Compile(string function)
        {
            var input = new ANTLRStringStream(function);
            var lexer = new NPortugolLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new NPortugolParser(tokens);

            var ast = parser.script();
            var tree = (CommonTree)ast.Tree;
            var nodes = new CommonTreeNodeStream(tree) { TokenStream = tokens };
            var walker = new NPortugolWalker(nodes);

            return walker.compile();
        } 
Esempio n. 3
0
        public Bytecode Compilar(string script)
        {
            var input  = new ANTLRStringStream(script);
            var lexer  = new NPortugolLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new NPortugolParser(tokens);

            var ast = parser.script();

            var tree   = (CommonTree)ast.Tree;
            var nodes  = new CommonTreeNodeStream(tree) { TokenStream = tokens };
            var walker = new NPortugolWalker(nodes) { DebugInfo = DebugInfo };

            var asm = walker.script();

            return new Bytecode(asm, parser.Functions, walker.SourceMap);
        }
Esempio n. 4
0
        public void Parse(string script)
        {
            NPortugolParser parser = null;

            try
            {
                configRepo.SaveScript(script);

                MainPresenter.MainView.ClearOutput();

                var input = new ANTLRStringStream(script);
                var lexer = new NPortugolLexer(input);
                var tokens = new CommonTokenStream(lexer);
                parser = new NPortugolParser(tokens);

                var r = parser.script();

                var t = (CommonTree)r.Tree;

                CreateASTGraph(t);
            }
            catch (RecognitionException ex)
            {
                var message = parser.GetErrorMessage(ex);

                MainPresenter.Error(message);
            }
            catch (Exception ex)
            {
                throw new Exception((string.Format("Putz... Erro não identificado :( [{0}]", ex.Message)));
            }
        }