Deadfish

Deadfish is a very odd interpreted programming language created by Jonathan Todd Skinner. It was released under public domain and was originally programmed in C, but now it has been since ported to many other programming languages (see below).

Deadfish has a way to output things but it has no way to input them! It has only a few commands, only four in total. It is also case-sensitive, and can deal only with integer values when adding or subtracting, however once squared this number increases greatly!

You can have several commands per line, at least in the C implementation.

Errors are not acknowledged: the shell simply adds a newline character!

Anything that is not a command is not accepted by the interpreter. As you've probably assumed deadfish was created in less than a hour, and can be very useful in creating highly interactive programs.

Commands
Sometimes, the additional command 'h', meaning halt, is used. Although the comment in the C implementation states, the implementation sets the value to zero if and only if.

Why "deadfish"?
Deadfish started out as a subset of HQ9+, as all it would do would be to print out hello world and give an iou depending on how many times the command 9 was entered for how many 99 bottles of beer programs it owed the programmer. Deadfish was originally going to be called fishheads as programming in this language is like eating raw fish heads. However, due to the limiting features of the language, programming in this language became like eating (and having to smell) dead, rotting fish heads, an experience not often generally considered pleasurable.

Example program
Note: the standard shell adds >> characters for readability.

>> i >> >> o 1 >> d

This program prints the ASCII values (as numbers, not characters, since Deadfish does not have character output) of the characters in the string "Hello world".

iisiiiisiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiooiiio dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddo dddddddddddddddddddddsddoddddddddoiiioddddddoddddddddo

Since the proper behavior of Deadfish arithmetic can be *cough* surprising, here are a few important test cases for people making interpreters: The program iissso should print 0; the program diissisdo should print 288; and the program iissisdddddddddddddddddddddddddddddddddo should print 0.

Implementations
Some of these implementations may not be considered fully compliant, sometimes because an implementor has implemented the intuitive meaning of the commands rather than the subtle deadfish way. For some of the implementations it may be hard for people other than the implementor to tell whether they are compliant or not.

A:;
Interprets one instruction per line v:-1.0;w:256.0;u:\n;t:1;r:0;j:i;l:d;b:s;o:o;c:>>;p:c;?:r:=:v:1;r:0;?:r:=:w:1;r:0;i:q;?:q:=:o:3;p:r;p:u;g:10;?:q:=:j:2;a:r:t;g:10;?:q:=:l:2;s:r:t;g:10;?:q:=:b:2;m:r:r;g:10;p:u;g:10

APL
∇Deadfish;x x ← 0 line: ⍞ ← '>> '  { x ∘← (~x∊¯1 256) × x     ⍵∊'ix': x ∘← x + 1 ⍵∊'d': x ∘← x - 1 ⍵∊'sk': x ∘← x * 2 ⍵∊'oc': ⎕ ← x  }¨⍞ → line ∇

APLBAONWSJAS
EXECUTE(Deadfish)

Attache
?? state-ful deadfish interpreter acc := 0 line := ""

deadfish[code] := ForEach[code, If[_ = "i", acc := acc + 1];; If[_ = "d", acc := acc - 1];; If[_ = "s", acc := acc ^ 2];; If[_ = "o", Print[acc]];;

If[acc = -1 or acc = 256, acc := 0] ]

DoWhile[line /= nil, deadfish[line];; line := Prompt[">> "] ]

Or, with the  library:

Needs[$langs] acc := 0 line := ""

DoWhile[line /= nil, acc := deadfish[line, acc];; line := Prompt[">> "] ]

AWK
It won't display the prompt, but other than that is complete. sub(/o/,x=x*(x>0&&x-256)*x^/s/+/i/-/d/)

Bash

 * 1) !/bin/bash

no=0

while true; do	((no==256||no<0)) && no=0 echo -n '>> ' # prompt if read; then case $REPLY in			d) ((no--)) ;;			i) ((no++)) ;; o) echo $no ;;			s) no=$((no*no)) ;; *) : ;;		esac	else		echo # on EOF	fi done

Batch
@echo off
 * start

set/pcmd=^>^> if %cmd%==i set /a acc=%acc%+1 if %cmd%==d set /a acc=%acc%-1 if %cmd%==s set /a acc=%acc%*%acc% if %cmd%==o echo %acc% if %acc%==256 set %acc%=0 if %acc%==-1 set %acc%=0 goto start

Here is another variant with an additional debug command "?" and the halt command "h". @echo off set debug=0
 * start

set cmd=0 set/pcmd=^>^> if %cmd%==i set/aacc=%acc%+1&if %debug%==1 echo %acc%+1 if %cmd%==d set/aacc=%acc%-1&if %debug%==1 echo %acc%-1 if %cmd%==s set/aacc=%acc%*%acc%&if %debug%==1 echo %acc%*%acc% if %cmd%==o echo %acc% if %cmd%==h set acc=0&set debug=0&goto :eof if %cmd%==? (if %debug%==0 (set debug=1) else (set debug=0)) if %acc%==256 set acc=0 if %acc%==-1 set acc=0 goto start

Befunge-93
v Deadfish in Befunge 0 >0" >>">:vv           < ,#       _$:vv-*5+7*44 +    v    <  _:*v
 * $ v^,_v^.<   >

5> ~   >#$>:375**-v ^    < $ #v-*:*25:_$1+ ^#-*65-*99:_$1-      #v ^ _$0~^ >:1+v -^>   #1-#_1+:48:**

Boo
/* Deadfish in Boo */ // Hallowe'en 2012 a = 0 while true: if a < 0 or a == 256: a = 0 c = prompt(">> ") if c == 's': a *= a    elif c == 'i': a += 1 elif c == 'd': a -= 1 elif c == 'o': print(a)
 * 1) by Chris Pressey

Brainfuck
Implementation by David Catt (User:David.werecat), reads one line of input at a time (for compatibility with most brainfuck interpreters) and interprets only one instruction per line >+[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..--- ---.[-]>>[-]+>,--[- -[-[--[ [<->[-]]<[>>>[-]>[-]>[-]>[-]<<<<[>+>+>+<<<-]>[>[<<+>>-]>[>+<-]>[<+<+>>- ]<<<-]<<<-]>]<[>>>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<[->+>>>>>+<[-]+<<<<- -[>>>>[<++++++++++<<->>>-]<+<<<-]>>>[<<<+>>>-]<<+>>>[-]+<<<--[>>>[< ++++++++++<->>-]<+<<-]>>[<<+>>-]<+<<<]>>>>[-]>[-]<<[>+<<<<[-]++++++++++++++ ++++++++++++++++++++++++++++++++++>>>[<<<+>>>-]<<<.>>>]>[<<<<[-]+++++++++++ +++++++++++++++++++++++++++++++++++++>>[<<+>>-]<<.>>>>-]<<[<<[-]+++++++++++ +++++++++++++++++++++++++++++++++++++>>[<<+>>-]<<.>>]<<[-]+++++++++++++++++ +++++++++++++++++++++++++++++++>[<+>-]<.[-]++++++++++.-->>>>>>[<<<< <<+>>>>>>-]<<<<<<<<-]>]<[>>+<<-]>]<[>>>[-]+>[-]<<[>[-]>+<<-]>>-[<<+>>-]<<>[ <+>-]<<<-]>]<[>-<-]>+[,--]<<]

Burlesque
{?i ?d S[ J}j{{'i 'd 's 'o}jFi}m[si)bx{J{-1==}{256==}m|{256.%}if}IC0je!

C
/* <-- Deadfish Interpreted Computer Language --> */ /* <-- Programmed by Jonathan Todd Skinner   --> */

/* <-- Include Header File --> */ /* Updated the Code to Remove Uneeded Header Includes - JTS */
 * 1) include 

/* <-- Declare some variables --> */ unsigned int x; /* make a positive integer and call it x */ char usrinput; /* string to hold user input */

/* <-- Declare a function --> */ void entercommand(void);

/* <-- Start Main Function --> */ int main(void) {	/* At beginning of x is always 0 */ x = 0; entercommand; }

/* <-- Enter Command --> */ void entercommand(void) {	/* Accept User Input */ printf(">> "); /* output shell symbol */ scanf("%c",&usrinput); /* scan for user input that is char */ /* Check for commands and do action */ /* Make sure x is not greater then 256 */ if(x == 256) x = 0; if(x == -1) x = 0; if(usrinput == 'i') {		x++; entercommand; }			else if(usrinput == 'd') {		x--; entercommand; }	else if(usrinput == 'o') {		printf("%d\n",x); entercommand; }	else if(usrinput == 's') {		x=x*x; entercommand; }	else {		printf("\n"); entercommand; }

}

Here's a slightly cleaned up version:

/* <-- Deadfish Interpreted Computer Language --> */ /* <-- Original programmed by Jonathan Todd Skinner   --> */ /* <-- Dumb stuff removed by some other guy --> */


 * 1) include 

int main(void) {   unsigned int x = 0;

while(1) { char input;

printf(">> "); scanf("%c",&input);

if(x == 256 || x == -1) x = 0; switch(input) { case 'i': ++x; break; case 'd': --x; break; case 'o': printf("%d\n",x); break; case 's': x*=x; break; default: printf("\n"); break; }   } }

C#
public class Deadfish { private static int x = 0; private static Dictionary Commands = new Dictionary { { 'i', => ++x }, { 'd', => --x }, { 's', => x *= x }, { 'o', => Console.WriteLine(x) } }; static void Main(string[] args) { Action prompt = => { Console.Write(">> "); Console.Out.Flush; };   prompt; int cmd; while ((cmd = Console.Read) != -1) { char command = Convert.ToChar(cmd); if (!Environment.NewLine.Contains(command)) { x = x == 256 || x < 0 ? 0 : x;       (Commands.ContainsKey(command) ? Commands[command] :  => Console.WriteLine); prompt; }   }  } }

another C# implementation

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO;

namespace Deadfish_Interpreter {   class Program {       static void Main(string[] args) {           StreamReader sr = new StreamReader(args[0]); string code = sr.ReadToEnd; code = code.Replace(((char)13).ToString, "");

int cell = 0;

foreach (char c in code) {               if (c == 'i') {                   cell++; }               else if (c == 'd') {                   cell--; }               else if (c == 's') {                   int i = cell * cell; cell = i;               } else if (c == 'o') {                   Console.Write(cell); }

if (cell == -1 || cell == 256) {                   cell = 0; }           }

Console.ReadLine; }   } }

