class REPL { _input _output _compiler _atEof _value } class method runIn: system (self new: system) run class method new: system let compiler = Compiler new. compiler define: "system" as: system. self _input: system input _output: system output _compiler: compiler _atEof: False _value: False method run _output println: "Foolang 0.0.0". { _atEof } whileFalse: { self readEvalPrint } method readEvalPrint { -- Cascade just for fun. self; prompt; read; eval; print } onError: { |error context| _output println: "ERROR: {error}". _output println: context } method prompt _output print: "> ". _output flush. self method read let source = "". { let line = _input readline. _atEof = line is False. _atEof ifFalse: { source = source append: line newline. self _tryParse: source } } whileFalse method eval _atEof ifFalse: { _value = _compiler evaluate } method print _atEof ifFalse: { _output display: _value. _output newline. _output flush } method _tryParse: source _compiler parse: source onEof: { |_err| return False }. True end class Main {} class method run: command in: system REPL runIn: system end