Going back to the original…
require ‘ostruct’
class BProgram
class Context < OpenStruct
def extrn(*)
end
def putchar char
print char.gsub(/\*n/) {"\n"}
end
end
def self.run_in_ruby(&block)
new(&block).run
end
def initialize(&block)
@ctx = Context.new
instance_eval(&block)
end
def run
@ctx.instance_eval(&@main)
end
def main(&block)
@main = block
end
def method_missing(name, arg)
@ctx.send("#{name}=", arg)
end
end
BProgram.run_in_ruby {
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar©; putchar(’!*n’);
}
a ‘hell’;
b ‘o, w’;
c ‘orld’;
}