5command

From Esolang
Jump to: navigation, search

5command is an esoteric programming language created by User:Icepy in 2014. 5command has a very small command set of only 5 commands. 5command is a tape based language which has an infinite amount of slots. It has a debug mode that can be set to true or false in a interpreter. debug mode is automatically false. Also, anything that is not valid syntax, is a comment. 5command was built to print out very large numbers, in a small amount of time and space.

Commands

+  move the pointer right on the tape
-  move the pointer left on the tape
^  increment where the pointer is pointing at
v  decrement where the pointer is pointing at
*  print out the number at the pointer (without a space);

Examples

Simple Program

^*

Normal mode will print

Program: ^*
Output: 1

Debug mode will print

Program: ^*
Output: 1

DEBUG
0->1

Interpreters

Here is one written in PHP

<?php
$program = "";
function run($program = "", $debug = false) {
    $counter = 0;
    $tape = array(0);
    echo "Program: '$program'<br>";
    echo "Output: '";
    $program = str_split($program);
    foreach($program as $cmd) {
        switch($cmd) {
	    case '+':
	        $counter++;
		if($tape[$counter] == null) {
		    $tape[$counter] = 0;
		}
	        break;
            case '-':
                if($counter == 0) {
	            echo " You cant go there!<br>";
		} else {
		    $counter--;
		}
		break;
            case '^':
	        $tape[$counter]++;
		break;
            case 'v':
                if($tape[$counter] == 0) {
                    echo " You cant go there!"
                } else {
	            $tape[$counter]--;
                }
		break;
	    case '*':
                echo $tape[$counter];
		break;
        }
    }
    echo "'";
    if($debug) {
	echo "<br><br>DEBUG<br>";
	for($i = 0; $i <= count($tape) - 1; $i++) {
	    echo "$i->$tape[$i]<br>";
	}
    }
}
run($program);
?>

And one written in perl

%c=qw(+ $p++ - $p-- ^ D++ v D-- * print+D);
$/=$,;$_=<>;s/./$c{$&};/g;s[D]'$b[$p]'g;eval

See also