diff --git a/ClassicInterpreter.rb b/ClassicInterpreter.rb index ef9cdd4..0c20015 100644 --- a/ClassicInterpreter.rb +++ b/ClassicInterpreter.rb @@ -6,6 +6,11 @@ class ClassicInterpreter < Interpreter + def initialize(source, left_in, right_in, debug, max_cycles, ascii_mode) + super(source, left_in, right_in, debug, max_cycles) + @ascii_mode = ascii_mode + end + # Nilads ~~~~~~~~~~~~~~~~~~~~~ def round_nilad() @@ -60,7 +65,11 @@ def close_round() def close_square() data = main_stack.pop() - puts @current_value + if @ascii_mode + print (@current_value % 2 ** 32).chr(Encoding::UTF_8) + else + puts @current_value + end @current_value += data[1] end diff --git a/brain_flak.rb b/brain_flak.rb index d7022b0..8e78086 100644 --- a/brain_flak.rb +++ b/brain_flak.rb @@ -171,7 +171,7 @@ when "brainflak" interpreter = BrainFlakInterpreter.new(source, numbers, [], debug, max_cycles) when "classic" - interpreter = ClassicInterpreter.new(source, numbers, [], debug, max_cycles) + interpreter = ClassicInterpreter.new(source, numbers, [], debug, max_cycles, ascii_out) when "miniflak", "mini" source = source.gsub(/#.*(\n|$)/,"").gsub(/[^\[\]{}()]/,"") # Parsing is done here so that we can strip `[]` properly while source =~ /\[\]/