C++ templates

 * 1) include

// //
 * 1) define PROGRAM i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,o,s,i,o,i,i,i,i,i,i,i,s,s,s,o

template  struct Cons { static void print { Ns::print; std::cout << n; } };

struct Nil { static void print {} };

template  struct Append;

template  struct Append { typedef Ns String; };

template  struct Append, Ns> { typedef Append Next; typedef Cons String; };

struct name { \ template  struct Result { \ static const int value = expr; \ typedef Out Output; \ }; \ }
 * 1) define INS(name, expr) \

INS(i, n + 1); INS(d, n - 1); INS(s, n * n);

template struct DecimalLoop;

template <> struct DecimalLoop<0> { typedef Nil String; };

template struct DecimalLoop { typedef DecimalLoop Next; typedef Cons<'0' + (n % 10), typename Next::String> String; };

template struct ToDecimal;

template <> struct ToDecimal<0> { typedef Cons<'\n', Cons<'0', Nil>> String; };

template struct ToDecimal { typedef Cons<'\n', typename DecimalLoop::String> String; };

struct o { template  struct Result { static const int value = n;   typedef typename Append<typename ToDecimal<n>::String, Out>::String Output; }; };

template struct Wrap { static const int value = n < 0 || n == 256 ? 0 : n; };

template <typename... Is> struct Seq;

template <typename I, typename... Is> struct Seq<I, Is...> { template <int n, typename Out> struct Result { typedef typename I::template Result<n, Out> A;   typedef typename Seq<Is...>::template Result<Wrap<A::value>::value, typename A::Output> B;    typedef typename B::Output Output; }; };

template <> struct Seq<> { template <int n, typename Out> struct Result { typedef Out Output; }; };

int main { Seq<PROGRAM>::Result<0, Nil>::Output::print; }

Chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken

Clever
import std.io.* as io; Int a = 0; String c; while (true) { if (a < 0 || a == 256) { a = 0; }    io::print(">> "); c = io::readln; if (c == "s") { a *= a;    } else if (c == "i") { a += 1; } else if (c == "d") { a -= 1; } else if (c == "o") { io::print(a); io::print("\n"); } }

COBOL
identification division. program-id. deadfish. data division. working-storage section. 77 n                   usage binary-int unsigned. 77 deadfish            pic x.       procedure division. perform forever call "printf" using z">> " end-call call "scanf" using z"%c" deadfish end-call if (n equal -1) or (n equal 256) then move 0 to n end-if evaluate deadfish when equal "d" subtract 1 from n giving n end-subtract when equal "i" add 1 to n giving n end-add when equal "o" call "printf" using x"25641000" by value n end-call when equal "s" multiply n by n end-multiply when equal "h" exit perform when other call "printf" using x"1000" end-call end-evaluate end-perform goback. end program deadfish.

Commodore 64 BASIC
Type "H" to quit. (Fixed to comply with the Deadfish 0-255 rule (again (again))). This program will also work in several other 8-bit BASICs, such as Applesoft BASIC. 10 INPUT A$ 20 IF A$="I" THEN B = B+1 21 IF A$="D" THEN B = B-1 22 IF A$="S" THEN B = B*B 23 IF A$="O" THEN PRINT B 24 IF A$="H" THEN END 31 IF B = 256 THEN B = 0 32 IF B = -1 THEN B = 0 33 GOTO 10

Common Lisp
Ensures full compliance, but throws an error when an invalid command is given. (defparameter *acc* 0) (defvar deadfish-dictionary '((#\i '1+)(#\d '1-)(#\s 'square)(#\o 'print))) (defun square (x) (* x x)) (defun deadfish-limit (x) (if (or (< x 0) (eql x 256)) 0 x)) (defmacro deadfish (input) (setf *acc* 0)  `(progn ,@(mapcar (lambda (ch) `(setf *acc* (deadfish-limit (funcall ,(cadr (assoc ch deadfish-dictionary)) *acc*))))		            (coerce input 'list)) nil))
 * The deadfish macro expects a string as its argument.

dc
[p]1:z[d*]2:z[1+]3:z[1-]4:z[0sB]dsAx[lB0>AlB256=A0d?lBz;zxsBclCx]dsCx
 * 1) Implements XKCD variation of Deadfish.

To use, enter each command in lower case on a line by itself.

This program uses the fact that in dc, each of "x", "k", "c", and "d" each do a different thing to a stack that has been pre-seeded with "0 0". The stack depth is then used to index an array of macros.

The "idso" version can't be done for that reason. "i" and "o" both consume a single positive integer off the top of the stack and error otherwise.

Deadfish
A brief study of the Deadfish language should convince you that it is not possible to implement a Deadfish interpreter in it.

However, on August 4 2012, Chris Pressey took it upon himself to visit the Deadfish Cafe in Winnipeg, Manitoba and, while having coffee there, to implement Deadfish in Turing -- making that implementation as close as anyone's gotten so far to "implementing Deadfish in Deadfish".

DL
Interprets a command per line.

DL Start Var Integer @x Var String @cmd Var Bool @bool Var Integer @pos ParStr(@cmd) StrPos(@cmd,i,@pos) Cmp(@pos,0,@bool) IfNot(@bool) Add(@x,1,@x) ### StrPos(@cmd,d,@pos) Cmp(@pos,0,@bool) IfNot(@bool) Sub(@x,1,@x) ### StrPos(@cmd,s,@pos) Cmp(@pos,0,@bool) IfNot(@bool) Mul(@x,@x,@x) ### StrPos(@cmd,o,@pos) Cmp(@pos,0,@bool) IfNot(@bool) say @x NL ### Cmp(@x,-1,@bool) If(@bool) @x = 0 ### Cmp(@x,256,@bool) If(@bool) @x = 0 ### Goto(6) DL End

Drift
filo cell.0 fifo uin loop { if ?uin = 0 { print char '\n print char '> uin.sin }  if ^cell = 256 | ^cell = (0-1) { ~cell cell.0 }  filo curr.(~uin) if ^curr = 'i { cell.(~cell+1) }else if ^curr = 'd { cell.(~cell-1) }else if ^curr = 's { cell.(^cell*~cell) }else if ^curr = 'o { print int ^cell } else { break }  del curr }

eWagon2
Neat: Enter your program as one line " >>"^^^!!!? "h" '0' {~ "i"^%=^ [`^'1'^+] "d"^%=^ [`^'1'^-] "s"^%=^ [`%^*] "o"^%=^ [`%$] "h"^%=^ [.] ` '256'^%=^ [,'0'] '-1'^%=^ [,'0'] ~, '1'^ }

Compact: " >>"^^^!!!?"h"'0'{~"i"^%=^[`^'1'^+]"d"^%=^[`^'1'^-]"s"^%=^[`%^*]"o"^%=^[`%$]"h"^%=^[.]`'256'^%=^[,'0']'-1'^%=^[,'0']~,'1'^}

Falcon
no=0 loop if no==-1 or no==256 no=0 end >> ">> " the_cmd = input switch the_cmd case "d" no=no-1 case "i" no=no+1 case "o" > no   case "s" no=no*no end end

FALSE
[0~][" >> "^ \$\$256=\1_=&[%0]?\ $'i=[\1+\]? $'d=[\1-\]? $'s=[\$*\]? 'o=[$,]? ]#

Felix
include "std/textio"; open Text_file; var a : int; while {true} {  write(stdout, ">> "); a = if a == 256 or a < 0 then 0 else a;  match readln stdin with | "i\n" => { ++a; } | "d\n" => { --a; } | "s\n" => { a*=a; } | "o\n" => { print a; endl; } endmatch; };

&gt;&lt;&gt;
This is the actual  version, with the correct   behaviour.

v                      Load zero in the register \0& v                  < \" >>"ooo v    <                 The input loop, stopping on 13 (CR, enter press) \i:o \:d=?!^~aor We process in reverse order, that's why the 'r' v                 < \&::&01-=$f1+:*=+?v v            &0~&<     The x==0||x==256 -> x=0 thing \l0=?v >ao           ^   If done with input, output newline and return to input loop \:"i"=?v >~&1+&     ^    Increment \:"d"=?v >~&1-&     ^    Decrement \:"s"=?v >~&:*&     ^    Square \:"o"=?v >~&:n&     ^    Output \:"h"=?v >~;       (^)   HALT >~                ^    If none of those, just remove it from input and run next

Forobj
">> "d'>i[,n>c[$i'1+>i][[$i'1->i][[$i,*>i][[$i d"\n"d][">> "d]$c"o"=?]$c"s"=?]$c"d"=?]$c"i"=?['>i][]$i'256=$i'=|?\],._

Forth
\ Type 'h' to halt : MAIN 0 BEGIN DUP 256 = OVER -1 = OR IF DROP 0 THEN KEY CASE 'i' OF 1+ ENDOF 'd' OF 1- ENDOF 's' OF DUP * ENDOF 'o' OF DUP. ENDOF 'h' OF DROP EXIT ENDOF ENDCASE AGAIN ; MAIN BYE

FORTRAN 77
c Deadfish interpreter in FORTRAN 77 PROGRAM DEADFISH CHARACTER*1 inp INTEGER state state = 0 DO         WRITE(*,'(2A)', ADVANCE='no')">>" READ(*,*)inp IF (state .EQ. 256 .OR. state .LT. 0) +      state = 0 IF (inp .EQ. 'i') THEN state = state + 1 ELSE IF (inp .EQ. 'd') THEN state = state - 1 ELSE IF (inp .eq. 's') THEN state = state**2 ELSE IF (inp .EQ. 'o') THEN WRITE(*,"(I3)")state END IF     END DO      END

Fueue
This hits some bugs in all the known Fueue interpreters. Join it into a single line to run it in the C one. [0]):[   )$$17--1[)$5~[)~[0]])$)[~+1])])]<<<[[        )~<[)$%+-~)100[)[            )~+[~:)(]-1)        ]!]~][        )~<[)$%+-~)105[)[            )~+[~:)(]%0)        ]!]~][        )~<[)$%+-~)111[)[            ):[)$7--1[                )$3~[)$~!%~)]$2<[):]~:            ]~)[                )[~)~$7:([$3~)+[<~+48]-)~10*)]/]--10):                        ~[10 ~:)~]~:         ]!]~][        )~<[)$%+-~)115[)[            )~*:[~:)(])        ]!]~][)[            10 ~:)~        ]!]:]:]:]:    ]]]    62 62 32 )~<~[        )$%+%~)0[[0]!]~    ]~:[)~([        )$%+-~)256[[0]!]~    ]:]~ ]

