public Compiler(String filepath, Program program) {

		try {
			this.parser = new CecilParser(new CommonTokenStream(new CecilLexer(new ANTLRFileStream(filepath))));

			this.parser.initialise();
			this.sim40 = parser.getSimulator();

			/* Parsing */
			try {
				this.parser.program();
				this.sim40.setLineNumbers(program);
				this.stdStream = new StandardOutputStream();
				this.errorStream = this.parser.getErrorStream();
			}

			catch(RecognitionException e) {
				this.errorStream.getErrors().add(new OutputError(e.line, e.getLocalizedMessage()));    
			}

			/* If no parser errors exist, then proceed for type checking */
			if(this.errorStream.getErrors().size() == 0) {
				/* type checking for labels */
				for(int i: parser.getDatafield().keySet()){
					if(parser.getLabelfield().keySet().contains(parser.getDatafield().get(i))) 
						this.sim40.memory[i] = this.parser.getLabelfield().get(this.parser.getDatafield().get(i));

					else { 
						this.errorStream.getErrors().add(new OutputError(program.getDataLine(parser.getDatafield().get(i)), "Data " + parser.getDatafield().get(i) + " has no labelfield"));
						this.sim40.setSuccessCompile(false);
					}
				}
			}

			else {
				this.sim40.setSuccessCompile(false);
			}

			/* Writing successful compilation to StandardOutputStream */
			if(this.sim40.isCompileSuccess()) {
				this.stdStream.getOutput().add("Program has successfully compiled"); 
				this.sim40.setSuccessCompile(true);
			}

		} 
		
		catch (IOException e) {
			this.errorStream.getErrors().add(new OutputError(1, "IOException: cannot read user input"));			
		}
	}