// Path: src/java/minijava/ast/AST.java
// public abstract class AST {
// 	
// 	public abstract <R> R accept(Visitor<R> v);
// 	
// 	@Override
// 	public String toString() {
// 		StringWriter out = new StringWriter();
// 		this.accept(new PrettyPrintVisitor(new PrintWriter(out)));
// 		return out.toString();
// 	}
// 
// }
// 
// Path: src/java/minijava/ast/Expression.java
// public abstract class Expression extends AST {
// 	
// 	/**
// 	 * The type of an expression is set by the type checking phase.
// 	 */
// 	public Type type;
// 
// 	public Type getType() {
// 		Assert.assertNotNull("Was this AST typechecked?", type);
// 		return type;
// 	}
// 	
// 	public void setType(Type theType) {
// 		//Assert.assertNull(type); 
// 		//As our visitor is written, we expect the types of some nodes to be set multiple times.
// 		//as long as there is no conflict in these type settings, there is no problem, and the assertion has been
// 		//modified to reflect that.
// 		assert(type==null || type.equals(theType));		
// 		type = theType;
// 	}
// 
// }
// 
// Path: src/java/minijava/ast/Program.java
// public class Program extends AST {
// 	
// 	public final MainClass mainClass;
// 	public final NodeList<ClassDecl> classes;
// 
// 	public Program(MainClass mainClass, NodeList<ClassDecl> otherClasses) {
// 		this.mainClass=mainClass;
// 		this.classes=otherClasses; 
// 	}
// 
// 	public Program(MainClass m, List<ClassDecl> cs) {
// 		this(m, new NodeList<ClassDecl>(cs));
// 	}
// 	
// 	public <R> R accept(Visitor<R> v) {
// 		return v.visit(this);
// 	}
// 
// }


import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import minijava.ast.AST;
import minijava.ast.Expression;
import minijava.ast.Program;
import minijava.parser.jcc.JCCMiniJavaParser;
import minijava.parser.jcc.ParseException;
package minijava.parser;



/**
 * Instead of calling methods in the JavaCC (or maybe SableCC) generated
 * parser directly. We use this class as a kind of Stub class to isolate us from
 * direct dependency on the generated parser.
 * <p>
 * In theory this means you should be able to replace the parser
 * with another implementation by editing these methods, and without
 * changing the main implementation for the rest of the compiler.
 * <p>
 * It also has the benefit of not mixing in utility methods with
 * the generated code. We can put different methods for calling the parser
 * (with a file, an inputstream, a String ect. in here).
 * <p>
 * Note: Actually, there is a dependency on the ParseException class generated
 * by JavaCC. To really get "plugability" we should not have this dependency.
 *
 * @author kdvolder
 */
public class MiniJavaParser {

	/**
	 * Read input from a File and parse it into an AST representation.
	 */
	public static Program parse(File file) throws IOException, ParseException {
		FileReader input = new FileReader(file);
		try {
			return parse(input);
		}
// Path: src/java/minijava/ast/AST.java
// public abstract class AST {
// 	
// 	public abstract <R> R accept(Visitor<R> v);
// 	
// 	@Override
// 	public String toString() {
// 		StringWriter out = new StringWriter();
// 		this.accept(new PrettyPrintVisitor(new PrintWriter(out)));
// 		return out.toString();
// 	}
// 
// }
// 
// Path: src/java/minijava/ast/Expression.java
// public abstract class Expression extends AST {
// 	
// 	/**
// 	 * The type of an expression is set by the type checking phase.
// 	 */
// 	public Type type;
// 
// 	public Type getType() {
// 		Assert.assertNotNull("Was this AST typechecked?", type);
// 		return type;
// 	}
// 	
// 	public void setType(Type theType) {
// 		//Assert.assertNull(type); 
// 		//As our visitor is written, we expect the types of some nodes to be set multiple times.
// 		//as long as there is no conflict in these type settings, there is no problem, and the assertion has been
// 		//modified to reflect that.
// 		assert(type==null || type.equals(theType));		
// 		type = theType;
// 	}
// 
// }
// 
// Path: src/java/minijava/ast/Program.java
// public class Program extends AST {
// 	
// 	public final MainClass mainClass;
// 	public final NodeList<ClassDecl> classes;
// 
// 	public Program(MainClass mainClass, NodeList<ClassDecl> otherClasses) {
// 		this.mainClass=mainClass;
// 		this.classes=otherClasses; 
// 	}
// 
// 	public Program(MainClass m, List<ClassDecl> cs) {
// 		this(m, new NodeList<ClassDecl>(cs));
// 	}
// 	
// 	public <R> R accept(Visitor<R> v) {
// 		return v.visit(this);
// 	}
// 
// }


// Path: src/java/minijava/parser/MiniJavaParser.java
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import minijava.ast.AST;
import minijava.ast.Expression;
import minijava.ast.Program;
import minijava.parser.jcc.JCCMiniJavaParser;
import minijava.parser.jcc.ParseException;

package minijava.parser;



/**
 * Instead of calling methods in the JavaCC (or maybe SableCC) generated
 * parser directly. We use this class as a kind of Stub class to isolate us from
 * direct dependency on the generated parser.
 * <p>
 * In theory this means you should be able to replace the parser
 * with another implementation by editing these methods, and without
 * changing the main implementation for the rest of the compiler.
 * <p>
 * It also has the benefit of not mixing in utility methods with
 * the generated code. We can put different methods for calling the parser
 * (with a file, an inputstream, a String ect. in here).
 * <p>
 * Note: Actually, there is a dependency on the ParseException class generated
 * by JavaCC. To really get "plugability" we should not have this dependency.
 *
 * @author kdvolder
 */
public class MiniJavaParser {

	/**
	 * Read input from a File and parse it into an AST representation.
	 */
	public static Program parse(File file) throws IOException, ParseException {
		FileReader input = new FileReader(file);
		try {
			return parse(input);
		}
		finally { //No matter what happens, always close the file!