Glass
{M[moO!iI!aA!sS!n<0>=c<1>=/cc<1>ie.?as.?=ec*=/e">> "oo.?fil.?=gf i.?=kj*"i"se.?=/knn*<1>aa.?=k<0>=\kj*"d"se.?=/knn*<1>as.?=k<0>=\ kj*"s"se.?=/knn*n*am.?=k<0>=\kj*"o"se.?=/kn*o(on).?<10>s(ns).?oo .?k<0>=\hh*<1>as.?=\e<0>=\\<10>s(ns).?oo.?]}
 * sl.?=hg*=l<-1>n*ae.? n*ae.?aa.?=/ln<0>=l<0>=\/hjf*g*h*as.?s

Go
package main

import (	"os"	"fmt"	"bufio" )

func main { reader := bufio.NewReader(os.Stdin)

var x int for { if x < 0 || x == 256 { x = 0 }		fmt.Print(">> ") input, _ := reader.ReadString('\n') c := input[0] switch c { case 's': x = x * x		case 'i': x++ case 'd': x-- case 'o': fmt.Println(x) }	} }

Haskell
import Data.Int (Int32) main = loop (0, "") loop :: (Int32, String) -> IO loop (x', s) = do   putStr $ s ++ ">> " c <- getChar let x = case x' of -1 -> 0; 256 -> 0; _ -> x'   loop $ case c of        'i' -> (x+1, "") 'd' -> (x-1, "") 'o' -> (x, show x ++ "\n") 's' -> (x*x, "") _  -> (x, "\n")

HTML / Javascript
This interpreter is online here. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><TITLE>Deadfish in HTML</TITLE> <SCRIPT type="text/javascript"> var i=0; function deadfish { var c=document.getElementById("cmd").value; document.getElementById("cmd").value=""; document.getElementById('op').innerHTML+= "&amp;gt;&amp;gt;&amp;nbsp;&amp;#"+c.charCodeAt(0)+";<BR/>"; if(c=='i') i++; else if(c=='d') i--; else if(c=='s') i*=i; else if(c=='o') document.getElementById('op').innerHTML+=i+"<BR/>"; else document.getElementById('op').innerHTML+="<BR/>"; if(i==256||i==-1) i=0; return false; } </SCRIPT> </HEAD><BODY> <H1>Deadfish in HTML</H1> &lt;DIV id="op">&lt;/DIV> <FORM onsubmit="return deadfish"> &amp;gt;&amp;gt;&amp;nbsp;<INPUT type="text" maxlength="1" size="1" id="cmd" /><BR/> <INPUT type="submit" value="Submit" /> </FORM> </BODY></HTML>

Another one: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> Deadfish in HTML

<a href="http://esolangs.org/wiki/Deadfish"<a>Deadfish in HTML</a> &gt;&gt; <input id="cmd" type="text" onkeypress="if(event.charCode==13) deadfish;"/>

<script type="text/javascript"> var acc = 0; function deadfish{ var cmd=document.getElementById('cmd').value;

if(cmd=='i') acc++; if(cmd=='d') acc--; if(cmd=='s') acc *= acc; if(acc==256 || acc<0) acc=0; if(cmd=='o') cmd+=' '+acc; document.getElementById('out').innerHTML+=cmd+' >> '; document.getElementById('cmd').value=''; }

Io
This implementation uses Io REPL itself (so you have the powers of Io at your disposal). Should be either entered into REPL directly or with -i option. CLI setPrompt(">> ") CLI writeCommandResult = false

x := 0 check := method(if(x == -1 or x == 256, x = 0)) i := method(check x = x + 1) d := method(check x = x - 1) s := method(check x = x * x) o := method(x println)

itflabtijtslwi
Another implementation using a unary representation. On the machine I tested it with, it did not manage to print numbers much larger than 1000 in the time I had patience to wait.

/ / // //    /*//    /./<\\\\>\\\\\\/    /P1/ >>        GGC.0GG ./N.a****************N.b./N.aN.b./ ./C.a.\.\iC.b./ .\./N.a.\./.\.\.\./N.\0.\.\.\./.\./ .\./N.b.\./.\.\.\./.\./ ./       ./C.a.\.\dC.b./ .\./N.a.\./.\.\.\./N.\0.\.\.\./.\./ .\./N.b.\./.\.\.\./.\./ .\./N.b.\./.\.\.\./.\./ ./       ./C.a.\.\oC.b./ .\./N.a.\./.\.\.\./N.\1.\.\.\./.\./ .\./N.b.\./.\.\.\./ .\.\.\./N.\d.\.\.\./N.\d1N.\d.\.\.\./ .\.\.\./1N.\d.\.\.\./N.\d1.\.\.\./ .\.\.\./N.\d1.\1.\1.\1.\1.\1.\1.\1.\1.\1.\.\.\./ 1.\.\.\.\N.\d .\.\.\./               .\.\.\./N.\cN.\d.\.\.\./N.\c.\.\.\./ .\.\.\./N.\c.\.\.\./N.\d.\.\.\./ .\.\.\./N.\e.\.\.\./N.\d.\.\.\./ .\.\.\./1.\1.\.\.\./2.\.\.\./.\.\.\./2.\1.\.\.\./3.\.\.\./               .\.\.\./2.\2.\.\.\./4.\.\.\./.\.\.\./2.\3.\.\.\./5.\.\.\./                .\.\.\./4.\2.\.\.\./6.\.\.\./.\.\.\./4.\3.\.\.\./7.\.\.\./                .\.\.\./4.\4.\.\.\./8.\.\.\./.\.\.\./4.\5.\.\.\./9.\.\.\./                .\.\.\./N.\dN.\d.\.\.\./0N.\d.\.\.\./ .\.\.\./N.\d.\.\.\./.\.\.\./ N.\cN.\dN.\1N.\e

.\.\.\./N.\0.\.\.\./N.\1.\.\.\./ .\./       ./        ./C.a.\.\sC.b./ .\./N.a.\./.\.\.\./N.\1.\.\.\./.\./ .\./N.b.\./.\.\.\./ .\.\.\./N.\c.\.\.\./N.\1N.\c.\.\.\./ .\.\.\./N.\c.\.\.\./.\.\.\./ .\.\.\./N.\0.\.\.\./N.\cN.\1.\.\.\./ .\./       ./        ./C.a./.\./W.b.\././ ./C.b./.\./ .\./N.a.\./.\.\.\./N.\0.\.\.\./.\./ .\./N.b.\./.\.\.\./.\./

./       C.a.\C.0C.b        ./<.\>./<.\.\.\.\>.\.\.\.\.\.\./ ./P.1./P.2./ ./P.0./P.1./ ./<.\>././       ./P.\2./P.1./ N.aN.0N.b       P.0 /   /P0/P1/ /<\>//   /P2/P1/ /N0// P0

J
This is a serious language that gets used in the finance industry, believe it or not.

getchar =: 'libc.so.6 getchar >c'&cd bounds =: (]*>&0*~:&256)@] prompt =: ][1!:2&4&'>> '@1: cmds   =: 'idso', LF, 255{a. cmdfns =: (>:@])`(<:@])`(*:@])`(][echo@])`prompt`(exit@0:) loop   =: getchar&''@1:$:bounds@(cmdfns`]@.(cmds&i.@[)) LF loop 0

Java
// Deadfish in Java -- JTS // Compiled with JDK 6 and tested with JRE 6 on Ubuntu 9.0.4 // And yes, I do hate Java like most people and I hate how I have to do it for comp sci! import java.util.Scanner; public class Deadfish {	public static void main(String args[]) {		Scanner comm = new Scanner(System.in); boolean isSquared = false; int x = 0; String usrinput; while(true) {			System.out.print(">> "); usrinput = comm.next; if(usrinput.contentEquals("i")) {				if(x >= 256 && isSquared == false) x = 0; x++; }			else if(usrinput.contentEquals("d")) {				if(x <= -1 && isSquared == false) x = 0; x--; }			else if(usrinput.contentEquals("o")) System.out.println(x); else if(usrinput.contentEquals("s")) {				if(x >= 256) isSquared = true; x = x * x;			} else System.out.println; }	} } //FIN

An other one, compiling on JDK1.1 import java.io.*; public class Deadfish { public static void main(String[] args) throws IOException { new Deadfish; }

public Deadfish throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int acc = 0; for(char ch=0; ch!='h'; ch = in.readLine.charAt(0)){ if(ch=='i') acc++; if(ch=='d') acc--; if(ch=='s') acc*=acc; if(acc==256 | acc<0) acc=0; if(ch=='o') System.out.println(acc); System.out.print(">> "); }   } }

Julia
Using multiple dispatch to implement several versions for user convenience.


 * 1) Deadfish implementation in Julia


 * 1) Run fully compliant version (infinite input/output loop):
 * 2)                   deadfish or deadfish(0)


 * 1) Run version that exits when entering 'h':
 * 2)                   deadfish(1)


 * 1) Run version that simulates manual input and
 * 2) appropriate output, given the input string as a whole:
 * 3)                   deadfish("input string")

function deadfish no parameters are given =# deadfish(0) end
 * 1) = Run fully compliant version of deadfish if

function deadfish(compliance::Int) x=0 while true print(">> ")

input=readline(STDIN)[1]

# Make sure x is not greater then 256 ;)       x == 256 ? x=0 : nothing        x == -1 ? x=0 : nothing        input == 'i' ? x=x+1 :        input == 'd' ? x=x-1 :        input == 'o' ? println(x) :        input == 's' ? x=x^2 :        input == 'h' && compliance ==1 ? break : println    end end

function deadfish(code::AbstractString) x=0 for i = 1:length(code) input=code[i] println(">> $input")

# Make sure x is not greater then 256 ;)       x == 256 ? x=0 : nothing        x == -1 ? x=0 : nothing        input == 'i' ? x=x+1 :        input == 'd' ? x=x-1 :        input == 'o' ? println(x) :        input == 's' ? x=x^2 : println    end end

Example output of test strings for "true" deadfish overflow detection:

