SNUSP programming language

SNUSP (for SNUSP's Not Unix, but Structured PATH) is a recast of the Brainfuck programming language into a Befunge-like two-dimensional style, inspired by its predecessor — PATH.

The SNUSP instruction set stays closer than PATH to the Brainfuck language by retaining all instructions related to memory (+, -, > and <) and IO (. and ,). The Brainfuck control flow instructions (] and [) are replaced by the four basic SNUSP two-dimensional control flow instructions (/, \<tt>, <tt>? and !).

Contents

Features

All SNUSP instructions are single non-alphanumeric characters.

Execution of a SNUSP program begins at the starting indicator ($) — or the top-left cell, in lack of a starting indicator — and proceeds rightwards in a straight line, one cell at a time, until an instruction changes the direction or performs a jump.

The two basic control-flow instructions ruld (\) and lurd (/) cause the direction of execution to turn 90° and can be thought of as deflectors. In addition, there is the skip (!) instruction, which immediately moves past the next cell, and the skipz (?) instruction, which works the same way if and only if the current memory cell contains zero. All the usual Brainfuck instructions (except ] and [) are available for memory manipulation and IO.

Like in Brainfuck, all alphanumeric characters are ignored and can be used as comments. In fact, SNUSP comments can even contain instruction characters, as long as they are never executed as code. Of course, embedding instructions into comments helps when writing obfuscated code.

For example, execution of the following SNUSP program begins at the starting indicator ($) and follows the staked-out path around the comment, finally ending upon hitting the return instruction (#).

   /============#
   | This is a
$==/ comment.

Thus, the program will never actually output anything, despite the fact that it contains a print instruction (.). The = and | characters are designated no-op instructions used to document the execution path.

Subroutines are implemented by the enter (@) and leave (#) instructions:

$===before=call===@\===after=call===#
                   |
                   \===inside=subroutine===#

The enter instruction pushes the current location and direction to the call stack. This information is used by the leave instruction, which pops the call stack and jumps back to the saved location. To avoid entering an infinite loop, it then immediately skips two cells forward. If the call stack is empty, executing a leave instruction causes the program to terminate.

Specification

As currently specified [1] (http://www.deepwood.net/~drlion/snusp/snusp-1.0-spec-wd1.pdf), the language is compartmentalized into three self-contained languages of increasing power, each one a superset of the previous one:

Core SNUSP 
Equal to Brainfuck in expressive power with essentially the same language semantics.
Modular SNUSP 
Adds support for subroutines by introducing a call stack and the enter (@) and leave (#) instructions.
Bloated SNUSP 
Currently adds support for concurrency and non-determinism.

However, there is talk about moving to a more scalable SRFI-style extension model. [2] (http://c2.com/cgi/wiki?SnuspLanguage)

Sample code

This Modular SNUSP program computes the quotient and remainder obtained by dividing two one-digit decimal numbers, which are read from standard input:

   /==!/============atoi=@@@@=@@=--#
   |   |   /==!/====itoa=@@@@=@@=++#
   |   |   |   |
$,@/>,@/@\@/.<@/.#
         |           /-\  
         \===div=?\<!\?/#!===+<<<\      /-\
                  \<==@\>@\>>!/?!/=<?\>!\?/<<#
                          |  |  #\->->+</
                          \=!\=?!/->>+<<?\#
                                #\?<<+>>-/

In the above program, the conversions between ASCII digits and integers are handled by the atoi and itoa subroutines, while the actual computation is performed by the div subroutine. Finally, the result is printed to standard output.

As another example, here is an implementation of the Ackermann function:

   /==!/==atoi=@@@@=@@=--#
   |   |
   |   | [j]{i} -> {A(i,j)}, where A is the Ackermann function
   |   |       /=========\!==\!====\   ** recursion **
$,@/>,@/==ack=!\?\<+#    |   |     |   A(0,j) -> j+1
 j   i           \<?\+>-@/#  |     |   A(i,0) -> A(i-1,1)
                    \@\>@\->@/@\<-@/#  A(i,j) -> A(i-1,A(i,j-1))
 {a}[ ][0]  #      #  |  |     |
 {0}[ ][a]  /-<<+>>\!=/  \=====|==@\>>>@\<<#  {a}[ ][0]
  (a > 0)   ?      ?           |   |    |     [a]{ }[a]
 [0][ ]{a}  \>>+<<-/!==========/   |    |
 [a][ ]{0}  #      #               |    |
                     {a}[ ][0][0]  |    |  [0][ ][ ]{a}
                     {0}[ ][a][a]  |    |  [a][ ][ ]{0}
                    #/?========\!==/    \==!/=======?\#
                     \->>+>+<<</            \>>>+<<<-/

Much like in the previous example, this program reads two decimal ASCII digits, converts them to integers, and uses them as parameters to the ack subroutine. However, in this case, the result of the subroutine is never printed to standard output; it can be extracted only by the use of a debugger. Because of the extreme growth rate of the Ackermann function, the result of most inputs would not fit in a single decimal digit; thus, a simple call to itoa would not suffice here.

Note the {a}[ ][0]-style comments; these document the stack effect of each subroutine. The stack layout prior to executing the subroutine is written first, while the resulting layout is written below or to the right. Each memory cell is bracketed, with curly brackets denoting the current memory cell.

The program that implements the Ackermann function demonstrates a remarkable property of Befunge-derived languages: code can be executed bi-directionally. This is exploited by the loop that moves a value up two cells, which also serves to move a value down two cells — by executing in the opposite direction!

To complete the program, the following subroutine could be employed to print the result in multi-digit decimal ASCII:

           /recurse\    #/?\ zero
==print10=!\@\>?!\@/<@\.!\-/
             |   \=/  \==itoa=@@@+@+++++#
             !     /+ !/+ !/+ !/+   \  mod10
             /<+> -\!?-\!?-\!?-\!?-\!
             \?!\-?!\-?!\-?!\-?!\-?/\  div10
                #  +/! +/! +/! +/! +/


External links

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools