Skip to content

Commit

Permalink
Merge pull request #86 from DJMcMayhem/master
Browse files Browse the repository at this point in the history
Merge for Release 1.5.2
  • Loading branch information
Wheatwizard committed Dec 18, 2017
2 parents 4fbee94 + 37acc72 commit 577fd14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ClassicInterpreter.rb
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions Interpreter.rb
Expand Up @@ -26,12 +26,16 @@ class Interpreter
def initialize(source, left_in, right_in, debug, max_cycles)
# Strip comments
source = source.gsub(/(^[^#]*)#.*(\n|$)/, '\1')
# Strips the source of any characters that aren't brackets or part of debug flags
@source = source.gsub(/(?<=^|[()\[\]<>{}]|\s)[^@()\[\]<>{}\s]*/, "")
# Strips extra whitespace
@source = @source.gsub(/\s/,"")
# Strips extra @s
@source = @source.gsub(/@+(?=[()\[\]<>{}]|$)/, "")
# Strips the source of any characters that aren't brackets (or part of debug flags in debug mode)
if debug then
@source = source.gsub(/(?<=^|[()\[\]<>{}]|\s)[^@()\[\]<>{}\s]*/, "")
# Strips extra whitespace
@source = @source.gsub(/\s/,"")
# Strips extra @s
@source = @source.gsub(/@+(?=[()\[\]<>{}]|$)/, "")
else
@source = source.gsub(/[^()\[\]<>{}]*/, "")
end
@left = Stack.new('Left')
@right = Stack.new('Right')
@main_stack = []
Expand Down
4 changes: 2 additions & 2 deletions brain_flak.rb
Expand Up @@ -171,9 +171,9 @@
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
source = source.gsub(/#.*(\n|$)/,"").gsub(/[^\[\]{}()]/,"") # Parsing is done here so that we can strip `[]` properly
while source =~ /\[\]/
source = source.gsub("[]","")
end
Expand Down

0 comments on commit 577fd14

Please sign in to comment.