julia> include("deadfish.jl") deadfish (generic function with 3 methods)

julia> deadfish("iissso") >> i >> i >> s >> s >> s >> o 0

julia> deadfish("iissiso") >> i >> i >> s >> s >> i >> s >> o 289

Kipple
(i>r) (r r-105 r>c 0>y c? (c y? 0>c?) (y a+1 1>f y?)  r-100 r>c 0>y c? (c y? 0>c?) (y a-1 1>f y?)  r-111 r>c 0>y c? (c y? 0>c?) (y a+0 a>@ (@>p) (p>q) 10>q y?)  r-115 r>c 0>y c? (c y? 0>c?) (y a+0 a>m+0 m>n 0>s (m-1 n+0 s+n m?) s>a 0>s? y?)

r>t a+0 a>b 0>y b+1  b? (b y? 0>b?) (y 0>a y?) a+0 a>b 0>y b-256 b? (b y? 0>b?) (y 0>a y?) ) (q>o)

Kitanai
$0[0]#$1[input">> "]?(add(eq($0@)256) (eq($0@)-1))([0])?(eq($1@)"i")($0[add@1])? (eq($1@)"d")($0[sub@1])?(eq($1@)"o") (print($0@))?(eq($1@)"s")($0[mul@@])&1 $"accumulator"[0] $"userInput"[input">> "] ?(eq ($"accumulator" @) 256) ($"accumulator"[0]) ?(eq ($"accumulator" @) -1) ($"accumulator"[0]) ?(eq ($"userInput" @) "i") ($"accumulator"[add @ 1]) ?(eq ($"userInput" @) "d") ($"accumulator"[sub @ 1]) ?(eq ($"userInput" @) "o") (print($"accumulator" @)) ?(eq ($"userInput" @) "s") ($"accumulator"[mul @ @]) &1
 * Compact version :
 * "Clean" version :

Kotlin
fun main(args : Array<String>) { var isSquared : Boolean = false var input : String? var a : Int = 0 while (true){ print(">> ") input = readLine when(input){ "i" -> {if (a == 256 && !isSquared) a = 0; a++} "d" -> {if (a < 0 && !isSquared) a = 0; a--} "o" -> println(a) "s" -> {isSquared = (a >= 256); a *= a}           else -> println }   } }

LOLCODE
BTW, This is a Deadfish interpreter in LOLCODE.
 * 1) !/usr/bin/env lci

HAI 1.3

HOW IZ I reading YR op   GIMMEH op, FOUND YR op IF U SAY SO

I HAS A x ITZ 0

IM IN YR reader... I IZ reading YR op MKAY TIL BOTH SAEM op AN "" op, WTF? OMG "i", x R SUM OF x AN 1, GTFO OMG "d", x R DIFF OF x AN 1, GTFO OMG "s", x R PRODUKT OF x AN x, GTFO OMG "o", VISIBLE x   OIC

EITHER OF BOTH SAEM x AN -1 AN BOTH SAEM x AN 256, O RLY? YA RLY, x R 0 OIC IM OUTTA YR reader

KTHXBYE

Lua

 * 1) !/usr/bin/env lua

accumulator = 0 while true do   io.write(">> ") local input = io.stdin:read'*l' if accumulator == 256 or accumulator < 0 then accumulator = 0 end if input == "i" then accumulator = accumulator + 1 elseif input == "d" then accumulator = accumulator - 1 elseif input == "s" then accumulator = accumulator ^ 2 elseif input == "o" then print(accumulator) end end

METAFONT
This is limited range due to limit of numbers in METAFONT. scrollmode; warningcheck:=0; inner end; Q:=0; def Z = if(Q<0)or(Q=256):Q:=0;fi enddef; def i = Q:=Q+1;Z; enddef; def d = Q:=Q-1;Z; enddef; def s = Q:=Q*Q;Z; enddef; def o = message decimal Q; enddef; def h = ;end; enddef;

Mirah
no=0 while true do   if no==-1 or no==256 then no=0 end print ">> " the_cmd = System.console.readLine if the_cmd.equals("d") then no=no-1 elsif the_cmd.equals("i") then no=no+1 elsif the_cmd.equals("s") then no=no*no end if the_cmd.equals("o") then puts "#{no}" end end

MIX (Knuth)
Assembly code (the MIXPC assembler; not quite the same as MIXAL):
 * DEADFISH ON MIX
 * PUBLIC DOMAIN

BASE 100 START

* STORE CURRENT VALUE IN ACCUMULATOR RESET  ENTA 0

* DISPLAY PROMPT AND REQUEST INPUT MAIN   CMPA =256= JE RESET OUT PROMPT(19) IN INBUF(19) JBUS *(19)

* DISPATCH BY INPUT LD1 INBUF(1:1) DEC1 'D'       J1Z OP_D DEC1 'I'-'D'       J1Z OP_I DEC1 'O'-'I'       J1Z OP_O DEC1 'S'-'O'       J1Z OP_S JMP MAIN

* DECREMENT OP_D   JAZ MAIN DECA 1 JMP MAIN

* INCREMENT OP_I   INCA 1 JMP MAIN

* SQUARE OP_S   STA 0 MUL 0 SLAX 5 JMP MAIN

* OUTPUT OP_O   STA 0 CHAR 1H     CMPA ='0'(1:1)=(1:1) JNE 1F SLAX 1 JMP 1B 1H     JANZ 1F LDA ='0'(1:1),0(2:5)= 1H     STA INBUF STX INBUF+1 OUT INBUF(19) LDA 0 JMP MAIN

PROMPT TEXT ">>" FILL PROMPT+14

INBUF  FILL *+14

END Deck (for use with decimal versions of MIX) (note that each card has a space in the first character position): N O6 A O4   H N ENX   E K BU    I OALH   A. PAEN D LB    E  AEU  ABG G  9 5 7  5  2487 5 5  53971 25 193671 25  9 97 665  1417 695  1417 755  141        5171165  5567 885 19377 555 19347  45  1497  55  1497  75  1497  65  149        647 715  1417 515  14 7 515   397 515   397   5  5 37 515   397   5  1 5        657 515   397  15  1487  15   487   5  5247  55  2 67   5  52471175  956        787 815  8397 775   3971185  5 871 35  5317   5  5 821515     7   5             797  15  2 67 835  44 71 25  52471 25 19377 515   397   5     7   5             927   5     7   5     7   5     7   5     7   5     7   5     7   5             937   5     7   5     7   5     7   5     7   5     7   5     7   5            1 67   5     7   5     7   5     7   5     7   5     7   5  2560   5            1 77   5     7   5     7   5     7   5     7   5     0   5                       147 5 5   39

MMIX
v	GREG 0 LOC Data_Segment buf	OCTA 0,0,0,0 buf2	BYTE 0,10,0 arg	OCTA buf,1 GREG buf

LOC #100 BYTE ">> ",0 G256	GREG #100 % Prompt for and read input Main	LDA $255,#100 TRAP 0,Fputs,1 LDA $255,arg TRAP 0,Fread,0 % Set to zero if -1 or 256 ZSP v,v,v CMP $0,v,G256 CSZ v,$0,0 % Check what command has been specified LDBU $0,buf SUB $0,$0,10 BZ $0,Main SUB $0,$0,'d'-10 PBNZ $0,1F % Decrement SUB v,v,1 PBZ $0,2F 1H	SUB $0,$0,'i'-'d'	PBNZ $0,1F % Increment ADD v,v,1 PBZ $0,2F 1H	SUB $0,$0,'o'-'i'	PBNZ $0,1F % Output LDA $255,buf2 DIV $1,v,10 3H	GET $0,rR ADDU $0,$0,'0' STBU $0,$255 BZ $1,3F SUBU $255,$255,1 DIV $1,$1,10 PBNZ $255,3B 3H	TRAP 0,Fputs,1 PBZ $1,2F 1H	SUB $0,$0,'s'-'o'	PBNZ $0,1F % Square MUL v,v,v PBZ $0,2F 1H	ADD $0,$0,'s'-'h'	BNZ $0,2F % Halt TRAP 0 % Skip the rest of the input line 2H	LDA $255,arg TRAP 0,Fread,0 LDBU $0,buf SUB $0,$0,10 PBNZ $0,2B PBZ $0,Main

MNNBFSL
Currently, all instructions must be on a single line.

[ _ <[<[-"]++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<[<_[->+<"][]>"+_ ]_+">++++]_checked if acc = 1 under 0> <"[<[-"]++++"">>>[<[-"]<<-[>"<-"][]<-[>>>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<<-"][][->+<"][][->-<"]_ [<[-"]++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<[<_[->+<"][]>[]_ ][-"]">++++] checked if acc = 256      >_ ,_+[-"][][<[-"]++++++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<[->-<"] [++++++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<<[->+<"][]>"_ ]<->++">] checked if command = d  _ _ -_ [<[-"][++++++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<<[->+<"][]>"_ ]<+>++">] checked if command = i  _ _ --_ [<[-"][++++++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<<[->+<"][]>"_ ]<".>++">] checked if command = o_ _ _ [<[-"][++++++++++">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<<[->+<"][]>"_ ]<">>[<[-"]<<-[>"<-"][]>[[-<<<+>>>"][]"][]<>++">] checked if command = ^2

Nim
var a = 0 while true: if a == -1 or a == 256: a = 0 write(stdout, ">> ") case readLine(stdin) of "d": a -= 1 of "i": a += 1 of "o": echo(a) of "s": a = a * a

