2 added 153 characters in body
source | link

Ruby, 407447 bytes

p,i=$*
r=[0]*1024
l=(i||'').length
r=[0]*l
l.times{|j|r[j]=i[j].ord}
i=j=0
p=ps=p.gsub(/\(.*?\)|\s/,'')
q=s.scan(/(\??)?(\D[#<>=+:-])(\d*)/)
e=->{abort"Error"}
p[/\d\s+\d/]||q*''!=s ?e[]:(c=p[j]r+=[0]until i+1<r.length
c=q[j]
j+=1
c[0]==??&&r[i]==0f=c[1]
c[0]&&r[i]==0?next: a=c[2]==''?%w{> < + '><+-}.index(c[1])'[f]?1:0:c[2].to_i
c=c[1]
c=='=+-'[f]&&a>255?e[]: f==?#?i=a :c==f==?>?i+=a :c==f==?<?i+=ai-=a :c==f==?=?r[i]=a :c==f==?+?r[i]+=a :c==f==?-?r[i]-=a :j=a
i<0?abort("ERR RAMidx<0")e[]:r[i]%=256
r+=[0]*1024 until i<r.length)while j<pj<q.length
puts r.first(r.index 0).map(&:chr)*''

Takes both the program and the input via command line arguments.

EDIT: Fixed a few bugs, and added support for invalid syntax at the cost of 40 bytes (while adding a few other optimisations).

Ruby, 407 bytes

p,i=$*
r=[0]*1024
(i||'').length.times{|j|r[j]=i[j].ord}
i=j=0
p=p.gsub(/\(.*?\)|\s/,'').scan(/(\??)(\D)(\d*)/)
(c=p[j]
j+=1
c[0]==??&&r[i]==0?next: a=c[2]==''?%w{> < + -}.index(c[1])?1:0:c[2].to_i
c=c[1]
c==?#?i=a :c==?>?i+=a :c==?<?i+=a :c==?=?r[i]=a :c==?+?r[i]+=a :c==?-?r[i]-=a :j=a
i<0?abort("ERR RAMidx<0"):r[i]%=256
r+=[0]*1024 until i<r.length)while j<p.length
puts r.first(r.index 0).map(&:chr)*''

Takes both the program and the input via command line arguments.

Ruby, 447 bytes

p,i=$*
l=(i||'').length
r=[0]*l
l.times{|j|r[j]=i[j].ord}
i=j=0
s=p.gsub(/\(.*?\)|\s/,'')
q=s.scan(/(\?)?([#<>=+:-])(\d*)/)
e=->{abort"Error"}
p[/\d\s+\d/]||q*''!=s ?e[]:(r+=[0]until i+1<r.length
c=q[j]
j+=1
f=c[1]
c[0]&&r[i]==0?next: a=c[2]==''? '><+-'[f]?1:0:c[2].to_i
'=+-'[f]&&a>255?e[]: f==?#?i=a :f==?>?i+=a :f==?<?i-=a :f==?=?r[i]=a :f==?+?r[i]+=a :f==?-?r[i]-=a :j=a
i<0?e[]:r[i]%=256)while j<q.length
puts r.first(r.index 0).map(&:chr)*''

Takes both the program and the input via command line arguments.

EDIT: Fixed a few bugs, and added support for invalid syntax at the cost of 40 bytes (while adding a few other optimisations).

1
source | link

Ruby, 407 bytes

p,i=$*
r=[0]*1024
(i||'').length.times{|j|r[j]=i[j].ord}
i=j=0
p=p.gsub(/\(.*?\)|\s/,'').scan(/(\??)(\D)(\d*)/)
(c=p[j]
j+=1
c[0]==??&&r[i]==0?next: a=c[2]==''?%w{> < + -}.index(c[1])?1:0:c[2].to_i
c=c[1]
c==?#?i=a :c==?>?i+=a :c==?<?i+=a :c==?=?r[i]=a :c==?+?r[i]+=a :c==?-?r[i]-=a :j=a
i<0?abort("ERR RAMidx<0"):r[i]%=256
r+=[0]*1024 until i<r.length)while j<p.length
puts r.first(r.index 0).map(&:chr)*''

Takes both the program and the input via command line arguments.