/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This file is part of J102. * * See the file "J102-LICENSE" for Copyright information and the * * terms and conditions for copying, distribution and * * modification of J102. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package org.sablecc.java; import java.io.*; import java.util.*; import org.sablecc.java.node.*; import org.sablecc.java.lexer.*; import org.sablecc.java.parser.*; public class CompileDir { public static void main(String[] arguments) { if(arguments.length > 1) { System.out.println("usage:"); System.out.println(" java CompileDir [dirname]"); System.exit(1); } Date start = new Date(); compiledir((arguments.length == 0) ? System.getProperty("user.dir") : arguments[0]); Date end = new Date(); System.out.println("Start: " + start); System.out.println("End : " + end); } private static void compiledir(String dirname) { String[] files = new File(dirname).list(); for(int i = 0; i < files.length; i++) { File file = new File(dirname, files[i]); if(file.isDirectory()) { compiledir(file.getPath()); } else if(file.isFile()) { String filename = file.getPath(); if(filename.endsWith(".java")) { compile(filename); } } } } private static void compile(String filename) { try { // System.out.println(); System.out.println(filename); UnicodePreprocessor preprocessor = new UnicodePreprocessor( new PushbackReader( new BufferedReader( new FileReader(filename)), 1024)); Lexer lexer = new Lexer(new PushbackReader(preprocessor, 1024)); Parser parser = new Parser(lexer); Start ast = parser.parse(); // System.out.println(); // System.out.println(ast); } catch(Exception e) { e.printStackTrace(); System.out.println(e); System.exit(1); } } }