Nqubl
Implementation by David Catt (User:David.werecat), interprets only one instruction per line. # " >>"E GT3S3T0T0T0T0S0 "i"=!KX}S2MS0# "d"=!KX}S2DS0# "s"=!KX}S2T3S4~0~]#S3T0S0~0~=KX}S3DS2T0S4T0S0+T4{#S4T2S0# "o"=!KX}S2NS0~10~P# S2T0T0S0 ~256~=!KX}S2~0~S0# ~-1~=!KX}S2~0~S0# [[[[[[[[{
 * 1) G~10~=KX}{#

OASYS (OAC)
class player {}

property int dummy

int value

method check { if value == -1 or value == 256 value = 0 }

method increment verbs {{i} {x}} { value = value + 1 this check }

method decrement verbs { value = value - 1 this check }

method square verbs {{s} {k}} { value = value * value this check }

method output verbs {{o} {c}} { print value print "\n" }

method init { player = create player }

OASYS Assembler
[&]%@*> ['I'X]%#%#<UP>+&CHK ['D]%#%#<DN>+&CHK ['S'K]%#%#<%#<MUL>+&CHK ['O'C]%#<PI CR [&CHK]%#<-1EQ/%#<256EQ/ RP:%#0>

Obfuscated C
Implementation by David Catt (User:David.werecat), interprets only one instruction per line. V J{W Z(a)H m;E(1)D(K((K(30,+,1)),<<,1))F(Q,m,G)U(m)B(K(3,*,K(5,*,7)),X(a,++))B(K((K(5,*,5)),<<,2),X(a,--))B(111,P(a))B(K(5,*,23),K(a,*=,K(a,^,0)))}T(K((K(a,<,0)),|,(K(a,==,(K(1,<<,8))))))Z(a)}T(Y(m))E(Y(G))M
 * 1) include <stdio.h>
 * 2) define A case
 * 3) define B(x,y) A x:;y;R;
 * 4) define C "%c"
 * 5) define D(x) O(S,x);S(x)
 * 6) define E(x) O(while,x){
 * 7) define F(x,y,z) x(y,z);
 * 8) define G getchar
 * 9) define H char
 * 10) define I "%i"
 * 11) define J main
 * 12) define K(x,y,z) x y z
 * 13) define L printf
 * 14) define M }}}}
 * 15) define N "\n"
 * 16) define O(x,y) x(y)
 * 17) define P(x) F(L,I N,x)
 * 18) define Q(x,y) K(x,=,y)
 * 19) define R break
 * 20) define S(x) F(L,C,x)
 * 21) define T(x) O(if,x){
 * 22) define U(x) O(switch,x){
 * 23) define V void
 * 24) define W int
 * 25) define X(x,y) x y
 * 26) define Y(x) K(x,!=,10)
 * 27) define Z(x) Q(x,0);

OCaml
let rec loop (x', s) : (int * string) -> unit = print_string (s ^ ">> "); let line = read_line in   let c = if String.length line > 0 then line.[0] else '?' in   let x = match x' with (-1 | 256) -> 0 | _ -> x' in   loop (match c with   | 'i' -> (x+1, "")   | 'd' -> (x-1, "")   | 'o' -> (x, string_of_int x ^ "\n")   | 's' -> (x*x, "")   | _   -> (x, "\n")   ) let _ = loop (0, "")

OOLANG
In this interpreter added instruction "h", to end execution. x.0.set; a.label; a.Input code:..in;

x>256.31.5.ifa;

x<0.31.7.ifa;

a==i.9.12.ifa;

x.inc; a.goto;

a==d.14.17.ifa;

x.dec; a.goto;

a==s.19.22.ifa;

x.x.mul; a.goto;

a==o.24.27.ifa;

x.get; a.goto;

a==h.29.29.ifa;

.halt;

x.0.set; a.goto;

Pascal
PROGRAM deadfish (INPUT, OUTPUT); VAR cmd: CHAR; acc: INTEGER; BEGIN acc := 0; REPEAT WRITE(‘>>’); READLN(cmd); CASE cmd OF ‘i’ : acc := acc+1; ‘d’ : acc := acc-1; ‘s’ : acc := SQR(acc); ‘o’ : WRITELN(acc); END; IF acc<0 THEN acc := 0; IF acc=256 THEN acc := 0; UNTIL cmd=‘h’; END.

Perl

 * 1) !/usr/bin/perl -w

my $acc=0; while (1) { print ">> "; $_ = <>;   if ($acc==-1 or $acc==256) { $acc=0; } if (/^i$/) { $acc++; } elsif (/^d$/) { $acc--; } elsif (/^o$/) { print $acc, "\n"; } elsif (/^s$/) { $acc*=$acc; } else { print "\n"; } }

Pure
using system; fish a "i" = a+1; fish a "d" = a-1; fish a "s" = a*a; fish a "o" = a when puts (str a) end; limit a = if a == 256 || a < 0 then 0 else a; main a = (printf "%s " ">>") $$ (main (fish (limit a) (gets))); main 0;

Python
""" Deadfish Programming Language Interpreter Programmed by Jonathan Todd Skinner This code is hereby released into the public domain Harry eased the mess """

accumulator = 0
 * 1) Initialization

while True: # Get user input cmd = raw_input('>> ') if accumulator == 256 or accumulator == -1: # Overflow, reset accumulator accumulator = 0 # Process input if cmd == 'i': accumulator += 1 # Increment elif cmd == 'd': accumulator += -1 # Decrement elif cmd == 'o': print accumulator # Output elif cmd == 's': accumulator *= accumulator # Square else: print 'Unrecognized command.'
 * 1) Main program loop

Python 3.x

 * 1) !/bin/env python3

''' Deadfish Interpreter written in python3. Written by chill0r. Everything is free to use - no restrictions.

Startup arguments: -strict: Output errors (and abort) on invalid characters and Overflow -p program: Execute program (does not exit if not told so) Accepted characters (case sensitive!): i / x: increment by 1 d: decrement by 1 s / k: square o / c: print accumulator h: exit interpreter (and stop program) (non standard) r: reset accumulator to 0 (non standard) ''' import sys

class DeadfishError(Exception): def __init__(self, message): print(message) sys.exit(1)

prog = sys.argv[sys.argv.index('-p')+1] if '-p' in sys.argv else None strict = '-strict' in sys.argv

acc = 0 i = 0

print(Python3 Deadfish interpreter version 0.1)

while True: if not bool(prog): prog = input('>>') for char in prog: if strict and not char in ['i', 'x', 'd', 's', 'k', 'h', 'o', 'c', 'r']: raise DeadfishError('Invalid character {} at index {}'.format(char, i)) if char in ['i','x']: acc += 1 elif char == 'd': acc -= 1 elif char in ['s', 'k']: acc *= acc elif char == 'h': print('Long live the fish!') sys.exit(0) elif char == 'r': acc = 0 if acc < 0 or acc == 256: if strict: raise DeadfishError('Overflow at char {} (Index {}) accumulator = {}'.format(char, i, acc)) else: acc = 0 if char in ['o', 'c']: print(acc) i += 1 prog = None i = 0

R
n <- 0 while(TRUE) { if(n==-1 || n==256) n <- 0 cmd <- scan(n=1,what='character') fun <- switch(cmd,               d=function(x) x-1,                i=function(x) x+1,                o=function(x) { cat(x,"\n"); x },                s=function(x) x*x) if(!is.null(fun)) n <- fun(n) }

Ruby
Implementation by Abe Voelker

n = 0 while true print '>> ' gets.chomp.each_char do |c| n = 0 if [-1, 256].include?(n) case c     when 'd' then n -= 1 when 'i' then n += 1 when 'o' then puts n     when 's' then n *= n    end end end
 * 1) !/usr/bin/env ruby

Rust
use std::io; use std::io::Read; use std::io::Write; fn main { let mut stdin = io::stdin; let input = &mut String::new; let mut acc: i64 = 0; loop { print!(">> "); io::stdout.flush; input.clear; stdin.read_line(input); for chr in input.chars { match chr{ 'i' => acc+=1, 'd' => acc-=1, 'o' => println!("{}",acc), 's' => acc *= acc, '\n'=> continue, _  => println!(""), }       }         acc = if acc == 256 || acc < 0 {0} else {acc} } }

Röda
{i=0;chars|{|k|i++if[k="i"];i--if[k="d"];i*=i if[k="s"];print i if[k="o"];i=0 if[i=-1 or i=256]}_}

