transcendental-lisp/src/main/LispMain.java

59 lines
1.4 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(new TerminateInterpreter(), System.err::print);
if (args.length > 0) {
String fileName = args[0];
try {
interpreter = new LispInterpreter(new FileInputStream(fileName), errorManager, System.out);
} catch (FileNotFoundException e) {
errorManager.generateError(new LispFileNotFoundException(e));
}
} else
interpreter = new InteractiveLispInterpreter(System.in, errorManager, System.out);
interpreter.interpret();
}
private static class TerminateInterpreter implements Runnable {
@Override
public void run() {
System.exit(1);
}
}
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;
}
}
}