Created
July 31, 2013 03:36
-
-
Save joelgallant/6119088 to your computer and use it in GitHub Desktop.
A gordian console runtime that interprets instructions as you type them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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