We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Skull

From Esolang
Jump to navigation Jump to search

Skull is an esoteric programming language designed by Emil Svensson (User:fr34k). The name comes from the sketch the author had drawn next to the language draft.


Commands

Note that the commands have been whitespaced to increase readability

Command Function
{ x [ y ] } Increment or decrement the specified cell (x) by the specified number (y)
{ x { While the specified cell (x) is not 0...
} } End while
| x | Print out the specified cell (x) to the screen
:ASC: / :NUM: Set the mode to ASCII or NUM (number)

Examples

Hello, world!

:ASC:     // set mode to ASCII (without this code the program would just output every cell as a number)
{0[+72]}   // set cell 0 to the ASCII value 72 (H)
{1[+101]}  // set cell 1 to the ASCII value 101(e)
{2[+108]}  // set cell 2 to the ASCII value 108(l)
{3[+111]}  // set cell 3 to the ASCII value 111(o)
{4[+32]}   // set cell 4 to the ASCII value 32 (space)
{5[+87]}   // set cell 5 to the ASCII value 87 (W)
{6[+114]}  // set cell 6 to the ASCII value 114(r)
{7[+100]}  // set cell 7 to the ASCII value 100(d)
{8[+33]}   // set cell 8 to the ASCII value 33 (!)
{9[+10]}   // set cell 9 to the ASCII value 10 (newline)
|0|       // H
|1|       // e
|2|       // l
|2|       // l
|3|       // o
|4|       // 
|5|       // W
|3|       // o
|6|       // r
|2|       // l
|7|       // d
|8|       // !
|9|       // newline

Without row breaks and comments

:ASC:{0[+72]}{1[+101]}{2[+108]}{3[+111]}{4[+32]}{5[+87]}{6[+114]}{7[+100]}{8[+33]}{9[+10]}|0||1||2||2||3||4||5||3||6||2||7||8||9|

Addition

This is a simple program doing addition (4+2)

:NUM:       // set mode to NUM
{0[+4]}      // set cell 0 to 4
{1[+2]}      // set cell 1 to 2
{0{         // while cell 0 is not 0
  {0[-1]}   // subtract cell 0 by 1
  {1[+1]}   // add 1 to cell 1
}}          // end while
|1|         // print cell 1 (6)

Without row breaks and comments

:NUM:{0[+4]}{1[+2]}{0{{0[-1]}{1[+1]}}}|1|

Another addition programming, displaying + and = symbols by changing the mode between ASC and NUM

:NUM:       // set mode to NUM
{0[+7]}      // set cell 0 to 7
{1[+3]}      // set cell 1 to 3

{2[+43]}     // set cell 2 to 43
{3[+61]}     // set cell 3 to 61
|0|         // print cell 0
:ASC:
|2|         // print cell 2 (+)
:NUM:
|1|         // print cell 1
{0{         // while cell 0 is not 0
  {0[-1]}   // subtract cell 0 by 1
  {1[+1]}   // add 1 to cell 1
}}          // end while
:ASC:
|3|         // print cell 3 (=)
:NUM:
|1|         // print cell 1 (10)

The above program would output

7+3=10

Implementation

Skull2C

This Perl script compiles completely correct Skull into C.

#!/bin/perl -w

use strict;
$|=1;
$/=undef;

while(<>)
{
    my $maxe=1;
    s/\/\/.*$//g;
    s/\{([0-9]+)\[([0-9]+)\]\}/scalar(($1>=$maxe and $maxe=$1+1),"c[$1]=$2;")/ge;
    s/\{([0-9]+)\[\+([0-9]+)\]\}/scalar(($1>=$maxe and $maxe=$1+1),"c[$1]+=$2;")/ge;
    s/\{([0-9]+)\[\-([0-9]+)\]\}/scalar(($1>=$maxe and $maxe=$1+1),"c[$1]-=$2;")/ge;
    s/\{([0-9]+)\{/scalar(($1>=$maxe and $maxe=$1+1),"while(c[$1]){")/ge;
    s/\|([0-9]+)\|/scalar(($1>=$maxe and $maxe=$1+1),"ofunc(c[$1]);")/ge;
    s/:ASC:/ofunc=putchar;/g;
    s/:NUM:/ofunc=putnum;/g;
    s/\}\}/\}/g;
    print "#include <stdio.h>\nint putnum(int x){return printf(\"\%d\",x);}\n";
    print "int main(void)\n{\nint (*ofunc)(int)=putchar;\nint c[$maxe];\n$_\nreturn 0;\n}\n";
}

Sofa Skull

Sofa Skull should work flawlessly with Skull programs

Computational class

Skull is Turing complete, as it is easy to compile a Minsky machine into a Skull program.