#!/usr/bin/perl $cd .= $_ while (<STDIN>); sub get_char { exit if ($ch_ptr == length($cd)); return substr($cd, $ch_ptr++, 1); } while (1) { $ch = get_char; $cell[$cl_ptr]++ if ($ch eq '+'); $cell[$cl_ptr]-- if ($ch eq '-'); (($_ = chr($cell[$cl_ptr])) && print) if ($ch eq '.'); $cl_ptr++ if ($ch eq '>'); $cl_ptr-- if ($ch eq '<'); if ($ch eq ',') { $inp_ch = getc(STDIN); $cell[$cl_ptr] = ord($inp_ch); } elsif ($ch eq '[') { ($ch_ptr = index($cd, ']', $ch_ptr)) if ($cell[$cl_ptr] == 0); } elsif ($ch eq ']') { ($ch_ptr = rindex($cd, '[', $ch_ptr)) if ($cell[$cl_ptr] != 0) +; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BF Interpreter
by jdporter (Paladin) on Mar 08, 2006 at 22:38 UTC | |
by aweeraman (Novice) on Mar 09, 2006 at 22:48 UTC | |
by aweeraman (Novice) on Mar 10, 2006 at 23:38 UTC | |
|
Re: BF Interpreter
by locked_user mtve (Deacon) on Mar 09, 2006 at 09:33 UTC |