transcendental-lisp/src/main/LispMain.java

35 lines
953 B
Java
Raw Normal View History

package main;
import interpreter.*;
public class LispMain {
private LispMain() {}
public static void main(String[] args) {
LispInterpreter interpreter = buildInterpreter(args);
interpreter.interpret();
}
private static LispInterpreter buildInterpreter(String[] args) {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
builder.setOutput(System.out);
builder.setErrorOutput(System.err);
builder.setTerminationFunction(() -> System.exit(0));
builder.setErrorTerminationFunction(() -> System.exit(1));
configureInput(args, builder);
return builder.build();
}
private static void configureInput(String[] args, LispInterpreterBuilder builder) {
if (args.length > 0)
builder.useFile(args[0]);
else {
builder.setInputName("stdin");
builder.setInput(System.in);
}
}
}