Char a = 'x'; Char b = 'y'; system string char.out.println(a+b); 怎么输出的是一个数字

From Esolang
This is a .
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
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.
Standard Deadfish
XKCD variation
Sometimes, the additional command 'h', meaning halt, is used.
Although the comment in the C implementation states /* Make sure x is not greater then [sic] 256 */, the implementation sets the value to zero if and only if value == -1 || value == 256.
Deadfish started out as a subset of , as all it would do would
be to print out
and give an iou depending on how many times
the command 9 was entered for how many
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.
Note: the standard shell adds && characters for readability.
This program prints the ASCII values 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 couple of important test cases for people making interpreters:
The program
should print 0; while
should print 289.
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.
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
? ← '&& '
{ x ?← (~x??1 256) × x
??'ix': x ?← x + 1
x ?← x - 1
??'sk': x ?← x * 2
??'oc': ? ← x
EXECUTE(Deadfish)
It won't display the prompt, but other than that is complete.
sub(/o/,x=x*(x&0&&x-256)*x^/s/+/i/-/d/)
#!/bin/bash
((no==256||no&0)) && no=0
echo -n '&& ' # prompt
case $REPLY in
d) ((no--)) ;;
i) ((no++)) ;;
o) echo $no ;;
s) no=$((no*no)) ;;
*) : ;;
echo # on EOF
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".
set debug=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
Deadfish in Befunge
&0& &&&&:vv
_$:vv-*5+7*44
&#$&:375**-v
& $ #v-*:*25:_$1+
^#-*65-*99:_$1-
_$0~^ &:1+v
#1-#_1+:48:**
/* Deadfish in Boo */
# by Chris Pressey
// Hallowe'en 2012
while true:
if a & 0 or a == 256:
c = prompt("&& ")
if c == 's':
elif c == 'i':
elif c == 'd':
elif c == 'o':
Implementation by David Catt (), reads one line of input at a time (for compatibility with most brainfuck interpreters) and interprets only one instruction per line
&+[&++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..-------
-----------------------.[-]&&[-]+&,----------[-----------------------------
-------------------------------------------------------------[-----[------[
----[&-&[-]]&[&&&[-]&[-]&[-]&[-]&&&&[&+&+&+&&&-]&[&[&&+&&-]&[&+&-]&[&+&+&&-
]&&&-]&&&-]&]&[&&&[-]&[-]&[-]&[-]&[-]&[-]&&&&&&[-&+&&&&&+&[-]+&&&&---------
-[&&&&[&++++++++++&&-&&&-]&+&&&-]&&&[&&&+&&&-]&&+&&&[-]+&&&----------[&&&[&
++++++++++&-&&-]&+&&-]&&[&&+&&-]&+&&&]&&&&[-]&[-]&&[&+&&&&[-]++++++++++++++
++++++++++++++++++++++++++++++++++&&&[&&&+&&&-]&&&.&&&]&[&&&&[-]+++++++++++
+++++++++++++++++++++++++++++++++++++&&[&&+&&-]&&.&&&&-]&&[&&[-]+++++++++++
+++++++++++++++++++++++++++++++++++++&&[&&+&&-]&&.&&]&&[-]+++++++++++++++++
+++++++++++++++++++++++++++++++&[&+&-]&.[-]++++++++++.----------&&&&&&[&&&&
&&+&&&&&&-]&&&&&&&&-]&]&[&&+&&-]&]&[&&&[-]+&[-]&&[&[-]&+&&-]&&-[&&+&&-]&&&[
&+&-]&&&-]&]&[&-&-]&+[,----------]&&]
{?i ?d S[ J}j{{'i 'd 's 'o}jFi}m[si)bx{J{-1==}{256==}m|{256.%}if}IC0je!
/* &-- 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 --& */
/* make a positive integer and call it x */
/* string to hold user input */
/* &-- Declare a function --& */
void entercommand(void);
/* &-- Start Main Function --& */
int main(void)
/* At beginning of x is always 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')
entercommand();
else if(usrinput == 'd')
entercommand();
else if(usrinput == 'o')
printf(&%d\n&,x);
entercommand();
else if(usrinput == 's')
entercommand();
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)
usigned int x = 0;
while(1) {
printf(&&& &);
scanf(&%c&,&input);
if(x == 256 || x == -1)
switch(input) {
printf(&%d\n&,x);
printf(&\n&);
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();
while ((cmd = Console.Read()) != -1) {
char command = Convert.ToChar(cmd);
if (!Environment.NewLine.Contains(command)) {
x = x == 256 || x & 0 ? 0 :
(Commands.ContainsKey(command) ? Commands[command] : () =& Console.WriteLine())();
#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 &&
struct Nil {
static void print() {}
template &typename Ms, typename Ns& struct A
template &typename Ns&
struct Append&Nil, Ns& {
typedef Ns S
template &char m, typename Ms, typename Ns&
struct Append&Cons&m, Ms&, Ns& {
typedef Append&Ms, Ns& N
typedef Cons&m, typename Next::String& S
#define INS(name, expr) \
struct name { \
template &int n, typename Out& struct Result { \
static const int value = \
typedef Out O \
INS(i, n + 1);
INS(d, n - 1);
INS(s, n * n);
template &int n& struct DecimalL
template && struct DecimalLoop&0& {
typedef Nil S
template &int n& struct DecimalLoop {
typedef DecimalLoop&n / 10& N
typedef Cons&'0' + (n % 10), typename Next::String& S
template &int n& struct ToD
template && struct ToDecimal&0& {
typedef Cons&'\n', Cons&'0', Nil&& S
template &int n& struct ToDecimal {
typedef Cons&'\n', typename DecimalLoop&n&::String& S
struct o {
template &int n, typename Out& struct Result {
static const int value =
typedef typename Append&typename ToDecimal&n&::String, Out&::String O
template &int n& struct Wrap {
static const int value = n & 0 || n == 256 ? 0 :
template &typename... Is& struct S
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 O
template && struct Seq&& {
template &int n, typename Out& struct Result {
typedef Out O
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
import std.io.*
Int a = 0;
while (true) {
if (a & 0 || a == 256) {
io::print("&& ");
c = io::readln();
if (c == "s") {
} else if (c == "i") {
} else if (c == "d") {
} else if (c == "o") {
io::print(a);
io::print("\n");
identification division.
program-id. deadfish.
data division.
working-storage section.
usage binary-int unsigned.
77 deadfish
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&& 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
end program deadfish.
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
# 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.
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,
took it upon himself to visit the
and, while having coffee there, to implement
-- making that implementation as close as anyone's gotten so far to "implementing Deadfish in Deadfish".
Interprets a command per line.
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)
Cmp(@x,-1,@bool)
Cmp(@x,256,@bool)
if no==-1 or no==256
the_cmd = input()
switch the_cmd
\$\$256=\1_=&[%0]?\
$'i=[\1+\]?
$'d=[\1-\]?
$'s=[\$*\]?
include "std/textio";
open Text_
var a :
while {true}
write(stdout, "&& ");
a = if a == 256 or a & 0 then 0
match readln stdin with
| "i\n" =& { ++a; }
| "d\n" =& { --a; }
| "s\n" =& { a*=a; }
| "o\n" =& { }
This is the actual idso version, with the correct x==-1||x==256 behaviour.
Load zero in the register
The input loop, stopping on 13 (CR, enter press)
\:d=?!^~aor
We process in reverse order, that's why the 'r'
\&::&01-=$f1+:*=+?v
The x==0||x==256 -& x=0 thing
If done with input, output newline and return to input loop
If none of those, just remove it from input and run next
"&& "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'=|?\],._
\ Type 'h' to halt
DUP 256 = OVER -1 = OR IF DROP 0 THEN
'i' OF 1+ ENDOF
'd' OF 1- ENDOF
's' OF DUP * ENDOF
'o' OF DUP . ENDOF
'h' OF DROP EXIT ENDOF
c Deadfish interpreter in FORTRAN 77
PROGRAM DEADFISH
CHARACTER*1 inp
INTEGER state
WRITE(*,'(2A)', ADVANCE='no')&&&&
READ(*,*)inp
IF (state .EQ. 256 .OR. state .LT. 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
This hits some bugs in all the known Fueue interpreters.
Join it into a single line to run it in the C one.
)$$17--1[)$5~[)~[0]])$[[)[~~~~()+1])])]&&&[[
)~&[)$%+-~)~~~100[)[
)~+[~:~~~)(]-1)
)~&[)$%+-~)~~~105[)[
)~+[~:~~~)(]%0)
)~&[)$%+-~)~~~111[)[
):[)$$7--1[
)$3~[)$~!~~%~)]$2&[):]~:
)~~~[~)~$7~~:~~([$3~)+[~~~&~()+48]~~~-)~10*)]/]--10):
~[10 ~:)~]~:
)~&[)$%+-~)~~~115[)[
)~*~~:[~:~~~)(])
]!]:]:]:]:
62 62 32 )~&~[
)$%+%~)~~~0[[0]!]~
)$%+-~)~~~256[[0]!]~
{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.?]}
package main
func main() {
reader := bufio.NewReader(os.Stdin)
if x & 0 || x == 256 {
fmt.Print(&&& &)
input, _ := reader.ReadString('\n')
c := input[0]
switch c {
fmt.Println(x)
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&)
This interpreter is online ().
&!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&&
function deadfish()
var c=document.getElementById(&cmd&).
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;
&/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& /&
&/BODY&&/HTML&
Another one:
&!DOCTYPE html PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&head&&title&Deadfish in HTML&/title&&/head&
&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').
if(cmd=='i') acc++;
if(cmd=='d') acc--;
if(cmd=='s') acc *=
if(acc==256 || acc&0) acc=0;
if(cmd=='o') cmd+='&br/&'+
document.getElementById('out').innerHTML+=cmd+'&br/&&& ';
document.getElementById('cmd').value='';
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.
/*/()()()()()()()()()()()()()()()()/
/./&\\\\&\\\\\\/
./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./
This is a serious language that gets used in the finance industry, believe it or not.
getchar =: 'libc.so.6 getchar &c'&cd
=: (]*&&0*~:&256)@]
=: ][1!:2&4&'&& '@1:
=: 'idso', LF, 255{a.
=: (&:@])`(&:@])`(*:@])`(][echo@])`prompt`(exit@0:)
=: getchar&''@1:$:bounds@(cmdfns`]@.(cmds&i.@[))
// 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.S
public class Deadfish
public static void main(String args[])
Scanner comm = new Scanner(System.in);
boolean isSquared =
int x = 0;
while(true)
System.out.print(&&& &);
usrinput = comm.next();
if(usrinput.contentEquals(&i&))
if(x &= 256 && isSquared == false)
else if(usrinput.contentEquals(&d&))
if(x &= -1 && isSquared == false)
else if(usrinput.contentEquals(&o&))
System.out.println(x);
else if(usrinput.contentEquals(&s&))
if(x &= 256)
isSquared =
System.out.println();
An other one, compiling on JDK1.1 (just in case you have some reason to stay away from ORACLE).
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*=
if(acc==256 | acc&0) acc=0;
if(ch=='o') System.out.println(acc);
System.out.print(&&& &);
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)
function deadfish(compliance::Int)
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()
function deadfish(code::AbstractString)
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()
Example output of test strings for "true" deadfish overflow detection:
julia& include(&deadfish.jl&)
deadfish (generic function with 3 methods)
julia& deadfish(&iissso&)
julia& deadfish(&iissiso&)
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?)
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?)
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()
#!/usr/bin/env lci
BTW, This is a Deadfish interpreter in LOLCODE.
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 &&
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
EITHER OF BOTH SAEM x AN -1 AN BOTH SAEM x AN 256, O RLY?
YA RLY, x R 0
IM OUTTA YR reader
#!/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)
This is limited range due to limit of numbers in METAFONT.
warningcheck:=0;
def Z = if(Q&0)or(Q=256):Q:=0;
def i = Q:=Q+1;Z;
def d = Q:=Q-1;Z;
def s = Q:=Q*Q;Z;
def o = message decimal Q;
def h = ;
while true do
if no==-1 or no==256 then
print "&& "
the_cmd = System.console.readLine()
if the_cmd.equals("d") then
elsif the_cmd.equals("i") then
elsif the_cmd.equals("s") then
if the_cmd.equals("o") then
puts "#{no}"
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
while true:
if a == -1 or a == 256:
write(stdout, "&& ")
case readLine(stdin)
Implementation by David Catt (), interprets only one instruction per line.
GT3S3T0T0T0T0S0
#G~10~=KX}{#
"i"=!KX}S2MS0#
"d"=!KX}S2DS0#
"s"=!KX}S2T3S4~0~]#S3T0S0~0~=KX}S3DS2T0S4T0S0+T4{#S4T2S0#
"o"=!KX}S2NS0~10~P#
~256~=!KX}S2~0~S0#
~-1~=!KX}S2~0~S0#
class player {}
property int dummy
method check {
if value == -1 or value == 256 value = 0
method increment verbs {{i} {x}} {
value = value + 1
this check
method decrement verbs {{d}} {
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
['I'X]%#%#&UP&+&CHK
['D]%#%#&DN&+&CHK
['S'K]%#%#&%#&MUL&+&CHK
['O'C]%#&PI CR
[&CHK]%#&-1EQ/%#&256EQ/ RP:%#0&
Implementation by David Catt (), interprets only one instruction per line.
#include &stdio.h&
#define A case
#define B(x,y) A x:;y;R;
#define C "%c"
#define D(x) O(S,x);S(x)
#define E(x) O(while,x){
#define F(x,y,z) x(y,z);
#define G getchar()
#define H char
#define I "%i"
#define J main
#define K(x,y,z) x y z
#define L printf
#define M }}}}
#define N "\n"
#define O(x,y) x(y)
#define P(x) F(L,I N,x)
#define Q(x,y) K(x,=,y)
#define R break
#define S(x) F(L,C,x)
#define T(x) O(if,x){
#define U(x) O(switch,x){
#define V void
#define W int
#define X(x,y) x y
#define Y(x) K(x,!=,10)
#define Z(x) Q(x,0);
V J(){W Z(a)HE(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
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, "")
PROGRAM deadfish (INPUT, OUTPUT);
cmd: CHAR;
acc: INTEGER;
acc := 0;
WRITE(‘&&’);
READLN(cmd);
CASE cmd OF
‘i’ : acc := acc+1;
‘d’ : acc := acc-1;
‘s’ : acc := SQR(acc);
‘o’ : WRITELN(acc);
IF acc&0 THEN acc := 0;
IF acc=256 THEN acc := 0;
UNTIL cmd=‘h’;
#!/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*=$ }
else { print &\n&; }
fish a "i" = a+1;
fish a "d" = a-1;
fish a "s" = a*a;
fish a "o" = a when puts (str a)
limit a = if a == 256 || a & 0 then 0
main a = (printf "%s " "&&") $$ (main (fish (limit a) (gets)));
Deadfish Programming Language Interpreter
Programmed by Jonathan Todd Skinner
This code is hereby released into the public domain
Harry eased the mess
# Initialization
accumulator = 0
# Main program loop
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
print 'Unrecognized command.'
#!/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
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']:
elif char == 'd':
elif char in ['s', 'k']:
acc *= acc
elif char == 'h':
print('Long live the fish!')
sys.exit(0)
elif char == 'r':
if acc & 0 or acc == 256:
if strict:
raise DeadfishError('Overflow at char {} (Index {}) accumulator = {}'.format(char, i, acc))
if char in ['o', 'c']:
print(acc)
prog = None
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)
Note: Specification of RogueVM is still draft, so it might change.
%TITLE "Deadfish"
%INIT R0 :start
%INIT R1 0
%DYNSTR :in
JNE #:go R1 #256
MESG "&& "
INPUT #:in
STRCMP R2 #"i"
JEQ #:inc R2 #0
STRCMP R2 #"d"
JEQ #:dec R2 #0
STRCMP R2 #"s"
JEQ #:squ R2 #0
STRCMP R2 #"o"
JEQ #:out R2 #0
ADD0 R1 #1
LEG R2 #0 R1
ADD0 R1 R2
MUL0 R1 R1
MESG #"\[R1,0]\n"
#!/usr/bin/env ruby
while true
print '&& '
gets.chomp.each_char do |c|
n = 0 if [-1, 256].include?(n)
when 'd' then n -= 1
when 'i' then n += 1
when 'o' then puts n
when 's' then n *= n
use std::io::R
use std::io::W
fn main() {
let mut stdin = io::stdin();
let input = &mut String::new();
let mut acc: i64 = 0;
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}
{i=0;split-s&&|{i++if($(k=&i&));i-- if($(k=&d&));i*=i if($(k=&s&));print i if($(k=&o&));i=0 if($(i=-1||i=256))}for k}
(define (execute n cmd)
((#\i) (+ n 1))
((#\d) (- n 1))
((#\s) (* n n))
((#\o) (display n) (newline) n)
(else n)))
(define (deadfish n)
(let ((char (read-char)))
((or (= n -1) (= n 256)) (deadfish 0))
((eof-object? char) n)
(else (deadfish (execute n char))))))
(deadfish 0)
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
while keep_going do
if accumulator = 256 or accumulator & 0 then
accumulator := 0;
write("&& ");
readln(command);
case command[1] of
when {'s'}: 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");
A more awesome version of this implementation would use Seed7's ability to create new program structures.
#!/usr/bin/env slsh
variable l=" ", n=0,
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; }
Protip 1: if you do not do something with the result of fputs and fgets (assign them to the scratch variable r in this case), slsh eventually runs out of stack space.
Protip 2: the braces in the above program are not matched correctly.
slsh does not seem to care.
Takes a line from stdin and runs all characters in said line. Unrecognized commands print a newline. Commands are case-sensitive, lowercase. Implements h and proper x==0||x==256 behavior.
OPTION STRICT
'declare vars
'REPL loop
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
ELSEIF C$==&d& THEN
ELSEIF C$==&s& THEN
ELSEIF C$==&o& THEN
ELSEIF C$==&h& THEN
PRINT 'adds a newline
IF X%==-1||X%==256 THEN X%=0 'zero behavior
UNTIL C$==&h&
/@@@=@@@=++++# 100 = 5*5*4 = 'd'
$=!\&,+?!#-=&@/=!/?!\&?\&!/?\&&/
\&?\==!=== & -/
\ !/?!\&?\& /
\-&| -/  !
'o'/ ++++++&/
\ !/?!\&?\& /
\-&| -/  !
\ !/?!\&?\& /
/= square = & = /?&/
/======= & =!\ noop =!/==
\?!/&&+&&-?\&!/&-?/&&+&?!/&+&\
In order to use this program, another program (possibly written in C or some other programming language) must make the INPUT and OUTPUT 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;
CREATE TRIGGER `DECREMENT` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 'd' BEGIN
UPDATE `DEADFISH` SET `VALUE` = `VALUE` - 1 WHERE `VALUE` & 0;
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;
CREATE TRIGGER `OUTPUT` INSTEAD OF INSERT ON `INPUT` WHEN NEW.`INPUT` = 'o' BEGIN
INSERT INTO `OUTPUT` SELECT `VALUE` AS `OUTPUT` FROM `DEADFISH`;
0 "&& " dup while
dup print swap inputstr
dup "d" eq if swap
dup "i" eq if swap
dup "s" eq if swap dup * endif
dup "o" eq if swap dup tostring 10 char concat print endif
-1 eq if pop 0 endif
dup 256 eq if pop 0 endif
-3 roll pop
dup endwhile
[[R0;];||;!;+;1;!;-;256;
[+;1;];[[-;1;];[
[*;];[[10;];
[10;];==;"o;];==;"s;];==;"d;];==;"i;];R0;
&iiqqq&{o:&@X}{T-!@_x}{i_iT}{D_d}{d?DT}{sqT}{ks}{xi}{co}{&id}
Allows the command sets of both variations.
Reads one line of input.
M 0 (i /r f \
fn f .&+;h d ;t f \
fn f: .$ \
fn d:i .$&&I c && \
fn d:d .$&&D c && \
fn d:s .$&&&+* c && \
fn d:o .$&&&+@&& \
fn c:256 .$0(i \
fn c:-1 .$0(i \
% Deadfish interpreter in TeX
\catcode32=9\endlinechar=-1
\newcount\accumulator
\def\checkwrapping{
\ifnum\accumulator=256\accumulator=0\fi
\ifnum\accumulator=-1\accumulator=0\fi
\advance\accumulator by 1
\checkwrapping
\advance\accumulator by -1
\checkwrapping
\multiply\accumulator by \accumulator
\checkwrapping
\message{\the\accumulator}
\tracingonline=-1
\scrollmode
\def\Activate{
\catcode105=13
\catcode100=13
\catcode115=13
\catcode111=13
\catcode62=11
\def\Start{
\escapechar=-1
\read16 to \&&
\iftrue\repeat
To use this program, save it in the file called "deadfish.cards" and then type in "@I deadfish.cards" at the "E&" prompt. And then it change to "C&" prompt and it is ready for typing in commands of deadfish.
@. Deadfish implementation in TeXnicard.
[d[c0][]dixd256-[][0*][]ix[]]s0
(patterns)sP0
@P patterns
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/
deadfish(src)
left(src,1)-&cmd
If acc=256 or acc&0 Then
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
If dim(src)=1 or cmd=&h& Then
right(src,dim(src)-1)-&src
Disp &REGULAR DEADFISH&,&IDSO INTERPRETER
DelVar AInput Str1 //DelVar doesn't need a colon or newlin this is the same as &DelVar A:Input Str1&
For(B,1,length(Str1
sub(Str1,B,1
A(not(Ans=&S&)+A(Ans=&S&))+(Ans=&I&)-(Ans=&D
Ans(Ans&256 and Ans-&A
% 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
if accumulator = 256 or accumulator & 0 then
accumulator := 0
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
put &Unrecognized command.&
This implementation uses Church numerals, which are essentially unary.
Use large ones at your own risk.
``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``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
``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 ``s`kd ``si `k`k`ki
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 adde all keys other than "I", "D", "S" and "O" (including the DELETE and RETURN key) 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.)
; Deadfish implementation for Nintendo Famicom
inesprg 1 ; 16K PRG ROM
ineschr 1 ; 8K CHR ROM
inesmir 1 ; vertical mirroring
inesmap 0 ; NROM
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
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
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
; Initialize APU/PPU/CPU
bit $;; Clear VBL
vwait1 bit $2002
bpl vwait1
vwait2 bit $2002
bpl vwait2
stx $;; Disable PPU
; Initialize RAM
ldy #csrlin
initram stx &0,y
bpl initram
sta &scroll2
; Initialize palette
initpal sta $2007
bne initpal
; Clear screen
clrscr sta $2007
bne clrscr
; Display prompt
prompt ldx #$00
jsr newline
; Wait until all keys are not pushed
keywait lda #8
sta &csrlin
keyw1 stx $4016
bne keywait
bne keywait
dec &csrlin
; Read keyboard
keyloop ldy #$05
stx $;; Skip row 0
stx $;; Skip row 1
stx $;; Skip row 2
stx $;; Skip row 3
stx $;; Skip row 4
stx $;; Skip row 5
jmp keyloop
keyo lda #$0E
jsr letter
keyi lda #$0B
jsr letter
keyd lda #$0C
jsr letter
keys lda #$0D
jsr letter
cmdo jsr newline
sta &csrlin
out1 lda 0,y
out2 stx &csrlin
out3 eor &csrlin
jmp prompt
; Increment
cmdi stx &spare ; Clear guard digit
incr1 inc &0,x
bne chk256
chk256 ldx #0
incr2 lda &0,x
cmp eq256,x
bne incr3 ; It isn't &256&
incr3 jmp prompt
; Decrement
cmdd lda &0,x
jmp prompt ; It is already zero
decr1 ldx #$00
decr2 lda &0,x
jmp chk256 ; Now check if equal to 256
decr3 lda #9
cmds stx &spare ; Clear guard digit
squ1 stx &multacc,y ; Clear multiplication accumulator memory
squ2 ldx #7
squ3 lda &0,x
sta &csrlin
eor &csrlin
sty &csrlin
lda muones,y
sta &temp2 ; Ones digit
lda mutens,y
sta &temp4 ; Tens digit
stx &temp3
lda &csrlin ; Position of a digit
adc &temp3 ; Position of another digit
lda &temp2
adc multacc,y
sta multacc,y
lda &temp4
adc multacc+1,y
sta multacc+1,y
ldy &csrlin
; Now conversion into base ten proper digits
stx &temp2 ; Carry
squ4 lda &multacc,x
adc &temp2
lda adones,y
lda adtens,y
sta &temp2
jmp chk256 ; Check if equal to 256
; New line routine (expects X=0)
newline lda &scroll1
bne nscrz1
nscrz1 sta &scroll1
lda &scroll2
bne nscrz2
nscrz2 sta &scroll2
sty &csrlin
rol &csrlin
rol &csrlin
ldy &csrlin
; Write letter to screen (A=letter to write)
letter pha
lda &scroll2
jsr nscrz2
; NMI handler
; Reset latch
; Cursor blink
inc &blink1
cmp &blink1
bne noblink
lda &blink2
sta &blink2
sta &blink1
noblink lda #$00
lda &scroll1
; Enable rendering
dw nmi,reset,0
; Pattern table
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
defchr $,\
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 'lj 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'
QopghotI'mughwI'
Implementation by David Catt () 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)
While True
Console.Write("&& ") : Interpret(Console.ReadKey.KeyChar)
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 Module
method() {
while (1 & 0) {
input = '&& '.input()
if ((acc == 256) || (acc & 0)) {
if (input == "i") {
acc = acc + 1
if (input == "d") {
acc = acc - 1
if (input == "s") {
acc = acc * acc
if (input == "o") {
acc.print()
+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
The first is with syntax highlighting, the second is a hexdump for recreating as the wiki software really can't cope.
    
   
         
  
   
           
   
             
    
    
     
    
    
    
    
      
    
           
    
     
           
    
     
           
    
     
           
    
      
       
  
    
    
  
     
    
    
     
    
    
     
    
      
  
         
  
20 20 20 0a 0a 20 20
09 0a 20 20 20 09 09 09
09 20 0a 20 0a 20 09
0a 20 20 09 0a 20 20 20
HTHT LF LF HTLF
20 09 20 20 20 20 20
0a 09 0a 20 20 20 0a 20
20 20 09 20 20 20 20
20 20 20 20 0a 09 20 20
0a 09 20 09 20 0a 20
0a 20 20 20 09 09 0a 09
HTLFHT HT LF LF
20 09 0a 09 20 09 20
0a 0a 20 20 09 09 0a 20
HTLFHT HT LFLF
20 20 0a 09 0a 09 20
20 20 20 20 0a 09 09 09
0a 20 20 20 20 09 09
20 09 20 20 09 0a 09 20
09 0a 09 20 09 20 09
0a 20 0a 20 20 20 20 09
HTLFHT HT HTLF LF
20 20 09 20 20 0a 09
20 20 09 0a 09 20 09 09
HTLFHT HTHT
0a 20 0a 20 20 20 20
09 09 09 20 20 09 09 0a
20 20 09 0a 09 20 09
09 09 0a 20 0a 20 20 20
HTLFHT HTHTHTLF LF
09 09 20 09 09 09 09
0a 09 20 20 09 0a 09 20
HTHT HTHTHTHTLFHT
20 20 20 0a 20 0a 0a
20 20 20 09 20 09 20 0a
0a 20 20 0a 20 0a 09
0a 0a 20 20 09 20 0a 20
LF LFHTLFLF
a 0a 20 20 20 20 0a 0a
20 0a 09 09 0a 0a 20 20
LFLF LFHTHTLFLF
20 09 0a 20 0a 0a 20
20 20 09 0a 09 20 20 20
HT HTLF LFLF
a 20 0a 09 0a 0a 20 20
09 09 20 0a 20 0a 0a 20
LF LFHTLFLF
HTHT LF LFLF
09 09 0a 09 20 20 20
0a 20 0a 09 0a 0a 20 20
LF LFHTLFLF
09 09 0a 20 0a 0a 20
0a 20 09 20 20 0a 0a 20
HTHTHTLF LFLF LF HT
a 09 0a 0a 20 20 09 20
20 20 0a 20 0a 0a 20 0a
LF LFLF LF
09 0a 20 09 20 20 20
09 20 09 20 0a 09 0a 20
HT HT LFHTLF
0a 20 0a 09 0a 0a 0a
LF LFHTLFLFLFLF
_0 %4 _4 ~-256 | { _0 =0 } _3
& & @i | { _0 + _3 } &
& & @d | { _0 - _3 } &
& & @s | { _0 & m _3 } &
& & @o | { _0 \ '\n" _3 } &
& & ~-10 | { '&& " } &
!i^inc"Increment
!d^dec"Decrement
!s^sqr"Square
!o^out"Output
=number,{{number}*{number}}
- Shortest ways to produce numbers in the range 0 to 255.
( retrieved on 8 February 2011) (Note: The creator's webpage was added for more information about the creator of the language.)
This is an implementation of Deadfish for the Commodore 64 ()

我要回帖

更多关于 system string char 的文章

 

随机推荐