$2.split(//).each do |c|
if c == '>' then pointer[1] += 1
elsif c == '<' then pointer[1] -= 1
elsif c == 'v' then pointer[0] += 1
elsif c == '^' then pointer[0] -= 1
elsif c == '!' then pointer = [0,0]; data.clear
elsif c == '+' then data.unshift
@@grid[pointer[0]][pointer[1]]
elsif c == 'o' then output << data.join
end
end
string = $3
end
return output.reverse
end
def english( string )
return parse(string).scan(/.{2}/).collect{ |tuple| tuple.hex.chr
}.join
end
end
hex = Hexagrid.new
while not $stdin.eof?
puts hex.english(gets)
end
I've got D:\NetBeansProjects\InterpreterHexagrid\lib\main.rb:33:in
`parse': undefined method `reverse' for nil:NilClass (NoMethodError)
from D:\NetBeansProjects\InterpreterHexagrid\lib\main.rb:37:in
`english'
from D:\NetBeansProjects\InterpreterHexagrid\lib\main.rb:43
$2.split(//).each do|c|
if c == '>' then pointer[1] += 1
elsif c == '<' then pointer[1] -= 1
elsif c == 'v' then pointer[0] += 1
elsif c == '^' then pointer[0] -= 1
elsif c == '!' then pointer = [0,0]; data.clear
elsif c == '+' then data.unshift
@@grid[pointer[0]][pointer[1]]
elsif c == 'o' then output<< data.join
end
end
string = $3
end
return output.reverse
end
def english( string )
return parse(string).scan(/.{2}/).collect{|tuple| tuple.hex.chr
}.join
end
end
hex = Hexagrid.new
while not $stdin.eof?
puts hex.english(gets)
end
ok, the error disappeared but for input
1d+d*dddd**++d1d+d*d*1d+*111++-++d1d+dd**1-++dd111+++11-+<[o<]!
i should get Hello but the while loop never stop
I used the "hello world" script given on the wiki page, and it worked
fine. Perhaps you have an error in your Hexagrid code. Did you compose
that code yourself, or did you get it from somewhere else?
In particular, and this is just from skimming the Hexagrid wiki page,
you can't do anything unless you define a stack, e.g. "stack{...};".
Also, I don't see any indication in the wiki page or the interpreter's
code that [ or ] have any meaning in the language, but you use them
near the end.
···
On Thu, Mar 10, 2011 at 5:30 PM, Ma Sz <magda.szlagor@gmail.com> wrote:
ok, the error disappeared but for input
1d+d*dddd**++d1d+d*d*1d+*111++-++d1d+dd**1-++dd111+++11-+<[o<]!
i should get Hello but the while loop never stop
Its more like the while loop never runs cause your input doesn't match the
regexp (thats the reason you get your first error).
···
2011/3/11 Ma Sz <magda.szlagor@gmail.com>
ok, the error disappeared but for input
1d+d*dddd**++d1d+d*d*1d+*111++-++d1d+dd**1-++dd111+++11-+<[o<]!
i should get Hello but the while loop never stop