Public feed
#532195
#!/usr/bin/ruby## Betterave -- Programmation fonctionnelle obscure#class Source attr_reader :index, :stuff def initialize(stuff) @stuff = stuff @index = -1 @vars = Hash.new(0) @strings = [] @tacks = [] end def oops(mess) print mess exit 1 end def parse() @index += 1 if @index >= @stuff.length then exit end case @stuff[@index,1] # Commentaires when "~" temp = @stuff.index("~",@index + 1) if temp == nil then oops "Unmatched comment!\n" end @index = temp # Operations mathematiques de base when /\d/ return @stuff[@index,1].to_i when "+" return parse() + parse() when "-" return parse() - parse() when "*" return parse() * parse() when "/" return parse() / parse() when "%" return parse() % parse() when "=" return parse() == parse() ? 1 : 0 when "<" return parse() < parse() ? 1 : 0 when ">" return parse() > parse() ? 1 : 0 # Manipulation de strings (leopard) when "\"" temp = @stuff.index("\"", @index + 1) if temp == nil then oops "Unmatched string!\n" end @strings << @stuff[ (@index + 1) ... temp ] @index = temp return @strings.length # Structure when "[" @tacks << @index when "|" temp = parse() if temp != 0 then if @tacks.length == 0 then @index = -1 else @index = @tacks.last end else endtack = @stuff.index("]", @index) if endtack == nil then oops "Unmatched tack!\n" end @tacks.pop @index = endtack end # Input when ":" return gets.to_i when ";" temp = @strings.length @strings << gets return temp # Output when "." temp = parse() print temp return temp when "," temp = parse() if temp < 0 or temp > 255 then return 0 end print temp.chr return temp when "$" temp = @strings[parse()] unless temp == nil then print temp end # Manipulation de variables when /[A-Z]/ @vars[@stuff[@index,1]] = parse() when /[a-z]/ return @vars[@stuff[@index,1].upcase] else return parse() end endendsource = Source.new(readlines.join)while source.index < (source.stuff.length - 1) source.parse()end