transcendental-lisp/src/main/LispMain.java

51 lines
1.3 KiB
Java
Raw Normal View History

package main;
import java.io.*;
import error.*;
import interpreter.*;
public class LispMain {
private LispMain() {}
public static void main(String[] args) {
LispInterpreter interpreter = null;
ErrorManager errorManager = new ErrorManager(() -> System.exit(1), System.err::print);
if (args.length > 0) {
String fileName = args[0];
try {
interpreter = new LispInterpreter(new FileInputStream(fileName), System.out, errorManager);
} catch (FileNotFoundException e) {
errorManager.generateError(new LispFileNotFoundException(e));
}
} else
interpreter = new InteractiveLispInterpreter(System.in, System.out, errorManager);
interpreter.interpret();
}
public static class LispFileNotFoundException extends LispException {
private static final long serialVersionUID = 1L;
private String message;
public LispFileNotFoundException(FileNotFoundException e) {
this.message = e.getMessage();
}
@Override
public int getSeverity() {
return ErrorManager.CRITICAL_LEVEL;
}
@Override
public String getMessage() {
return message;
}
}
}