Deadfish/Implementations (nonalphabetic and A-L)
← Back to Deadfish#Implementations
Deadfish has been implemented in lots of different languages, both practical and esoteric. This page lists the first part. The next part is at: Deadfish/Implementations (M-Z)
Юᓂ곧⎔
Implementation in the non-ASCII language Юᓂ곧⎔. Accepts the standard `idso` inputs.
⌂ «» ☹ ❝Δις Юᓂ곧⎔ κοδε μπασεδ ον α Δεαδφις Ϲ ιντερπρετερ μπι Ασδφ κονβερτεδ αντ τεστεδ μπι Σάλπιγξ❞ ℤ 事 ← ☰। писать «“⁌☷☶⁍⁌☷☶⁍”»। ∀«।।» ☹ ቁምፊ 工। 工← получатзнак «»। ¿ «事⇔᠒᠕᠖∨事⇔−☱» 事←☰। ¿ «工⇔‘⁌☱☵☱⁍’» ∆事। ¬¿«工⇔‘⁌☱☴☴⁍’» ∇事। ¬¿«工⇔‘⁌☱☵☷⁍’» писать «“﹪ℤ␊” ¦ 事»। ¬¿«工⇔‘⁌☱☶☳⁍’» 事×←事। ¬писать «“⁌☷☶⁍⁌☷☶⁍”»। ☺ ☺
ثلاثي
ﻮﻨﻴﺳﺎﻃ ﺭﺩ ﺫ ﻦﺴﻃﺮﺤﻃﺫ ﻲﺼﻃ ﺎﻧﺎﺴﻃ ﻮﻃﺎﺳﺎﻃ ﺎﻘﻃﺭ ﻖﻘﻗ ﻲﻘﻃﺭ ﺎﻃﻮﺴﻃ ﺎﻄﻴﺴﻃ ﻞﻃ ﻁ ﻑ ﻲﺼﻃ ﺎﻧﺎﺴﻃ ﺎﻘﻃﺭ ﻖﺒﺟ ﻲﻘﻃﺭ ﻲﺻﺎﻃ ﺎﻄﻴﺴﻃ ﺩﺍﺩﺎﻓ ﻑ ﻦﺴﻃﺮﺤﻃﺫ ﻖﻠﺳ ﺲﺳ ﻦﺣﺮﻤﻨﻃ ﻁ ﺢﺤﻤﻠﻃﺭ ﻲﺼﻃ ﺎﻧﺎﺴﻃ ﺎﻘﻃﺭ ﻕ ﻲﻘﻃﺭ ﻲﺻﺎﻃ ﺎﻄﻴﺴﻃ ﺍﺩﺍﺩﺎﻓ ﻑ ﻦﺴﻃﺮﺤﻃﺫ ﻖﻠﺳ ﺱﺪﺳ ﺪﺣﺮﻤﻨﻃ ﻁ ﺢﺤﻤﻠﻃﺭ ﻲﺼﻃ ﺎﻧﺎﺴﻃ ﺎﻘﻃﺭ ﻖﻴﺒﺟ ﻲﻘﻃﺭ ﻲﺻﺎﻃ ﺎﻄﻴﺴﻃ ﺍﺩﻭﺪﻓ ﻑ ﻦﺴﻃﺮﺤﻃﺫ ﻖﻠﺳ ﺲﺴﺳ ﺲﻗﺭ ﻁ ﺢﺤﻤﻠﻃﺭ ﻲﺼﻃ ﺎﻧﺎﺴﻃ ﺎﻘﻃﺭ ﺎﻘﻳ ﻲﻘﻃﺭ ﻲﺻﺎﻃ ﺎﻄﻴﺴﻃ ﻱﺩﻭﺩﺎﻓ ﻑ ﻦﺴﻃﺮﺤﻃﺫ ﻖﻠﺳ ﺲﺳ ﻂﻔﻃ ﻁ ﺢﺤﻤﻠﻃﺭ ﻲﺼﻃ ﺍﺩﺍﺪﻓ ﺎﻘﻃﺭ ﻮﻧﺭ ﻲﻘﻃﺭ ﻲﺻﺎﻃ ﺎﻄﻴﺴﻃ ﻭﺩﺪﻓ ﻑ ﺢﺤﻤﻠﻃﺭ ﻖﻠﺳ ﺲﻃ ﺢﺤﻤﻠﻃﺭ ﻁ ﺯﺭ ﻭﺰﻳﺯﺯ ﻢﺿ ﺐﺤﺛ ﻁ ﺲﻃﺮﻃ
One- sixth of the line is dripping. It is dripping. It's dripping. It's dripping . Speechless regurgitation in the line -- Google Translate
The Fourth Imam's Biography The Fourth Commandment of the Prophet (s.a.w.a.) -- Microsoft Translate
תלת
וניסאט רד ן נסטרחטן יצט אנאסט וטאסאט אקטר קקק יקטר אטוסט אטיסט לט ט פ יצט אנאסט אקטר קבג יקטר יצאט אטיסט דאדאפ פ נסטרחטן קלס סס נחרמנט ט חחמלטר יצט אנאסט אקטר ק יקטר יצאט אטיסט אדאדאפ פ נסטרחטן קלס סדס דחרמנט ט חחמלטר יצט אנאסט אקטר קיבג יקטר יצאט אטיסט אדודפ פ נסטרחטן קלס ססס סקר ט חחמלטר יצט אנאסט אקטר אקי יקטר יצאט אטיסט ידודאפ פ נסטרחטן קלס סס טפט ט חחמלטר יצט אדאדפ אקטר ונר יקטר יצאט אטיסט ודדפ פ חחמלטר קלס סט חחמלטר ט זר וזיזז מף בחך ט סטרט
Venisat Red n Nestrechten Ycet Anast and Tasat Akter Kekk Yakter Adust Agust Lat T P Ycet Anast Ekter Kabeg Yaktar Yitzat Await Dadap P Nester Kells Ses Nehrment T Hakhmelter Ycet Anast Akter K Yaktar YitSat Ativist Adadap P Nestrechten Kels Seds Dekhment T Hakhmelter Ycet Anast Akter Kibag Yaktar Yitzat Atypist Adudef P Nestrechten Kells Sesses Saker T Hakhmelter Ycet Anast Akter Aki Yaktar Yitset Aetist Yedodap P Nasterkhten Kels Ses Teft T Hachamlater Ycet Addep Akter Venner Yakter Yitzat Aetist Vaddef P Hakhmelter Kels Set Khamtar T Stranger and Moved Mf Bakhtar T Strat -- Microsoft Translate
(script())
let n is ( prompt ) let a is ( throw 0 ) if n is i ( let n is ( n + 1 ) ) orif n is d ( let n is ( n - 1 ) ) orif n is s ( let n is ( n * n ) ) orif n is o ( throw (n) catch ) if a is 0 or a is 256 ( variable a is ( throw 0 ) )
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
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Containers.Indefinite_Holders; with Ada.Integer_Text_IO; procedure Deadfish is package String_Holder is new Ada.Containers.Indefinite_Holders(String); use String_Holder; value_output : Natural := 0; str_input : String_Holder.Holder := To_Holder(""); begin Prompt : loop Put(">> "); String_Holder.Replace_Element(str_input, Get_Line); for rg in str_input.Element'Range loop case str_input.Element(rg) is when 'i' | 'x' => case value_output is when 255 => value_output := 0; when others => value_output := Natural'Succ(value_output); end case; when 'd' => case value_output is when 257 => value_output := 0; when 0 => null; when others => value_output := Natural'Pred(value_output); end case; when 's' | 'k' => case value_output is when 16 => value_output := 0; when others =>value_output := value_output * value_output; end case; when 'o' | 'c' => Ada.Integer_Text_IO.Put(value_output, Width => 0); Put_Line(""); when others => null; end case; end loop; end loop Prompt; end Deadfish;
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)
ARMLite
Maximum program length is 128 due to ARMLite restrictions.
; We can't use 256 as an immediate in ARMLite, nor -1. ; so we will use custom constants instead. mov r10, #1 sub r11, r11, r10 ; r11 = -1 lsl r10, r10, #8 ; r10 = 256 ; Enter string mov r12, #program str r12, .ReadString ; loop through the program, reading loop: ; load r1'th char from beginning ldrb r2, [r12 + r1] ; if r2 is null, end instantly cmp r2, #0 cmp r2, # 104 ; h beq interpret_h cmp r2, #105 ; i beq interpret_i cmp r2, #100 ; d beq interpret_d cmp r2, #115 ; s beq interpret_s cmp r2, #111 ; o beq interpret_o end_loop: add r1, r1, #1 b loop interpret_h: halt interpret_i: ; add r0 to 1. If R0 == 256, make R0 zero. add r0, r0, #1 b check_zero interpret_d: sub r0, r0, #1 b check_zero interpret_s: ; armlite has no 'mul'... mov r3, r0 mov r4, #0 mul_loop: add r4, r4, r0 sub r3, r3, #1 cmp r3, #0 bgt mul_loop mov r0, r4 b check_zero interpret_o: str r0, .WriteUnsignedNum b check_zero check_zero: ;set r0 to zero after operation cmp r0, r10 beq set_zero cmp r0, r11 beq set_zero b end_loop set_zero: mov r0, #0 b end_loop program: .block 128
A Slow Language
r0:rI~rd x _^"i"d d=:r1+:rd d^ l r"d"d d=:r1-:rd d^ l r"s"d d=:r^*:rd d l r"o"d d=:r^o:rd d l l O r:r^F1+^*d A d-10^=0:rvd v dr:=0:rvd u l l l
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 langs
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/)
BASE
ASSIGN a TO 0 WHILE TRUE ASSIGN u TO USER CHECK IF u IS i IF YES THEN ASSIGN a TO SUM a PLU 1 END CHECK IF u IS d IF YES THEN ASSIGN a TO SUM a MIN 1 END CHECK IF u IS s IF YES THEN ASSIGN a TO SUM a TIM a END CHECK IF u IS o IF YES THEN PRINT var:a END CHECK IF a IS 256 OR -1 IF YES THEN ASSIGN a TO 0 END
Bash
#!/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
GNU bc
/*Bc does not support character I/O. Here is an alternate mapping: *0:i *1:d *2:s *3:o */ ac=0 while(1) { if(ac==-1)ac=0 if(ac==256)ac=0 print ">> " a=read() if(a==0)ac+=1 else if(a==1)ac-=1 else if(a==2)ac*=ac else if(a==3)print ac } quit
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:**
Befunge-98
0v ^;#+1$< ;;#-1$< ;;#*:$< ;.:$< >>#@~:'i-!#^_:'d-!#^_:'s-!#^_:'o-!#^_ ^ > :f1+:*-!#v_:01--!#v_ ^ 0$< <
Boo
/* Deadfish in Boo */ # by Chris Pressey // 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)
Brainfuck
Implementation by User:David.werecat, reads one line of input at a time (for compatibility with most brainfuck interpreters) and interprets only one instruction per line
>+[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..------- -----------------------.[-]>>[-]+>,----------[----------------------------- -------------------------------------------------------------[-----[------[ ----[<->[-]]<[>>>[-]>[-]>[-]>[-]<<<<[>+>+>+<<<-]>[>[<<+>>-]>[>+<-]>[<+<+>>- ]<<<-]<<<-]>]<[>>>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<[->+>>>>>+<[-]+<<<<--------- -[>>>>[<++++++++++<<->>>-]<+<<<-]>>>[<<<+>>>-]<<+>>>[-]+<<<----------[>>>[< ++++++++++<->>-]<+<<-]>>[<<+>>-]<+<<<]>>>>[-]>[-]<<[>+<<<<[-]++++++++++++++ ++++++++++++++++++++++++++++++++++>>>[<<<+>>>-]<<<.>>>]>[<<<<[-]+++++++++++ +++++++++++++++++++++++++++++++++++++>>[<<+>>-]<<.>>>>-]<<[<<[-]+++++++++++ +++++++++++++++++++++++++++++++++++++>>[<<+>>-]<<.>>]<<[-]+++++++++++++++++ +++++++++++++++++++++++++++++++>[<+>-]<.[-]++++++++++.---------->>>>>>[<<<< <<+>>>>>>-]<<<<<<<<-]>]<[>>+<<-]>]<[>>>[-]+>[-]<<[>[-]>+<<-]>>-[<<+>>-]<<>[ <+>-]<<<-]>]<[>-<-]>+[,----------]<<]
Implementation by User:None1 and generated by BFFuck, it has an interactive shell and interprets only one instruction per line, but it runs on 8 bit cells with wrapping
>>>>>>>>>>>>>>>[-]>+[<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]>>>,>,>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>+<<[-]]>>>>>>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>-<<[-]]>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>>>>>>[-]<<<<<[>>>>>+<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>[-]<[-]>>[<<+>>-]<<[>>>>>>>[<<<<<+<+>>>>>>-]<<<<<<[>>>>>>+<<<<<<-]<-][-]]>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>[<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>+>-]<<<<<<<<<<<<<++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<[-]>>>>>>>>>>>>>>[>+<-][-]++++++++++.[-]<[-]]>>>]
A shorter alternative compiled with a higher version of BFFuck.
>>>>>>>>>>>>>>>[-]>+[<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++++++++++++++++++++++++++++++.[-]>>>,>,>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>+<<[-]]>>>>>>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>-<<[-]]>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>>>>>>[-]<<<<<[>>>>>+<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<[>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>[-]<[-]>>[<<+>>-]<<[>>>>>>>[<<<<<+<+>>>>>>-]<<<<<<[>>>>>>+<<<<<<-]<-][-]]>>>>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<<<[-]<[-]>>>>>>[<<<<<<+>>>>>>-]+<<[<<<<->+>>>-]<<<[>>>+<<<-]<[>>>>>>-<<<<<<[-]]>[-]<[-]>>>>>>[<<<<<+<+>>>>>>-]<<<<<[>>>>>+<<<<<-]<[>>[<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>+>-]<<<<<<<<<<<<<<[-]>[-]+>[-]+<[>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[-]>[-]<<<<<[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++[-<++++++>]>>[-<<+>>]<<]<[.[-]<]<[-]>>>>>>>>>>>>>>[>+<-][-]++++++++++.[-]<[-]]>>>]
Buffalo!
This is a full implementation when run under the Python interpreter (which has unbounded integers). Output of large numbers (beyond about 1000) is quite slow, since exponentiation, multiplication, division and even addition have to be implemented from scratch using unary increment/decrement, but it gets there in the end. Characters other than 'i', 'd', 's' and 'o' have arbitrary interpretation.
Unfortunately it's too large to include on the page, but it's here: [1]
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 */ #include <stdio.h> /* <-- 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 [sic] 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 --> */ #include <stdio.h> 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; } } }
There is a horribly short interpreter (I won't add ">>", since it wastes a lot of code):
/* <-- By:Asdf --> */ #include<stdio.h> int main(){ int x=0; for(;;){ char i; i=getchar(); if(x==256||x==-1)x=0; if(i=='i')++x; else if(i=='d')--x; else if(i=='o')printf("%d\n",x); else if(i=='s')x*=x; else printf("\n"); } }
Unfortunately, many inplementers use input. It would be a lot shorter if it is predefined:
/* <-- By:Asdf --> */ #include<stdio.h> int main(){ int ptr=0, x=0; char c[10000]="";//Code goes here for(;c[ptr]!='\0';++ptr){ if(x==256||x<0)x=0; if(c[ptr]=='i')++x; else if(c[ptr]=='d')--x; else if(c[ptr]=='o')printf("%d\n",x); else if(c[ptr]=='s')x*=x; else printf("\n"); } }
Also, the most horrible (but short) interpreter (spaghetti code):
#include <stdio.h> //By: Positron int main(){int x=0,i;a:i=getchar();if(x==256||x==-1)x=0;if(i=='i')++x;else if(i=='d')--x;else if(i=='o')printf("%d\n",x);else if(i=='s')x*=x;else putchar(10);goto a;}
or in a more readable way:
/*By: Positron*/ #include <stdio.h> int main() { int x=0,i; a: i=getchar(); if(x==256||x==-1) x=0; if(i=='i') ++x; else if(i=='d') --x; else if(i=='o') printf("%d\n",x); else if(i=='s') x*=x; else putchar(10); goto a; }
Here's a slightly shorter (yet very unreadable) interpreter:
/* By: Presauced */ #include<stdio.h>main(){int x=0,i;for(;;){ i=getchar();if(x==256||x==-1)x=0;if(i=='i') ++x;else if(i=='d')--x;else if(i=='o')printf( "%d\n",x);else if(i=='s')x*=x;else puts("\n");}}
With only for loops:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { for(argv[0] = (char *)malloc(16); 0; 0); for(argv[0][0] = 1; argv[0][0] < 15; argv[0][argv[0][0]] = 0, argv[0][0]++); for(0; argv[0][0] != 'h' && ((signed char *)(argv[0]))[0] != -1; printf(">> "), ((signed char *)(argv[0]))[0] = getc(stdin), printf("\n")){ for(0; argv[0][0] == 'i'; *((int *)(argv[0] + 1)) += 1, argv[0][0] = 0); for(0; argv[0][0] == 'd'; *((int *)(argv[0] + 1)) -= 1, argv[0][0] = 0); for(0; argv[0][0] == 's'; *((int *)(argv[0] + 1)) *= *((int *)(argv[0] + 1)), argv[0][0] = 0); for(0; argv[0][0] == 'o'; printf("%d\n", *((int *)(argv[0] + 1))), argv[0][0] = 0); for(0; *((int *)(argv[0] + 1)) == -1 || *((int *)(argv[0] + 1)) == 256; *((int *)(argv[0] + 1)) = 0); } for(free(argv[0]); 0; 0); }
C#
public class Deadfish { private static int x = 0; private static Dictionary<char, Action> Commands = new Dictionary<char, Action> { { '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(); } } } }
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(); } } }
Here is a large C# implementation written in only one statement by BoundedBeans. It's possibly a bit too large for this page.
C++ Codegolfed
//By: Areallycoolusername // Supports one-liners #include <iostream> using namespace std; int main() { int acc = 0; char a; do { std::cout << ">> "; std::cin >> a; if(a=='i') { acc++; } if(a=='d') { acc--; } if(a=='s') { acc *= acc; } if(a=='o') { std::cout << acc << endl; } if(acc<0||acc==256) { acc = 0; } } while(a!='h'); return 69; //For the lols }
Another implementation, based on the previous implementation:
// Implementation by Tsuki #include<iostream> int main(){int ac=0;char a;do{std::cout<<">>";std::cin>>a;switch(a){case'i':ac++;break;case'd':ac--;break;case's':ac*=ac;break;case'o':std::cout<<ac<<'\n';break;}if(ac<0||ac==256){ac=0;}}while(a!='q');return 0;}
C++ templates
#include <iostream> // #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 <char n, typename Ns> struct Cons { static void print() { Ns::print(); std::cout << n; } }; struct Nil { static void print() {} }; template <typename Ms, typename Ns> struct Append; template <typename Ns> struct Append<Nil, Ns> { typedef Ns String; }; template <char m, typename Ms, typename Ns> struct Append<Cons<m, Ms>, Ns> { typedef Append<Ms, Ns> Next; typedef Cons<m, typename Next::String> String; }; #define INS(name, expr) \ struct name { \ template <int n, typename Out> struct Result { \ static const int value = expr; \ typedef Out Output; \ }; \ } INS(i, n + 1); INS(d, n - 1); INS(s, n * n); template <int n> struct DecimalLoop; template <> struct DecimalLoop<0> { typedef Nil String; }; template <int n> struct DecimalLoop { typedef DecimalLoop<n / 10> Next; typedef Cons<'0' + (n % 10), typename Next::String> String; }; template <int n> struct ToDecimal; template <> struct ToDecimal<0> { typedef Cons<'\n', Cons<'0', Nil>> String; }; template <int n> struct ToDecimal { typedef Cons<'\n', typename DecimalLoop<n>::String> String; }; struct o { template <int n, typename Out> struct Result { static const int value = n; typedef typename Append<typename ToDecimal<n>::String, Out>::String Output; }; }; template <int n> 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(); }
Castile
Runs under (at least) Castile 0.3. Does not accept more than one command per line.
fun main() { a = 0; c = ""; while true { if a == 256 or a < 0 { a = 0; } c = input(">> "); if c == "i" { a = a + 1; } else if c == "d" { a = a - 1; } else if c == "s" { a = a * a; } else if c == "o" { print(str(a)); } } }
CLFCE
Technically this program is 9 lines long
compile 1-10 a(0) loop( c(input(">")) if(c="i") then(a=a+1) elseif(c="d") then(a=a-1) elseif(c="s") then(a=a*a) elseif(c="o") then(therm(a)) if(a=256) then(a=0) elseif(a=-1) then(a=0) )
Chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
C-INTERCAL
PLEASE NOTE Written by oshaboy DO ,1 <- #1024 DO WRITE IN ,1 DO .3 <- #0 PLEASE NOTE .20 is index DO .20 <- #1 DO NOTE :10 is the accumulator PLEASE :10 <- #0 DO COME FROM (40) PLEASE NOTE Check if EOF PLEASE .6 <- ',1 SUB .20'~#256 PLEASE ABSTAIN .6 FROM COMING FROM (60) DO NOTHING PLEASE (20) NEXT DO COME FROM (60) PLEASE REINSTATE COMING FROM DO NOTE This loads the next char into .3 PLEASE REINSTATE NEXTING DO .1 <- .3 DO .2 <- ,1 SUB .20 PLEASE (1009) NEXT PLEASE NOTE This removes capitalization and makes the code MUCH shorter DO .5 <- .3~#31 PLEASE ABSTAIN .5 FROM NEXTING PLEASE (20) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING PLEASE (31) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING PLEASE (32) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING PLEASE (33) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING PLEASE (34) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO REINSTATE NEXTING DO (44) NEXT DO COME FROM (51) DO COME FROM (52) DO COME FROM (53) DO COME FROM (54) (44) DO FORGET #1 DO .1 <- .20 PLEASE (1020) NEXT PLEASE .20 <- .1 PLEASE NOTE Check if greater then[sic] 256 DO :1 <- :10 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 DO :1 <- :&1 PLEASE :1 <- :1~#1 PLEASE ABSTAIN :1 FROM COMING FROM (46) DO NOTHING DO (35) NEXT PLEASE REINSTATE COMING FROM PLEASE COME FROM (46) PLEASE :1 <- :10~#256 PLEASE ABSTAIN :1 FROM COMING FROM (47) DO NOTHING PLEASE REINSTATE COMING FROM DO :1 <- :10~'#65535$#65519' DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 DO :1 <- :V1 PLEASE :1 <- :1~#1 PLEASE ABSTAIN :1 FROM NEXTING PLEASE (35) NEXT PLEASE REINSTATE NEXTING PLEASE COME FROM (47) (40) PLEASE DO NOTHING (20) PLEASE GIVE UP (31) PLEASE :1 <- :10 PLEASE :2 <- #1 DO (1510) NEXT (51) PLEASE :10 <- :3 (32) PLEASE :1 <- :10 PLEASE :2 <- #1 DO (1509) NEXT (52) PLEASE :10 <- :3 (33) PLEASE READ OUT :10 (53) DO NOTHING (34) PLEASE :1 <- :10 PLEASE :2 <- :10 DO (1549) NEXT (54) PLEASE :10 <- :3 (35) PLEASE :10 <- #0 PLEASE RESUME #1
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.
;;; The deadfish macro expects a string as its argument. (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))
This version prompts the user for an input and responds to invalid characters with a newline.
(let ((accumulator 0)) (declare (type integer accumulator)) (loop with input of-type (or null string) = NIL do (format T "~&>> ") (setf input (read-line)) (clear-input) (when input (loop for token of-type character across input do (when (or (= accumulator -1) (= accumulator 256)) (setf accumulator 0)) (case token (#\i (incf accumulator)) (#\d (decf accumulator)) (#\o (write accumulator)) (#\s (setf accumulator (* accumulator accumulator))) ((#\Newline #\Space #\Tab) NIL) (otherwise (terpri)))))))
CraftyFunge
Cthulhu
0A *]A 1A i 2A i[6A 3A e2AdE2A[6A 4A e2AE2BE4Be8AE3B[0B[6A 5A e2Ao[0A 6A e2Aiiiiiiii]A 7A E2A[0A 8A [0A 264A E2A[0A 265A [0A 0B e4B]C 0C e3BE2A 1C e4BdE4Be2BE5B[1B[0B 1B e5B]D 0D i 1D e5BdE5Be3BiE3B[1B
Note that since there is no character input in Cthulhu, input is supplied as numbers - 1 is end, 2 is i, 3 is d, 4 is s and 5 is o.
dc
# Implements XKCD variation of Deadfish. [p]1:z[d*]2:z[1+]3:z[1-]4:z[0sB]dsAx[lB0>AlB256=A0d?lBz;zxsBclCx]dsCx
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, in order to come as close as possible to "implementing Deadfish in Deadfish".
Deadfish "self-interpreter"
This is very close to a Deadfish self-interpreter.
a:i:d:s:oj
Deadfish++
Please enter 1 character at a time. Supports both idso and xkcd. h to halt.
[u~a;f(a=i):i;f(a=x):i;f(a=d):d;f(a=s):s;f(a=k):s;f(a=o):o;f(a=c):o;f(a=h):h;]
Difficult
thing.keyword.while true[ thing.keyword.if (n eq 256)or(n ls 0)[n=0?] n=thing.console.input(">> ")? thing.keyword.switch n[ thing.keyword.wheneq "d"[ n--? ] thing.keyword.wheneq "i"[ n++? ] thing.keyword.wheneq "o"[ thing.console.print("*(n)")? ] thing.keyword.wheneq "s"[ n=n^2? ] ] ]
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 }
Easyfuck
This program takes in the code character by character and executes it after encountering a "carriage return" character:
i(#increment bi-cell +`(<+>) #check if number is 0b00000001 00000000 (256) -`(<--`(0-->0-<)++>)+ #check if number is 0b11111111 11111111 (-1) <$>>!<$>&>0--------<[}`(>+<)]>-`(<<0<0>>>)0<0<< ) d(#decrement bi-cell -`(<->) #check if number is 0b00000001 00000000 (256) -`(<--`(0-->0-<)++>)+ #check if number is 0b11111111 11111111 (-1) <$>>!<$>&>--------<[}`(>+<)]>-`(0<0<0<0>>>)<<< ) l(#left-rotate bi-cell <{>{`(<+>) ) a(#add bi-cell to one to the left $0<<=`(<+>)>$0<<=> ) o(#print int at bi-cell, then a space OS2.S ) r(#copy bi-cell to the right <$>>!<$>>! ) s(#square bi-cell r$<<M>$>Mlllllllla #check if number is 0b00000001 00000000 (256) -`(<--`(0-->0-<)++>)+ ) <>0>0>0>0>0>1---$0 #alloc memory and set storage to 13 >,.^[^>,.^]^---. #take input until 13 (enter on windows), then output new line [#main loop J>>>>>>>>>>S0+S #go past memory and set storage to 1 S[S>`X-``(S0S)+S]S$0J! #go through code until nonzero encountered, take to storage and turn into zero >^-`(>>>>>iJ$>)+^ #compare against i and if equal, increment >^-`(>>>>dJ$>>)+^ #compare against d and if equal, decrement >^-`(>>>sJ$>>>)+^ #compare against s and if equal, square >^-`(>>oJ$>>>>)+^ #compare against o and if equal, output ] #structure: 0[stdin]1-4[chars i d s o]5-10[3 memory bi-cells]11+[deadfish program] @ idso
Here is a minified version:
i(+`(<+>)-`(<--`(0-->0-<)++>)+<$>>!<$>&> 0--------<[}`(>+<)]>-`(<<0<0>>>)0<0<<)d( -`(<->)-`(<--`(0-->0-<)++>)+<$>>!<$>&>-- ------<[}`(>+<)]>-`(0<0<0<0>>>)<<<)l(<{> {`(<+>))a($0<<=`(<+>)>$0<<=>)o(OS2.S)r(< $>>!<$>>!)s(r$<<M>$>Mlllllllla-`(<--`(0- ->0-<)++>)+)<>0>0>0>0>0>1---$0>,.^[^>,.^ ]^---.[J>>>>>>>>>>S0+SS[S>`X-``(S0S)+S]S $0J!>^-`(>>>>>iJ$>)+^>^-`(>>>>dJ$>>)+^>^ -`(>>>sJ$>>>)+^>^-`(>>oJ$>>>>)+^]@ idso
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; };
><>
This is the actual idso
version, with the correct x==-1||x==256
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
Fishing
v+CC[vCCCCCCCC?!CCCCCCCCCC?!CCCCCCCCCCCCCCCCC?!CCCCCC?!CCCCCC?!CCCCCC?!CCCCCCD_ n{D E`-1`n} = {E`256`n} = { E`>>`PEI{E`i`}= {E`d`}= {E`s`}= {E`o`}= {{N}} D D _DDDDDDDDDDD] D D D D D D < D D D D D D D < < < < D D EC }C }C }C }C D D `C iC dC SC NC D D 0C {C {C {C {C D D `C D D D D D D nC D D D D D D {C D D D D D |DDDDDDDDD]DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD]DDDDDDD]DDDDDDD]DDDDDDD]DDDDDDDD]
FlinnScrip
while(0=nil){ input(1);//this does not output ">>" because flinnscript does not support prepends and appends in inputs. if(1="i"||1="x"){add(2,1);}; if(1="d"){add(2,-1);}; if(1="s"||1="k"){multiply(2,var(2));}; if(1="o"||1="c"){print(2);}; if(2=256||2=-1){set(2,0);}; };
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
Free Hero Mesh
; Of course, it is not possible to win this game. (Control Player Input ('I %x 1 + =%x) ('D %x 1 - =%x) ('S %x %x * =%x) ('O %x PopUp) (BEGIN_TURN %x -1 eq %x 256 eq lor if 0 =%x then) )
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]!]~ ]:]~ ]
Office VBA
Sub Deadfish() Dim Code As String Dim i As Integer Dim v As String Dim Accumulator As Integer Code = InputBox("Deadfish code?", "Deadfish") Accumulator = 0 For i = 1 To Len(Code) v = Mid(Code, i, 1) Select Case v Case "i" Accumulator = Accumulator + 1 Case "d" Accumulator = Accumulator - 1 Case "s" Accumulator = Accumulator * Accumulator Case "o" MsgBox (Accumulator) End Select If Accumulator = 256 Or Accumulator = -1 Then Accumulator = 0 End If Next End Sub
G#
ticker assign a as 0 boolean assign l as 1 make main; [ print("Deag#ish",\n) loop if ?l is 1 [ for c in input [ if c is "i" [ add 1 to +a ] if c is "d" [ add -1 to +a ] if c is "s" [ add +a to +a ] if c is "o" [ print(+a) ] ] ] ]
gar
> < + ^ { ?? >>>>>>>>>> : * | + ] ~ ) [ <<<<< + ]] ~ )) [[ <<<<<< + ]]] ~ ))) [[[ <<<< + ]]]] ~ )))) [[[[ ~~ ))))) ( ~~ ^^ < + ^ ~~ ))))) (( ~~ ^^ > + ^ ~~ ))))) ((( ~~ ^^ ! } (((( ~~ ^^ : * ^ ~ ((((( ~~ > ^^ + ]]]]] > < + ^ [[[[[ ~~ >>>> : : : * * * | ^^ + ]]]]]] > < + ^ [[[[[[ ~~ }
Glass
{M[moO!iI!aA!sS!n<0>=c<1>=/cc<1>ie.?as.?=ec*=/e">> "oo.?fil.?=gf *sl.?=hg*=l<-1>n*ae.?<256>n*ae.?aa.?=/ln<0>=l<0>=\/hjf*g*h*as.?s 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.?]}
Glulx
<!include ":glulx" <!include ":glk" !stack 256 :Prompt !string ">> " !main 3 ; Check if Glk supported; quit if not gestalt gs.IOSystem,2,$ jz $,0 ; Open window !pushr 0,0,0,glk.wintype_TextBuffer,0 glk glk_window_open,5,$2 jz $2,0 push $2 glk glk_set_window,1,0 setiosys 2,0 ; Main loop ; Check if number is -1 or 256 0h jne $0,-1,1f 2h copy 0,$0 1h jeq $0,256,2b ; Prompt and get input streamstr Prompt !pushr $2,Buf,1,0 glk glk_request_line_event,4,0 1h push Event glk glk_select,1,0 jne @Etype,glk.evtype_LineInput,1b jz @Eval1,0b ; Execute operation copyb @Buf,$1 jeq $1,'i',I jeq $1,'d',D jeq $1,'s',S jeq $1,'o',O jump 0b ; Increment :I add $0,1,$0 jump 0b ; Decrement :D sub $0,1,$0 jump 0b ; Square :S mul $0,$0,$0 jump 0b ; Output :O streamnum $0 streamchar 10 jump 0b !bss :Event !allot 16 :Etype !is Event :Ewin !is Event+4 :Eval1 !is Event+8 :Eval2 !is Event+12 :Buf !allot 8
Go
package main import ( "os" "fmt" "bufio" ) func main() { reader := bufio.NewReader(os.Stdin) var x int for { fmt.Print(">> ") input, err := reader.ReadString('\n') if err != nil { return } for _, c := range input { switch c { case 's': x = x * x case 'i': x++ case 'd': x-- case 'o': fmt.Println(x) } if x < 0 || x == 256 { x = 0 } } } }
GotoScript
# Variables 1 x := 0 2 new_x := "" # Reset accumulator on under/overflow 3 GOTO 1 IF x < 0 | x = 256 # Get input 4 GOTO INPUT '>> ' CATCH 5 # Invalid input 5 PRINT 'Invalid command.' # Increment 'i' new_x := x + 1 # Decrement 'd' new_x := x - 1 # Square 's' new_x := x * x # Output 'o' PRINT x 6 GOTO 4 # Loop back 7 GOTO 2 WHEN new_x != ""
Gray Snail
Instead of squaring numbers above 31, it just returns 0. Instead of increasing above 999, it goes to 0. However, you can reach 999, as 999 is regarded as separate from -1 (it checks whether 999 was obtained by increment or decrement).
POP a number a000 POP a "show number" a POP a carry a0 POP a newline a" " POP a "all input" a">>" "input more commands" OUTPUT "[all input]" INPUT commands "analyse commands" OUTPUT "[all input]" POP instruction commands [commands] GOTO "input more commands" [instruction] "" POP a temp a[number] POP hundreds temp [temp] POP tens temp [temp] POP ones temp [temp] GOTO "o command" [instruction] o GOTO "s command" [instruction] s GOTO "di command" [instruction] d GOTO "di command" [instruction] i POP a "all input" a"[all input][instruction][newline]>>" GOTO "analyse commands" "o command" GOTO "skip hundreds" [hundreds] 0 POP a "all input" a"[all input]o[newline][number][newline]>>" GOTO "analyse commands" "skip hundreds" GOTO "skip tens" [tens] 0 POP a "all input" a"[all input]o[newline][tens][ones][newline]>>" GOTO "analyse commands" "skip tens" POP a "all input" a"[all input]o[newline][ones][newline]>>" GOTO "analyse commands" "s command" POP a "all input" a"[all input]s[newline]>>" GOTO "square 0[ones]" [number] 00[ones] GOTO "square 1[ones]" [number] 01[ones] GOTO "square 2[ones]" [number] 02[ones] GOTO "square 30" [number] 030 GOTO "square 31" [number] 031 GOTO "to 000" "di command" POP a "all input" a"[all input][instruction][newline]>>" POP a digit aones GOTO "[instruction] [ones]" "finished with one operation" GOTO "completely finished" [carry] 0 GOTO "completely finished" [digit] hundreds "#This is in case we have just changed tens, so we have to change hundreds." GOTO "digit is tens" [digit] tens POP a digit atens GOTO "[instruction] [tens]" "digit is tens" POP a digit ahundreds GOTO "[instruction] [hundreds]" "completely finished" GOTO "to 000" [hundreds][tens][ones] 256 GOTO "to 000" [instruction][hundreds][tens][ones] d999 POP a number a[hundreds][tens][ones] "number is changed" POP a carry a0 GOTO "analyse commands" "to 000" POP a number a000 GOTO "number is changed" "d 0" POP a [digit] a9 POP a carry a1 GOTO "finished with one operation" "d 1" POP a [digit] a0 POP a carry a0 GOTO "finished with one operation" "d 2" POP a [digit] a1 POP a carry a0 GOTO "finished with one operation" "d 3" POP a [digit] a2 POP a carry a0 GOTO "finished with one operation" "d 4" POP a [digit] a3 POP a carry a0 GOTO "finished with one operation" "d 5" POP a [digit] a4 POP a carry a0 GOTO "finished with one operation" "d 6" POP a [digit] a5 POP a carry a0 GOTO "finished with one operation" "d 7" POP a [digit] a6 POP a carry a0 GOTO "finished with one operation" "d 8" POP a [digit] a7 POP a carry a0 GOTO "finished with one operation" "d 9" POP a [digit] a8 POP a carry a0 GOTO "finished with one operation" "i 0" POP a [digit] a1 POP a carry a0 GOTO "finished with one operation" "i 1" POP a [digit] a2 POP a carry a0 GOTO "finished with one operation" "i 2" POP a [digit] a3 POP a carry a0 GOTO "finished with one operation" "i 3" POP a [digit] a4 POP a carry a0 GOTO "finished with one operation" "i 4" POP a [digit] a5 POP a carry a0 GOTO "finished with one operation" "i 5" POP a [digit] a6 POP a carry a0 GOTO "finished with one operation" "i 6" POP a [digit] a7 POP a carry a0 GOTO "finished with one operation" "i 7" POP a [digit] a8 POP a carry a0 GOTO "finished with one operation" "i 8" POP a [digit] a9 POP a carry a0 GOTO "finished with one operation" "i 9" POP a [digit] a0 POP a carry a1 GOTO "finished with one operation" "square 00" POP a number a000 GOTO "analyse commands" "square 01" POP a number a001 GOTO "analyse commands" "square 02" POP a number a004 GOTO "analyse commands" "square 03" POP a number a009 GOTO "analyse commands" "square 04" POP a number a016 GOTO "analyse commands" "square 05" POP a number a025 GOTO "analyse commands" "square 06" POP a number a036 GOTO "analyse commands" "square 07" POP a number a049 GOTO "analyse commands" "square 08" POP a number a064 GOTO "analyse commands" "square 09" POP a number a081 GOTO "analyse commands" "square 10" POP a number a100 GOTO "analyse commands" "square 11" POP a number a121 GOTO "analyse commands" "square 12" POP a number a144 GOTO "analyse commands" "square 13" POP a number a169 GOTO "analyse commands" "square 14" POP a number a196 GOTO "analyse commands" "square 15" POP a number a225 GOTO "analyse commands" "square 16" GOTO "to 000" "square 17" POP a number a289 GOTO "analyse commands" "square 18" POP a number a324 GOTO "analyse commands" "square 19" POP a number a361 GOTO "analyse commands" "square 20" POP a number a400 GOTO "analyse commands" "square 21" POP a number a441 GOTO "analyse commands" "square 22" POP a number a484 GOTO "analyse commands" "square 23" POP a number a529 GOTO "analyse commands" "square 24" POP a number a576 GOTO "analyse commands" "square 25" POP a number a625 GOTO "analyse commands" "square 26" POP a number a676 GOTO "analyse commands" "square 27" POP a number a729 GOTO "analyse commands" "square 28" POP a number a784 GOTO "analyse commands" "square 29" POP a number a841 GOTO "analyse commands" "square 30" POP a number a900 GOTO "analyse commands" "square 31" POP a number a961 GOTO "analyse commands" end
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")
Hot Soup Processor
; Deadfish in Hot Soup Processor (ver3.51), version 1 -- dnm 2021-06-04 accumulator = 0 command = "" exitbtn="EXIT" onexit goto *exit onkey goto *interpret objsize 600,24 mes "Deadfish Interpreter" mes "Enter command:" input command button exitbtn,*exit *loopreset stop *interpret if accumulator = 256 | accumulator < 0 : accumulator = 0 if iparam=73 : accumulator = accumulator + 1 if iparam=68 : accumulator = accumulator - 1 if iparam=83 : accumulator = accumulator * accumulator if iparam=79 : mes accumulator goto *loopreset *exit end
hsifdaeD
,idso
This terminates when you enter something that is not i, d, s or o.
HTML / Javascript
This interpreter is archived online (from the Wayback Machine; retrieved on 23 September 2012).
<!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+= ">> &#"+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> <DIV id="op"></DIV> <FORM onsubmit="return deadfish()"> >> <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"> <html> <head><title>Deadfish in HTML</title></head> <body> <h1><a href="http://esolangs.org/wiki/Deadfish"<a>Deadfish in HTML</a></h1> <span id="out">>> </span> <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+='<br/>'+acc; document.getElementById('out').innerHTML+=cmd+'<br/>>> '; document.getElementById('cmd').value=''; } </script> </body> </html>
A shorter(and programmer friendly)one(I made it print every value after entering every command just for easier debugging).
<span id="out"></span> <input id="cmd" type="text" onkeypress="d();"/> <script>var a=0; function d(){ var c=document.getElementById('cmd').value; if(c=='i')a++; if(c=='d')a--; if(c=='s')a*=a; c+=' key pressed, the accumulator becomes '+a; if(a==256||a<0)a=0; document.getElementById('out').innerHTML+=c+'. <br/>'; document.getElementById('cmd').value=''; }</script>
Html/Javascript Simplified
<!DOCTYPE html> <html> <head><title>Deadfish Interpreter</title></head> <body> <script> var acc = 0; do { var a = prompt(">> "); if(a=='i') acc++; if(a=='d') acc--; if(a=='s') acc *= acc; if(a=='o') console.log(acc); if(acc<0||acc==256) acc = 0; } while(a!='h'); </script> </body> </html>
ICI
Quick and dirty, has an obvious bug I need to fix...
// Deadfish in ICI (4.1.0), version 1 -- dnm 2022-02-17 static accumulator = 0; // BUG: each trip through the loop, e.g., via (each) break, prints anew (">> ") // i.e., n command(s) submitted per line will print n prompt(s) // Hitting ENTER at a prompt (i.e., no [other] input) will print just one ">> " while (1) { if (accumulator == 256 || accumulator < 0) { accumulator = 0; } printf(">> "); command := getchar(); switch (command) { case "i": ++accumulator; break; case "d": --accumulator; break; case "s": accumulator = accumulator * accumulator; break; case "o": printf("%i\n", accumulator); break; } }
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
ΙΧΘΥΣ
Non-Latin Deadfish superset that can redefine itself to `idso` Deadfish
ΙiιΘΙdχΘΙsθΘΙoυΘΧ
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
Here is a one line "incantation" by User:BoundedBeans. In J, one line is one expression, so everything here is in one expression as well. You can get past that limitation by using the LF constant inside of an explicit verb (or using control words inside of one), but I explicitly avoided this (although I did use explicit definitions as verbs). Originally this was going to be a script, but I also thought I wanted to remove all whitespace, and specifically one verb :
doesn't work if you remove the whitespace around it (and a ton of other methods failed as well). What I settled on was dynamically loading the script from a string which all question marks are replaced with spaces, but none occur literally. To run this, either you can type it into the J shell, or it sort of works on tio.run (example here). Either way, you'll have to run Deadfish 0
after you run the incantation (it merely loads the Deadfish function; immediately calling it in the same line doesn't work for some reason).
It only accepts one command per line, and will crash if you try entering more, none, or any invalid command.
Anyway, here is the program:
(0!:101)((u:11$32)((11,17,47,62,95,131,155,183,208,245,301)})'Deadfish=:3?:''((3?:''''(((256=0{y)+.(_1=0{y)){((3?:''''''''y'''''''')`(3?:''''''''0(0})y'''''''')))(`:6)y'''')&:((3?:''''(((''''''''idsoh''''''''i.((1!:1)1)){((3?:''''''''(1+0{y)0}y'''''''')`(3?:''''''''y(0})~(_1+0{y)'''''''')`(3?:''''''''y(0})~*:0{y'''''''')`(3?:''''''''>(1{((":0{y)(1!:2)2);y)'''''''')`(3?:''''''''y(1})~(_1+1{y)'''''''')))(`:6))(y(1})~(1+1{y))'''')&:((3?:''''>1{((''''''''>>''''''''(1!:2)2);y)'''')))^:_)0,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
Another 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(">> "); } } }
Yet another one, now in JDK 11
import java.util.Scanner; public class Deadfish{ public static void main(String[] args){ int x = 0; String code; while(true){ System.out.print("\n>> "); code = input.nextLine(); for(int i = 0; i < code.length; ++i){ if(x == -1 || x == 256) x = 0; switch(code.charAt(i)){ case 'i': ++x; break; case 'd': --x; break; case 's': x *= x; break; case 'o': System.out.print("\n"+x); break; case 'h': return; } } } } }
Might as well add another one to the mix
import java.util.Scanner; public class Main { public static void main(String[] args) { int acc = 0; Scanner input = new Scanner(System.in); String program = input.nextLine(); for (char command : program.toCharArray()) { if (acc == -1 || acc == 256) { acc = 0;} switch (command) { case 'i': acc++; break; case 'd': acc--; break; case 's': acc *= acc; break; case 'o': System.out.print(acc); break; } } } }
JavaScript
Exports a function, import it with
import { deadfish } from "./path/to/deadfish.js"
and use it with
deadfish(/*code string/*, /*ascii output (boolean)*/)
export function deadfish (code, ascii) { let a = 0 let x = [] if (typeof(code) === "string") { let c = code.split("") for (let i = 0; i < code.length; i++) { switch (c[i]) { case 'i': a++ break case 'd': a-- break case 's': a *= a break case 'o': x.push(a) break default: break } if (a == 256 || a < 0) { a = 0 } } } if (ascii === true) { return String.fromCharCode.apply(null, x) } else { return x } }
JavaScript (very short)
A very concise JS implementation by User:Nomad. I believe it is fully compliant.
(Had a fun time golfing to achieve this - JS has some pretty crazy quirks)
Save in a file, and call with deadfish code as command line parameter:
Ex:
node interpreter.js iissso
(c => [0,...c.split('')].forEach((v,i,a) => i < 1 ? null : ((a[0] = a[0] === 256 || a[0] === -1 ? 0 : a[0]), a[0] += (v === 'i' ? 1 : v === 'd' ? -1 : v === 's' ? (a[0]**2)-a[0] : (0, console.log(v === 'o' ? a[0] : '')))) ))(process.argv.slice(2)[0] || '')
JSFuck
The JScrewIt conversion of the compact JavaScript interpreter is ridiculously long (25106 bytes), so LZMA is used to compress it into only 828 bytes. As such, you get a Python program that prints the original program:
print(__import__('lzma').decompress(__import__('base64').b64decode('/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4GIRAvpdAC2XR6W7ezTpsthqBJMKlkHoj8hJp+R43Focgp9KAYHFUPucb1pSwRhO1GTNk7zE1kn936LaGZRkeTMCvYZ4G7a8HWDS6KHrWnoyAu7PHoQjUMKNruiE1bLBJ5XImddkaGwLwEsKn/BYpFl7Y9uU6jvQ2LmrZmOSR6GMNuTVQK65ClfJmRzWJiN9VWSV0grhLqiMojiYUr9OUH+h3ID47kG893AVtfXmn+l9ML85StAkMaZIynW7GmKtAMqgF7oRgcmvH4iCzCek6rw+HnKFb8U2szz/JXgPpeH3dHcFQqtCYyDMpCWIk91h9JKyDOq66SDDHaIOhjDprK7LpjOsZNfCtI3f9MBvU6UlDoudvZ84vyiyVS3GTDC9vbZlFEUx0hG8hodyxSlnf/ysf41qmPtA7zF9HCTrh4GvMyeXXaLjo55RIJ9jtgZbEiJPMDJ/4PYJVPaP5wVJB/4+uYsNNzaf9Joq2YRqRYjJ4F72HBxAGz4jcEmT9Pru+ULiQ8ow2bObGbfYW+mbe5ROz41lzMWYiVIPIWFmw4F0WqlBGWi7NOYpcrL6+5W1NPcKvPwGLvLCFm4Gbv2LLTyzca4d0YRhJMz3asWvto6fRYjxgR74P7DkuATd/Hwgw0xuewy0oYL6Tnq3O4dMHi8sQKh8vooVWE+YshQkMcEcYfFIBfyFKGWyAgoocXSVIkCEcYWFWhl+ycecADuVBpsGjD8FisnlvMsTXmO3iZ9RdM3nHAmNNfcC2e46uhEkWMHsWgP8HhDegij7OBP3FnH2bcJcO6K2cAnzSevz6R1WY4QecQGK46XWRlCSzL+pa5wSem50Ve76uAFOQ3FCUyWth/00qSzmlgjZBrrRnb+hi3B6Gi6ssBvqS0K6ZCuwm6i+vkUldX31MwFZHYwE+omRHi59JpsXgcF9JTJF4d4qtzwliYZUp4t9VuTLtpKKl5jbS9SmEjE65Ga7hYSzAsuXHlIbFCdRULw2nMjssvuC1DcVZZeXtcwa1FEj4jd7hQAAAIMHXgQRwg6JAAGWBpLEAQDR8t4fscRn+wIAAAAABFla')).decode())
The flags used in JScrewIt make the program support all node versions.
Julia
Using multiple dispatch to implement several versions for user convenience.
# Deadfish implementation in Julia # Run fully compliant version (infinite input/output loop): # deadfish() or deadfish(0) # Run version that exits when entering 'h': # deadfish(1) # Run version that simulates manual input and # appropriate output, given the input string as a whole: # deadfish("input string") function deadfish() #= Run fully compliant version of deadfish if no parameters are given =# deadfish(0) end 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
K
{1">>";0{x*2=-1 256?x:y@x}/("xkcdiso"!7#(1+;{x*x};{-1@$x;x};-1+))@0:0;.z.s`}`
Keg
0{'::"ÿ1+=$0<+['_0"] \>\>\ ,,,,?:o=[':."]:i=['1+"]:d=['1-"]:s=[':*"
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
- Compact version :
$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
- "Clean" version :
$"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
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
#!/usr/bin/env lci BTW, This is a Deadfish interpreter in LOLCODE. 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
#!/usr/bin/env lua local acc = 0 io.write(">> ") while true do local c = io.read(1) if not c then break end if c == 'i' then acc = acc + 1 elseif c == 'd' then acc = acc - 1 elseif c == 's' then acc = acc*acc elseif c == 'o' then io.write(tostring(acc)) io.write('\n') elseif c == 'h' then break elseif c == 'r' then acc = 0 elseif c == '\n' then io.write(">> ") else io.write('\n') end if acc == 256 or acc == -1 then acc = 0 end end