The language defined by the Revised Revised Revised Revised Revised Report on the Algorithmic Language Scheme
(define (execute n cmd) (case cmd ((#\i) (+ n 1)) ((#\d) (- n 1)) ((#\s) (* n n)) ((#\o) (display n) (newline) n)   (else n)))

(define (deadfish n) (let ((char (read-char))) (cond    ((or (= n -1) (= n 256)) (deadfish 0))     ((eof-object? char) n)     (else (deadfish (execute n char))))))

(deadfish 0)

Seed7
This version includes the optional halt command (for if this was not included, you would need to press Ctrl+C, then, to exit the interpreter.  Or enter a blank line to make it crash.)  This is not really conformant as the spec says that errors are ignored

$ include "seed7_05.s7i"; include "stdio.s7i"; var boolean: keep_going is TRUE; var integer: accumulator is 0; var string: command is ""; const proc: main is func begin while keep_going do      if accumulator = 256 or accumulator < 0 then accumulator := 0; end if; write(">> "); readln(command); case command[1] of        when {'s'}: accumulator := accumulator * accumulator; when {'o'}: writeln(accumulator); when {'i'}: accumulator := accumulator + 1; when {'d'}: accumulator := accumulator - 1; when {'h'}: keep_going := FALSE; otherwise: writeln("STOP CONFUSING ME"); end case; end while; end func;

A more awesome version of this implementation would use Seed7's ability to create new program structures.

S-Lang
variable l=" ", n=0, r; forever { if (n==-1||n==256) n=0; r=fputs(">> ", stdout); r=fgets(&l, stdin); switch (l[0]) { case 'd': n--; } { case 'i': n++; } { case 'o': print(n); } { case 's': n=n*n; } } }
 * 1) !/usr/bin/env slsh

Protip 1: if you do not do something with the result of  and   (assign them to the scratch variable   in this case),   eventually runs out of stack space.

Protip 2: the braces in the above program are not matched correctly. does not seem to care.

SmileBASIC
Takes a line from stdin and runs all characters in said line. Unrecognized commands print a newline. Commands are case-sensitive, lowercase. Implements  and proper   behavior. OPTION STRICT 'declare vars VAR X% VAR S$,C$

'REPL loop REPEAT LINPUT ">> ";S$ 'get line from stdin 'exec all chrs in line WHILE LEN(S$)!=0 C$=SHIFT(S$) 'pop chr from front of string IF C$=="i" THEN INC X% ELSEIF C$=="d" THEN DEC X% ELSEIF C$=="s" THEN 'square x  X%=X%*X% ELSEIF C$=="o" THEN 'output x  PRINT X%  ELSEIF C$=="h" THEN BREAK ELSE PRINT 'adds a newline ENDIF IF X%==-1||X%==256 THEN X%=0 'zero behavior WEND UNTIL C$=="h"

SNUSP
/@@@=@@@=++++#	100 = 5*5*4 = 'd'  /          |                \! \ $=!\>,+?!#-=>@/=!/?!\<?\>!/?\<</ |      eof? 'd'  \->| -/  \-/     | \<?\==!=== < -/          'i'/  +++++>/  |       ! \ !/?!\<?\> /      |                 \->| -/  !       |                    \<?\==|==  < +/           'o'/ ++++++>/  |       ! \ !/?!\<?\> /      |                 \->| -/  !       |                    \<?\==|==  < ./           's'/   ++++>/  |       ! \ !/?!\<?\> /      |                 \->| -/          | /= square = < = /?</             | | /======= > =!\ noop =!/==  <  / | |       / ++<+<\      | \?!/>>+<<-?\>!/>-?/<<+>?!/>+<\    \  up2  /  \          \?- /

SQL
In order to use this program, another program (possibly written in C or some other programming language) must make the <tt>INPUT</tt> and <tt>OUTPUT</tt> views to do the necessary things.

PRAGMA RECURSIVE TRIGGERS = 1;

CREATE TABLE `DEADFISH` (`VALUE` INT);

INSERT INTO `DEADFISH` VALUES (0);

CREATE VIEW `INPUT` AS SELECT '' AS `INPUT`;

CREATE VIEW `OUTPUT` AS SELECT '' AS `OUTPUT`;

CREATE TRIGGER `INCREMENT` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 'i' BEGIN UPDATE `DEADFISH` SET `VALUE` = `VALUE` + 1; UPDATE `DEADFISH` SET `VALUE` = 0 WHERE `VALUE` = 256; END;

CREATE TRIGGER `DECREMENT` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 'd' BEGIN UPDATE `DEADFISH` SET `VALUE` = `VALUE` - 1 WHERE `VALUE` > 0; END;

CREATE TRIGGER `SQUARE` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 's' BEGIN UPDATE `DEADFISH` SET `VALUE` = `VALUE` * `VALUE`; UPDATE `DEADFISH` SET `VALUE` = 0 WHERE `VALUE` = 256; END;

CREATE TRIGGER `OUTPUT` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 'o' BEGIN INSERT INTO `OUTPUT` SELECT `VALUE` AS `OUTPUT` FROM `DEADFISH`; END;

Stackstack
0 ">> " dup while dup print swap inputstr dup "d" eq if swap  1 - endif dup "i" eq if swap  1 + endif dup "s" eq if swap dup * endif dup "o" eq if swap dup tostring 10 char concat print endif dup -1 eq if pop 0 endif dup 256 eq if pop 0 endif -3 roll pop dup endwhile

StaPLe
eval;dup; [eval;dup;if;swap;[R0;];&#124;&#124;;!;+;1;swap;!;-;256;dup;pop;dup;push;ife;swap; [drop;pop;+;1;push;];swap;[ife;swap;[drop;pop;-;1;push;];swap;[ife;swap; [drop;pop;*;dup;push;];swap;[ife;swap;[putc;10;put;pop;dup;push;]; swap;[putc;10;];==;"o;];==;"s;dup;];==;"d;dup;];==;"i;dup;getc;];R0;

Staq
&iiqqq&{o:&iiiqi;@X}{T-!@_x}{i_iT}{D_d}{d?DT}{sqT}{ks}{xi}{co}{>id}

Allows the command sets of both variations.

Stlang
Reads one line of input.

M 0 (i /r f \ fn f .<+;h d ;t f \ fn f: .$ \ fn d \ fn d:i .$<>I c <> \ fn d:d .$<>D c <> \ fn d:s .$<><+* c <> \ fn d:o .$<><+@<> \ fn c \ fn c:256 .$0(i \ fn c:-1 .$0(i \

TAVERN
INCLUDE standard.inc

<RAM>

0 VARIABLE VALUE

HERE CONSTANT INPUT-TABLE 1, 4 ALLOT

<ROM>


 * START

BEGIN || >> | INPUT-TABLE ACCEPT INPUT-TABLE 1 + @ IF     INPUT-TABLE 2 + @ ?DUP IF        EXECUTE ELSE CR     THEN ELSE CR   THEN VALUE @ 256 = VALUE @ -1 = OR IF 0 VALUE ! THEN AGAIN


 * VALUE INCR ; VOCAB I
 * VALUE DECR ; VOCAB D
 * VALUE @ DUP * VALUE ! ; VOCAB S
 * VALUE @ . CR ; VOCAB O
 * QUIT ; VOCAB H

TeX
% Deadfish interpreter in TeX

\catcode32=9\endlinechar=-1

\newcount\accumulator

\def\checkwrapping{ \ifnum\accumulator=256\accumulator=0\fi \relax \ifnum\accumulator=-1\accumulator=0\fi }

\def\I{ \advance\accumulator by 1 \checkwrapping }

\def\D{ \advance\accumulator by -1 \checkwrapping }

\def\S{ \multiply\accumulator by \accumulator \checkwrapping }

\def\O{ \message{\the\accumulator} }

\tracingonline=-1 \scrollmode

\def\Activate{ \catcode105=13 \catcode100=13 \catcode115=13 \catcode111=13 }

\catcode62=11

\def\Start{ \escapechar=-1 \loop \read16 to \>> \>> \iftrue\repeat }

\Activate \leti=\I \letd=\D \lets=\S \leto=\O \Start

TeXnicard
To use this program, save it in the file called "<tt>deadfish.cards</tt>" and then type in "<tt>@I deadfish.cards</tt>" at the "<tt>E&gt;</tt>" prompt. And then it change to "<tt>C&gt;</tt>" prompt and it is ready for typing in commands of deadfish. @. Deadfish implementation in TeXnicard. [d[c0][]dixd256-[][0*][]ix[]]s0 (patterns)sP0 @S i 1+`0x @S d 1-`0x @S s d*`0x @S o ?s[] @P patterns <i
 * i;

<d
 * d;

<s
 * s;

<o
 * o;

@C main

Thutu
This stores data in unary, which explains its inefficiency and the length of one of the lines. /=>=> =x/z=x/ /=>=> =x/> /=1/=n=>=> =xse/ /^i=xs(a*)e/=>=> =xs$1ae/ /^d=xsa?(a*?)e/=>=> =xs$1e/ /^s=xs(a*)a(b*)e/s=xs$1b$2e$1$2b/ /^s=xs(b*)e(a*)b/s=xs$1e$2a/ /^s=xs(b*)e(a*)$/=>=> =xs$2e/ /^o=xs(a*)e$/o=xs$1v/ /(=x.*[sbc])v/$1w0/ /(=x.*[sbc])av/$1cw1/ /(=x.*[sbc])aav/$1ccw2/ /(=x.*[sbc])aaav/$1cccw3/ /(=x.*[sbc])aaaav/$1ccccw4/ /(=x.*[sbc])aaaaav/$1cccccw5/ /(=x.*[sbc])aaaaaav/$1ccccccw6/ /(=x.*[sbc])aaaaaaav/$1cccccccw7/ /(=x.*[sbc])aaaaaaaav/$1ccccccccw8/ /(=x.*[sbc])aaaaaaaaav/$1cccccccccw9/ /(=x.*[sbc])aaaaaaaaaa(a*)v/$1bbbbbbbbbb$2v/ /(=xsc*)bbbbbbbbbb(.*)w/$1ccccccccca$2w/ /(=x.*)ab(.*w)/$1ba$2/ /(=x.*)ac(.*w)/$1ca$2/ /(=x.*)bc(.*w)/$1cb$2/ /=xs([ca]*)aw/=xs$1av/ /=xs(c*)w/=xs$1x/ /=xs(c*)c(a*)x/=xs$1a$2x/ /^o=xs(a*)x(.*)$/$2=n=>=> =xs$1e/ /^.*=x/=n=>=> =x/ . /=xsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae/se/ .

TI-68k
deadfish(src) Prgm Local acc 0->acc Loop Local cmd left(src,1)->cmd If acc=256 or acc<0 Then 0->acc EndIf If cmd="i" Then acc+1->acc ElseIf cmd="d" Then acc-1->acc ElseIf cmd="s" Then acc^2->acc ElseIf cmd="o" Then Disp acc EndIf If dim(src)=1 or cmd="h" Then Exit EndIf right(src,dim(src)-1)->src EndLoop EndPrgm

TI-BASIC
ClrHome Disp "REGULAR DEADFISH","IDSO INTERPRETER DelVar AInput Str1 //DelVar doesn't need a colon or newline after its argument; this is the same as "DelVar A:Input Str1" For(B,1,length(Str1 sub(Str1,B,1 If Ans="O Disp A A(not(Ans="S")+A(Ans="S"))+(Ans="I")-(Ans="D Ans(Ans<256 and Ans->A End

Turing
% Deadfish in Turing % Implemented by Chris Pressey on August 4 2012, % in the Deadfish Cafe in Winnipeg, Manitoba, Canada % (Thus, this is also "Deadfish in Deadfish")

var accumulator : int var command : string (1)

accumulator := 0 loop if accumulator = 256 or accumulator < 0 then accumulator := 0 end if   put ">> " .. get command if command = "i" then accumulator := accumulator + 1 elsif command = "d" then accumulator := accumulator - 1 elsif command = "s" then accumulator := accumulator * accumulator elsif command = "o" then put accumulator else put "Unrecognized command." end if end loop

Unlambda
This implementation uses Church numerals, which are essentially unary. Use large ones at your own risk.

````sii ``s``s`ks ``s``s`kskk `k ``s``s `d`k `````.>.>. @ic `k ``s``s``s``s`k?i`kii`k ``s``s`ks ``s`k`s`ks ``s`k`s`kk i `ki ``s``s``s``s`k?d`kii`k ``s``s``si `k ``s``s`ks ``s`k`si ``s`kk ``s``s`ks ``s`k`s`ks ``s`k`s`kk ``si`kk `ki ``s`kk ``si`kk `k`k`ki `k`ki ``s``s``s``s`k?o`kii`k ``sk ``s`kr ``s`k ```sii ``s `k `s``s``si `k ``s``s``si`kk ``s`k`s``si`k `k``si`k `k``si`k `k``si`k `k``si`k `k``si`k `k``si`k `k``si`k `k``si`k `k``si`k k                 ``s`kk ``s``s`ks``s`k`s`ks ``s`k`s`kk ``si`k`ki `ki ``s`k`s``s`ks``s`k`sik ``s`kk``s`kk``si`k`ki `ki ``s`kk ``s``s`ks ``s`k`s`ks ``s`k`s`kk `k ``s``si`k.9 `k ``s``si`k.8 `k ``s``si`k.7 `k ``s``si`k.6 `k ``s``si`k.5 `k ``s``si`k.4 `k ``s``si`k.3 `k ``s``si`k.2 `k ``s``si`k.1 `k `k.0 ``s`kk ``s``s`ks``s``s`ks `k ``s`kc ``s`k`s`k`k`ki ``s``s`ks``s``s`ksk `k`k``si`ki `kk ``s``s`kskk `ki ``s `k`s``s`ks k i         ``s``s``s``s`k?s`kii`k ``s``s`ks k i          ``si`kr ``s``s`kc ``s`k`s`k`ki ``s``s`ks ``s``s`ks ``s``s`ks k `k``s`k`sik `k `k ``````s``s`ks k ``s``s`ks k i               ``s``s`ks k i ``s``s`ks k i                k ``si`ki `k ``s`kd ``si `k`k`ki i `ki

Unofficial MagicKit Assembler
This is probably the longest one (due to so many things that aren't built-in, so it has to implement all of them). Note, it contains tabs which are necessary to compile properly. You can download the compiled file, source codes, and ".NES.INI" in the external resources section.

To use, push a key "I", "D", "S", or "O" at the prompt. A line break is automatically added after each command; all keys other than "I", "D", "S" and "O" (including the DELETE and RETURN key) are ignored; all buttons on both gamepads are also ignored, and so is the microphone. (If you want to restart the program, push the RESET button on the console.)

inesprg 1 ; 16K PRG ROM ineschr 1 ; 8K CHR ROM inesmir 1 ; vertical mirroring inesmap 0 ; NROM
 * Deadfish implementation for Nintendo Famicom

zp digits	ds 8 spare	ds 1 scroll1	ds 1 scroll2	ds 1 blink1	ds 1 blink2	ds 1 csrlin	ds 1 temp2	ds 1 temp3	ds 1 temp4	ds 1 multacc	ds 17

code

bank 0

; Sprites org $C000 oamdata	db 215,16,0,32 ; Cursor db 223,15,0,$08, 223,15,0,$10, 223,15,0,$18, 223,15,0,$20 ; First hidden row db 223,15,0,$28, 223,15,0,$30, 223,15,0,$38, 223,15,0,$40 db 231,15,0,$08, 231,15,0,$10, 231,15,0,$18, 231,15,0,$20 ; Second hidden row db 231,15,0,$28, 231,15,0,$30, 231,15,0,$38, 231,15,0,$40

; Multiplication table org $C100 muones	db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 db 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5 db 0,2,4,6,8,0,2,4,6,8,0,2,4,6,8,0 db 0,3,6,9,2,5,8,1,4,7,0,3,6,9,2,5 db 0,4,8,2,6,0,4,8,2,6,0,4,8,2,6,0 db 0,5,0,5,0,5,0,5,0,5,0,5,0,5,0,5 db 0,6,2,8,4,0,6,2,8,4,0,6,2,8,4,0 db 0,7,4,1,8,5,2,9,6,3,0,7,4,1,8,5 db 0,8,6,4,2,0,8,6,4,2,0,8,6,4,2,0 db 0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5 mutens	db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;0 db 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1 ;1 db 0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3 ;2 db 0,0,0,0,1,1,1,2,2,2,3,3,3,3,4,4 ;3 db 0,0,0,1,1,2,2,2,3,3,4,4,4,5,5,6 ;4 db 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7 ;5 db 0,0,1,1,2,3,3,4,4,5,6,6,7,8,9,9 ;6 db 0,0,1,2,2,3,4,4,5,6,7,7,8,9,9,0 ;7 db 0,0,1,2,3,4,4,5,6,7,8,8,9,0,1,2 ;8 db 0,0,1,2,3,4,5,6,7,8,9,9,0,1,2,3 ;9 ;; 0 1 2 3 4 5 6 7 8 9 A B C D E F

; Addition table adones	db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 db 0,1,2,3,4,5,6,7,8,9 adtens	db 0,0,0,0,0,0,0,0,0,0 db 1,1,1,1,1,1,1,1,1,1 db 2,2,2,2,2,2,2,2,2,2 db 3,3,3,3,3,3,3,3,3,3 db 4,4,4,4,4,4,4,4,4,4 db 5,5,5,5,5,5,5,5,5,5 db 6,6,6,6,6,6,6,6,6,6 db 7,7,7,7,7,7,7,7,7,7 db 8,8,8,8,8,8,8,8,8,8 db 9,9,9,9,9,9,9,9,9,9

; =256 table eq256	db 6,5,2,0,0,0,0,0

bank 1 org $E000

; Initialize APU/PPU/CPU reset	sei ldx #$FF txs inx stx $2000 stx $4015 bit $2002 ; Clear VBL vwait1	bit $2002 bpl vwait1 vwait2	bit $2002 bpl vwait2 stx $2000 stx $2001 ; Disable PPU

; Initialize RAM ldy #csrlin initram	stx <0,y dey bpl initram lda #216 sta <scroll2

; Initialize palette lda #$3F sta $2006 stx $2006 ldy #$0A initpal	sta $2007 stx $2007 dey bne initpal

; Clear screen lda #$20 sta $2006 stx $2006 lda #$0F clrscr	sta $2007 sta $2007 sta $2007 sta $2007 dex bne clrscr

; Display prompt prompt	ldx #$00 stx $2000 stx $2001 jsr newline lda #$0A sta $2007 sta $2007 lda #$0F sta $2007 sta $2007 sta $2007 sta $2007 sta $2007 sta $2007 lda #$80 sta $2000

; Wait until all keys are not pushed keywait	lda #8 sta <csrlin ldy #$05 ldx #$04 sty $4016 iny keyw1	stx $4016 lda $4017 and #$1E eor #$1E bne keywait sty $4016 lda $4017 and #$1E eor #$1E bne keywait dec <csrlin bne keyw1

; Read keyboard keyloop ldy #$05 ldx #$04 sty $4016 iny stx $4016 sty $4016 stx $4016 ; Skip row 0 sty $4016 stx $4016 ; Skip row 1 lda $4017 and #$04 beq keyo sty $4016 stx $4016 ; Skip row 2 lda $4017 and #$04 beq keyi sty $4016 stx $4016 ; Skip row 3 sty $4016 stx $4016 ; Skip row 4 lda $4017 and #$10 beq keyd sty $4016 stx $4016 ; Skip row 5 lda $4017 and #$08 beq keys jmp keyloop

keyo	lda #$0E jsr letter jmp cmdo

keyi	lda #$0B jsr letter jmp cmdi

keyd	lda #$0C jsr letter jmp cmdd

keys	lda #$0D jsr letter jmp cmds

; Output cmdo	jsr newline lda #$0F sta <csrlin ldy #7 out1	lda 0,y cpy #0 beq out2 cmp #0 beq out3 out2	stx <csrlin out3	eor <csrlin sta $2007 dey bpl out1 jmp prompt

; Increment cmdi	stx <spare ; Clear guard digit incr1	inc <0,x lda <0,x cmp #10 bne chk256 lda #0 sta <0,x inx bne incr1 chk256	ldx #0 incr2	lda <0,x cmp eq256,x bne incr3 ; It isn't "256" inx cpx #8 bne incr2 sta <0 sta <1 sta <2 incr3	jmp prompt

; Decrement cmdd	lda <0,x bne decr1 inx cpx #$08 bne cmdd jmp prompt ; It is already zero decr1	ldx #$00 decr2	lda <0,x beq decr3 dec <0,x jmp chk256 ; Now check if equal to 256 decr3	lda #9 sta <0,x inx bne decr2

; Square cmds	stx <spare ; Clear guard digit ldy #16 squ1	stx <multacc,y ; Clear multiplication accumulator memory dey bpl squ1 ldy #7 squ2	ldx #7 squ3	lda <0,x sta <csrlin lda 0,y asl a	asl a	asl a	asl a	eor <csrlin sty <csrlin tay lda muones,y sta <temp2 ; Ones digit lda mutens,y sta <temp4 ; Tens digit stx <temp3 lda <csrlin ; Position of a digit clc adc <temp3 ; Position of another digit tay lda <temp2 adc multacc,y sta multacc,y lda <temp4 clc adc multacc+1,y sta multacc+1,y ldy <csrlin dex bpl squ3 dey bpl squ2 ; Now conversion into base ten proper digits inx stx <temp2 ; Carry squ4	lda <multacc,x clc adc <temp2 tay lda adones,y sta <0,x lda adtens,y sta <temp2 inx cpx #8 bne squ4 jmp chk256 ; Check if equal to 256

; New line routine (expects X=0) newline	lda <scroll1 clc adc #8 cmp #240 bne nscrz1 txa nscrz1	sta <scroll1 lda <scroll2 clc adc #8 cmp #240 bne nscrz2 txa nscrz2	sta <scroll2 ldy #$08 sty <csrlin asl a	rol <csrlin asl a	rol <csrlin ldy <csrlin sty $2006 ora #$01 sta $2006 rts

; Write letter to screen (A=letter to write) letter	pha ldx #$00 stx $2000 stx $2001 lda <scroll2 jsr nscrz2 lda #$0A sta $2007 sta $2007 lda #$0F sta $2007 pla sta $2007 rts

; NMI handler nmi	pha

; Reset latch bit $2002

; Cursor blink lda #$3F sta $2006 lda #$13 sta $2006 inc <blink1 cmp <blink1 bne noblink lda <blink2 eor #$1D sta $2007 sta <blink2 lda #$00 sta <blink1

; Scroll noblink	lda #$00 sta $2006 sta $2006 sta $2005 lda <scroll1 sta $2005

; OAM lda #$C0 sta $4014

; Enable rendering lda #$1E sta $2001

; Done pla rti

; Vectors org $FFFA dw nmi,reset,0

; Pattern table bank 2 org $0000

;0	defchr $00011100,\ $00100110,\	      $01100011,\	       $01100011,\	       $01100011,\	       $00110010,\	       $00011100,\	       $00000000

;1	defchr $00001100,\ $00011100,\	      $00001100,\	       $00001100,\	       $00001100,\	       $00001100,\	       $00111111,\	       $00000000

;2	defchr $00111110,\ $01100011,\	      $00000111,\	       $00011110,\	       $00111100,\	       $01110000,\	       $01111111,\	       $00000000

;3	defchr $00111111,\ $00000110,\	      $00001100,\	       $00011110,\	       $00000011,\	       $01100011,\	       $00111110,\	       $00000000

;4	defchr $00001110,\ $00011110,\	      $00110110,\	       $01100110,\	       $01111111,\	       $00000110,\	       $00000110,\	       $00000000

;5	defchr $01111110,\ $01100000,\	      $01111110,\	       $00000011,\	       $00000011,\	       $01100011,\	       $00111110,\	       $00000000

;6	defchr $00011110,\ $00110000,\	      $01100000,\	       $01111110,\	       $01100011,\	       $01100011,\	       $00111110,\	       $00000000

;7	defchr $01111111,\ $01100011,\	      $00000110,\	       $00001100,\	       $00011000,\	       $00011000,\	       $00011000,\	       $00000000

;8	defchr $00111100,\ $01100010,\	      $01110010,\	       $00111100,\	       $01001111,\	       $01000011,\	       $00111110,\	       $00000000

;9	defchr $00111110,\ $01100011,\	      $01100011,\	       $00111111,\	       $00000011,\	       $00000110,\	       $00111100,\	       $00000000

;>	defchr $00110000,\ $00011000,\	      $00001100,\	       $00000110,\	       $00001100,\	       $00011000,\	       $00110000,\	       $00000000

;I defchr $01111110,\ $00011000,\	      $00011000,\	       $00011000,\	       $00011000,\	       $00011000,\	       $01111110,\	       $00000000

;D defchr $01111100,\ $01100110,\	      $01100011,\	       $01100011,\	       $01100011,\	       $01100110,\	       $01111100,\	       $00000000

;S defchr $00111110,\ $01100011,\	      $01100000,\	       $00111110,\	       $00000011,\	       $01100011,\	       $00111110,\	       $00000000

;O defchr $00111110,\ $01100011,\	      $01100011,\	       $01100011,\	       $01100011,\	       $01100011,\	       $00111110,\	       $00000000

;blank defchr $22222222,\ $22222222,\	      $22222222,\	       $22222222,\	       $22222222,\	       $22222222,\	       $22222222,\	       $22222222

;cursor defchr $00000000,\ $00303030,\	      $00030300,\	       $00303030,\	       $00030300,\	       $00303030,\	       $00000000,\	       $00000000

var'aq
Notes:

Will only allow one command per line

Can only be stopped by killing the process

The way var'aq is currently implemented (interpreter-wise), any program using  will not run correctly unless the code is copied into the command-line directly

(* QopghotI' mughwI' var'aq *)

0 "toD" cher

~ QopghotI'mughwI' {

">> " cha'

'Ij "Doch" cher

Doch 0 1 tlheghpe' "Doch" cher

Doch "i" tlheghrap'a' { toD 1 boq "toD" cher } HIja'chugh

Doch "d" tlheghrap'a' { toD 1 boqHa' "toD" cher } HIja'chugh

Doch "o" tlheghrap'a' { toD cha' } HIja'chugh

Doch "s" tlheghrap'a' { toD toD boq'egh "toD" cher } HIja'chugh

toD -1 rap'a' { 0 "toD" cher } HIja'chugh

toD 256 rap'a' { 0 "toD" cher } HIja'chugh

QopghotI'mughwI'

} pong

QopghotI'mughwI'

Visual Basic .NET
Implementation by David Catt (User:David.werecat) which allows a program file to be specified as a command line parameter. Option Explicit On Option Strict On Module Deadfish Dim Val As Integer = 0 Sub Main Dim ProgCode As String = "" Try : ProgCode = My.Computer.FileSystem.ReadAllText(Command.Trim(""""c)) Catch : End Try For Each C As Char In ProgCode Interpret(C) Next While True Console.Write(">> ") : Interpret(Console.ReadKey.KeyChar) End While End Sub Sub Interpret(ByVal C As Char) Select Case C 			Case "d"c : Val -= 1 : Console.WriteLine Case "i"c : Val += 1 : Console.WriteLine Case "o"c : Console.WriteLine : Console.WriteLine(Val.ToString) Case "s"c : Val = Val ^ 2 : Console.WriteLine End Select If (Val < 0) Or (Val = 256) Then Val = 0 End Sub End Module

Vorpal
method { acc = 0 while (1 > 0) { input = '>> '.input if ((acc == 256) || (acc < 0)) { acc = 0 }        if (input == "i") { acc = acc + 1 } else { if (input == "d") { acc = acc - 1 } else { if (input == "s") { acc = acc * acc } else { if (input == "o") { acc.print }                }             }         }     } }

WARP
+A@s,l=li!:li:0?0?^.p%li@m}pc>pc1^_m|^.s@p=espc=pc0@r{pc=cc! :"i":cc?0?>xx1:"d":cc?0?<xx1:"s":cc?0?&xxxx:"o":cc?0?)xx :256:xx?0?=xx0:es:pc?0?^.e>pc1^.r@e

Whitespace
The first is with syntax highlighting, the second is a hexdump for recreating as the wiki software really can't cope.

<div style="border: 1px solid #ddd;padding:1em;background-color:#f9f9f9;font-family: monospace,Courier;">

000000: 20 20 20 20 0a 0a 20 20 09 0a 20 20 20 09 09 09      ␊␊  ␉␊   ␉␉␉ 000010: 09 09 20 0a 20 0a 20 09 0a 20 20 09 0a 20 20 20  ␉␉ ␊ ␊ ␉␊  ␉␊ 000020: 20 20 09 20 20 20 20 20 0a 09 0a 20 20 20 0a 20    ␉     ␊␉␊   ␊ 000030: 20 20 20 09 20 20 20 20 20 20 20 20 0a 09 20 20     ␉        ␊␉ 000040: 09 0a 09 20 09 20 0a 20 0a 20 20 20 09 09 0a 09  ␉␊␉ ␉ ␊ ␊   ␉␉␊␉ 000050: 20 20 09 0a 09 20 09 20 0a 0a 20 20 09 09 0a 20    ␉␊␉ ␉ ␊␊  ␉␉␊ 000060: 20 20 20 0a 09 0a 09 20 20 20 20 20 0a 09 09 09     ␊␉␊␉     ␊␉␉␉ 000070: 20 0a 20 20 20 20 09 09 20 09 20 20 09 0a 09 20   ␊    ␉␉ ␉  ␉␊␉ 000080: 20 09 0a 09 20 09 20 09 0a 20 0a 20 20 20 20 09   ␉␊␉ ␉ ␉␊ ␊    ␉ 000090: 09 20 20 09 20 20 0a 09 20 20 09 0a 09 20 09 09  ␉  ␉  ␊␉  ␉␊␉ ␉␉ 0000a0: 20 0a 20 0a 20 20 20 20 09 09 09 20 20 09 09 0a   ␊ ␊    ␉␉␉  ␉␉␊ 0000b0: 09 20 20 09 0a 09 20 09 09 09 0a 20 0a 20 20 20  ␉  ␉␊␉ ␉␉␉␊ ␊ 0000c0: 20 09 09 20 09 09 09 09 0a 09 20 20 09 0a 09 20   ␉␉ ␉␉␉␉␊␉  ␉␊␉ 0000d0: 09 20 20 20 0a 20 0a 0a 20 20 20 09 20 09 20 0a  ␉   ␊ ␊␊   ␉ ␉ ␊ 0000e0: 09 0a 20 20 0a 20 0a 09 0a 0a 20 20 09 20 0a 20  ␉␊  ␊ ␊␉␊␊  ␉ ␊ 0000f0: 0a 0a 20 20 20 20 0a 0a 20 0a 09 09 0a 0a 20 20  ␊␊    ␊␊ ␊␉␉␊␊ 000100: 09 20 09 0a 20 0a 0a 20 20 20 09 0a 09 20 20 20  ␉ ␉␊ ␊␊   ␉␊␉ 000110: 0a 20 0a 09 0a 0a 20 20 09 09 20 0a 20 0a 0a 20  ␊ ␊␉␊␊  ␉␉ ␊ ␊␊ 000120: 20 09 09 0a 09 20 20 20 0a 20 0a 09 0a 0a 20 20   ␉␉␊␉   ␊ ␊␉␊␊ 000130: 09 09 09 0a 20 0a 0a 20 0a 20 09 20 20 0a 0a 20  ␉␉␉␊ ␊␊ ␊ ␉  ␊␊ 000140: 0a 09 0a 0a 20 20 09 20 20 20 0a 20 0a 0a 20 0a  ␊␉␊␊  ␉   ␊ ␊␊ ␊ 000150: 20 09 0a 20 09 20 20 20 09 20 09 20 0a 09 0a 20   ␉␊ ␉   ␉ ␉ ␊␉␊ 000160: 20 0a 20 0a 09 0a 0a 0a 0a                        ␊ ␊␉␊␊␊␊

WTFZOMFG
'>> " _2 + (  _0 %4 _4 ~-256 | { _0 =0 } _3 > + > > ^ & > @i | { _0 + _3 } < & > @d | { _0 - _3 } < & > @s | { _0 & m _3 } <  & > @o | { _0 \ '\n" _3 } < & > ~-10 | { '>> " } < + )

ZiziQue
[Start] !i^inc"Increment !d^dec"Decrement !s^sqr"Square !o^out"Output . [out] "{number} ^Start [inc] +number ^Start [dec] -number ^Start [sqr] =number,{{number}*{number}} ^Start

Variants of deadfish

 * Deadfish i object oriented
 * Deadfish~ superset
 * FISHQ9+ — deadfish merged with HQ9+
 * Deadfish x — xkcd variant with extra commands
 * Print "deadfish" includes termination, and character printing.
 * Deadfish 2 is another superset.
 * Functional deadfish adds "functions"

External resources

 * (Note: The creator's webpage was added for more information about the creator of the language.)
 * Deadfish at Planet Source Code
 * Anarchy golf Deadfish challenge
 * Implementation of Deadfish in Nintendo Family Computer
 * Implementation on the Makey-Makey
 * Deadfish implementation for Pebble watches
 * Deadfish implementation for Pebble watches