Skull+

From Esolang
(Redirected from Skull plus)
Jump to: navigation, search

Skull+ is a Skull-derivative with added support for input and subroutines. It was created by Magnus Holm (User:Judofyr) and is almost backward compatible with regular Skull (shouldn't be hard to support both languages). The language is in active development and the spec listed here may change (but will always work in Sofa Skull). If someone else is also building a Skull+-interpreter/compiler contact me and I'll move any new experimental features to the discussion-page before changing this one.

Language overview[edit]

Registers[edit]

Skull+ uses two registers: one for cells (contains positive integers; read & write) and one for subroutines (contains code; write & execute). The cell-register defaults to 0 and uses 255 wrap (so -1 would equal 255).

IO[edit]

IO supports two IO-modes: NUM and ASC.

{0[83]}    // Set cell 0 to 83
:NUM:      // Change to NUM-mode
<0>        // Will print out "83"
:ASC:      // Change to ASC-mode
<0>        // Will print out "S"


:NUM:      // Change to NUM-mode
>0<        // Read char into cell 0
           // If you give it "8", the cell will contain 8
           // .............. "S", ..................... 0
:ASC:      // Change to ASC-mode
>0<        // Read char into cell 0
           // If you give it "8", the cell will contain 56
           // .............. "S", ..................... 83

EOF[edit]

When EOF occurs, it should give you 0 (you won't be able to get EOF in NUM-mode).

Commands[edit]

Command Function
{x[y]} Sets the specified cell (x) by the specified number (y)
{x[+y]} Increment the specified cell (x) by the specified number (y)
{x[-y]} Decrement the specified cell (x) by the specified number (y)
{x->y} Appends the value in cell x to cell y
<x> Output the character at cell (x) to the screen (based on the mode)
|x| Same as <x>, but only needed if you want to support Skull.
>x< Input the character at cell x (based on the mode)
:ASC: / :NUM: Set the mode to ASCII or NUM (number)
{x{code}} While the specified cell (x) is not 0, run code.
{x(code)} Puts the code in subroutine x
!x! Runs subroutine x
!x?y! Runs subroutine x if cell y is zero

Examples[edit]

Hello World[edit]

 :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>

Cat[edit]

EOF returns 0:

:ASC:>0<{0{<0>>0<}}

EOF returns -1:

:ASC:>0<{0[+1]}{0{{0[-1]}<0>>0<{0[+1]}}}

99 bottles of beer[edit]

(With some cheating...)

{0[+99]}{1[+44]}{2[+46]}{3[+84]}{4[+97]}{5[+98]}{6[+100]}{7[+101]}{8[+102]}{9[+104]}{10[+105]}{11[+107]}{12[+108]}{13[+110]}
{14[+111]}{15[+112]}{16[+114]}{17[+115]}{18[+116]}{19[+117]}{20[+119]}{21[+10]}{22[+32]}{23[78]}{0(:NUM:<0>)}{1(:ASC:|22||5
||14||18||18||12||7||17||22||14||8||22||5||7||7||16|)}{2(:ASC:|22||14||13||22||18||9||7||22||20||4||12||12|)}{3(<3><4><11><
7><22><14><13><7><22><6><14><20><13><1><22><15><4><17><17><22><10><18><22><4><16><14><19><13><6>)}{0{!0!!1!!2!:ASC:<1><22>!
0!!1!:ASC:<2><21>!3!:ASC:<2><21><21>{0[-1]}}}:ASC:<23><14>!1!!2!:ASC:<2><21>

Fibonacci[edit]

///////////// VARIABLES
{0[10]}    // How many numbers we want
///////////// CONSTANTS
{1[1]}     // Small temp
{2[1]}     // Large temp
{4[32]}    // Space
{5[10]}    // Newline
///////////// CODE
:NUM:<1>   // Print out 1
:ASC:<4>   // Print of a space
{0[-1]}
{0{
  {1{       // Moves 1 to 3
    {1[-1]}
    {3[+1]}
  }}
  {2{       // Moves 2 to 1, adds 2 to 3
    {1[+1]}
    {2[-1]}
    {3[+1]}
  }}
  {3{       // Adds 3 to 2
    {3[-1]}
    {2[+1]}
  }}
  :NUM:<1>       // Print out the number
  :ASC:<4>       // Print out a space
  {0[-1]}
}}
:ASC:<5> // Print out a newline

Without row breaks and comments:

{0[10]}{1[1]}{2[1]}{4[32]}{5[10]}:NUM:<1>:ASC:<4>{0[-1]}{0{{1{{1[-1]}{3[+1]}}}
{2{{1[+1]}{2[-1]}{3[+1]}}}{3{{3[-1]}{2[+1]}}}:NUM:<1>:ASC:<4>{0[-1]}}}:ASC:<5>

Implementations[edit]

Sofa Skull[edit]

The main implementation is named Sofa Skull (since it was programmed on a sofa) and is availble here: http://gitorious.org/projects/sofaskull