/** * Start one module after the other and try to compile the input file. Then generate the assembler * file and create this file for jasmin. */ private static void parseCompile(String input, String fileName) throws ParserException, LexerException, IOException { String output; // Init output string StringReader reader = new StringReader(input); // Standard routine to start the parser, lexer, ... PushbackReader r = new PushbackReader(reader, 100); Lexer l = new Lexer(r); Parser parser = new Parser(l); Start start = parser.parse(); // ASTPrinter printer = new ASTPrinter(); // start.apply(printer); TypeChecker typeChecker = new TypeChecker(); // Starting TypeChecker start.apply(typeChecker); CodeGenerator codeGenerator = new CodeGenerator(typeChecker.getSymbolTable()); copySymbolTable( typeChecker, codeGenerator); // To get all the identifiers copied with an index to CodeGen start.apply(codeGenerator); output = createOutput(codeGenerator, fileName); Writer wout = new BufferedWriter( // Write everything to the outputfile.j new OutputStreamWriter(new FileOutputStream(fileName + ".j"), "UTF8")); wout.append(output); wout.close(); }
/** * Check the code with Lexer, Parser and TypeChecker. After this was all correct, start the * Liveness analysis */ private static void parseLiveness(String input) throws ParserException, LexerException, IOException { StringReader reader = new StringReader(input); // Standard routine to start the parser, lexer, ... PushbackReader r = new PushbackReader(reader, 100); Lexer l = new Lexer(r); Parser parser = new Parser(l); Start start = parser.parse(); TypeChecker typeChecker = new TypeChecker(); // Starting TypeChecker start.apply(typeChecker); GraphVisitor analysis = new GraphVisitor(); start.apply(analysis); new Liveness(analysis, typeChecker); // Start Liveness analysis }