transcendental-lisp/main/LispInterpreter2.java

51 lines
1.6 KiB
Java

package main;
import parser.*;
import eval.*;
import error.ErrorManager;
import java.io.*;
import java.net.*;
import remotefs.RemoteFileInputStream;
public class LispInterpreter2 {
public static final String HOST_NAME = "localhost";
public static final int PORT_NUM = 5150;
public static void main(String[] args) {
LispParser parser = null;
if (args.length > 0) {
try {
InetAddress host = InetAddress.getByName(HOST_NAME);
RemoteFileInputStream remoteIn =
new RemoteFileInputStream(host, PORT_NUM, args[0]);
parser = new LispParser(remoteIn, args[0]);
} catch (UnknownHostException e) {
ErrorManager.generateError(e.getMessage(),
ErrorManager.CRITICAL_LEVEL);
} catch (FileNotFoundException e) {
ErrorManager.generateError(e.getMessage(),
ErrorManager.CRITICAL_LEVEL);
}
} else {
parser = new LispParser(System.in, "System.in");
}
while (! parser.eof()) {
try {
SExpression sexpr = parser.getSExpr();
System.out.println(EVAL.eval(sexpr));
} catch (RuntimeException e) {
ErrorManager.generateError(e.getMessage(), 2);
} catch (IOException e) {
ErrorManager.generateError(e.getMessage(),
ErrorManager.CRITICAL_LEVEL);
}
}
}
}