Here's the top-level structure of my solution: public static void main(String args[]) { processFile(args[0]); } private static void processFile(String filename) { try { BufferedReader br = open(filename); while ((line = br.readLine()) != null) { if (line.startsWith(INCLUDE)) { ... processFile(incfile); } else if (line.startsWith(DEFINE)) doDefine(line); else doLine(line); } } catch (IOException e) {} } p.s. Remember that a4/lpp-processLine has a line-processing algorithm.