예제 #1
0
        static void Main(string[] args)
        {
            StreamReader astream = new StreamReader(args[0]);

            AntlrInputStream antlrStream = new AntlrInputStream(astream);

            MINICLexer lexer = new MINICLexer(antlrStream);

            CommonTokenStream tokens = new CommonTokenStream(lexer);

            MINICParser parser = new MINICParser(tokens);

            IParseTree tree = parser.compileUnit();

            Console.WriteLine(tree.ToStringTree());

            STPrinter ptPrinter = new STPrinter();

            ptPrinter.Visit(tree);

            ASTGenerator astGenerator = new ASTGenerator();

            astGenerator.Visit(tree);

            ASTPrinter astPrinter = new ASTPrinter("test.ast.dot");

            astPrinter.Visit(astGenerator.M_Root);

            MINIC2CTranslation tr = new MINIC2CTranslation();

            tr.VisitCOMPILEUNIT(astGenerator.M_Root as CASTCompileUnit, new TranslationParameters());
            tr.M_TranslatedFile.EmmitStdout();
            StreamWriter trFile = new StreamWriter(Path.GetFileName(args[0] + ".c"));

            tr.M_TranslatedFile.EmmitToFile(trFile);
            trFile.Close();
            StreamWriter m_streamWriter = new StreamWriter("CodeStructure.dot");

            tr.M_TranslatedFile.PrintStructure(m_streamWriter);
        }
예제 #2
0
        static void Main(string[] args)
        {
            StreamReader      AStream          = new StreamReader(args[0]);
            AntlrInputStream  antlrInputStream = new AntlrInputStream(AStream);
            MINICLexer        lexer            = new MINICLexer(antlrInputStream);
            CommonTokenStream tokens           = new CommonTokenStream(lexer);
            MINICParser       parser           = new MINICParser(tokens);
            IParseTree        tree             = parser.compileUnit();

            Console.WriteLine(tree.ToStringTree());

            STPrinterVisitor stPrinter = new STPrinterVisitor();

            stPrinter.Visit(tree);

            ASTGenerator astgen = new ASTGenerator();

            astgen.Visit(tree);

            ASTPrinterVisitor astPrinterVisitor = new ASTPrinterVisitor("test.ast.dot");

            astPrinterVisitor.Visit(astgen.M_Root);

            MINICTranslation cGenerator = new MINICTranslation();

            cGenerator.Visit(astgen.M_Root);
            CodeContainer file = cGenerator.FileBuilder.AssemblyCodeContainer();

            Console.WriteLine(file.ToString());

            StreamWriter m_streamWriter = new StreamWriter("CodeStructure.dot");

            cGenerator.FileBuilder.PrintStructure(m_streamWriter);

            MINICPrinter m_minicPrinter = new MINICPrinter("CodeStructure.c", file);

            m_minicPrinter.printer();
        }