2016-12-17 10:19:18 -05:00
|
|
|
package main;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import error.*;
|
|
|
|
import interpreter.*;
|
|
|
|
|
|
|
|
public class LispMain {
|
|
|
|
|
|
|
|
private LispMain() {}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
LispInterpreter interpreter = null;
|
2016-12-19 11:38:14 -05:00
|
|
|
ErrorManager errorManager = new ErrorManager(() -> System.exit(1), System.err::print);
|
2016-12-17 10:19:18 -05:00
|
|
|
|
|
|
|
if (args.length > 0) {
|
|
|
|
String fileName = args[0];
|
|
|
|
|
|
|
|
try {
|
2016-12-19 11:38:14 -05:00
|
|
|
interpreter = new LispInterpreter(new FileInputStream(fileName), System.out, errorManager);
|
2016-12-17 10:19:18 -05:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
errorManager.generateError(new LispFileNotFoundException(e));
|
|
|
|
}
|
|
|
|
} else
|
2016-12-19 11:38:14 -05:00
|
|
|
interpreter = new InteractiveLispInterpreter(System.in, System.out, errorManager);
|
2016-12-17 10:19:18 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|