package eu.bryants.anthony.toylanguage.compiler;

import java.io.File;
import java.io.FileNotFoundException;

import parser.BadTokenException;
import parser.ParseException;
import eu.bryants.anthony.toylanguage.ast.CompilationUnit;
import eu.bryants.anthony.toylanguage.parser.ToyLanguageParser;

/*
 * Created on 2 Apr 2012
 */

/**
 * @author Anthony Bryant
 */
public class Compiler
{
  public static void main(String... args) throws FileNotFoundException, ParseException, BadTokenException, NameNotResolvedException, ConceptualException
  {
    if (args.length != 2)
    {
      System.err.println("Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler <input-file> <output-file>");
      System.exit(1);
    }
    File input = new File(args[0]);
    File output = new File(args[1]);
    if (!input.isFile())
    {
      System.err.println("Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler <input-file> <output-file>");
      System.exit(2);
    }
    if (output.exists() && !output.isFile())
    {
      System.err.println("Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler <input-file> <output-file>");
      System.exit(3);
    }

    CompilationUnit compilationUnit = ToyLanguageParser.parse(input);

    Resolver.resolve(compilationUnit);

    new CodeGenerator(compilationUnit).generate(output.getAbsolutePath());
    System.out.println(compilationUnit);
  }
}

@@ -381,16 +381,146 @@
 piler%0A%7B%0A
+  private static final String USAGE = %22Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler %3Cinput-file%3E %3Coutput-file%3E%22;%0A%0A
   public
@@ -729,97 +729,13 @@
 tln(
-%22Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler %3Cinput-file%3E %3Coutput-file%3E%22
+USAGE
 );%0A 
@@ -894,97 +894,13 @@
 tln(
-%22Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler %3Cinput-file%3E %3Coutput-file%3E%22
+USAGE
 );%0A 
@@ -1006,97 +1006,13 @@
 tln(
-%22Usage: java eu.bryants.anthony.toylanguage.compiler.Compiler %3Cinput-file%3E %3Coutput-file%3E%22
+USAGE
 );%0A 

Centralise the Usage help text