Skip to content

Instantly share code, notes, and snippets.

@joelgallant
Created July 31, 2013 03:36
Show Gist options
  • Save joelgallant/6119088 to your computer and use it in GitHub Desktop.
Save joelgallant/6119088 to your computer and use it in GitHub Desktop.
A gordian console runtime that interprets instructions as you type them
import edu.gordian.elements.methods.UserMethod;
import edu.gordian.scopes.Scope;
import edu.gordian.values.UserReturningMethod;
import edu.gordian.values.Value;
import java.util.Scanner;
import java.util.StringTokenizer;
public class ConsoleGordian {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
String line;
Scope.RunningEnvironment runtime = new Scope(new UserMethod[]{new UserMethod("print") {
@Override
public void run(Value[] arguments) {
System.out.println(arguments[0].getValue());
}
}}, new UserReturningMethod[0]).new RunningEnvironment();
while (!(line = s.nextLine()).equals("exit")) {
StringTokenizer l = Scope.preRun(line);
while (l.hasMoreElements()) {
runtime.next(l.nextToken());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment