PATH

 back   




Introduction

PATH programs are arranged on a two-dimensional grid. Slash and backslash characters are used to direct program flow up, down, left, and right, and “arrow” characters are used to branch program flow.

A PATH program has only a minimal environment to run: an array of unlimited integers (memory cells), and standard input and output. The program can input and/or ouput ASCII values from the cells, increment/decrement cells, seek between different cells, and branch off in different directions if the current cell is not equal to 0.

The PATH interpreter starts at the first "$" character in the program file and starts heading right, reading every character (or instruction symbol) in its way. The interpreter behaves accordingly when it encounters one of these valid instruction symbols:

$  start the program here, heading right
#  end the program
+  increment the current memory cell value
-  decrement the current memory cell value
}  move the read/write head on the right memory cell (next one)
{  move the read/write head on the left memory cell (previous one)
,  input an ASCII character from standard input into the current memory cell
.  output an ASCII character from the current memory cell into standard output
/  if heading in direction:
 
- right, turn up
- down, turn left
- left, turn down
- up, turn right
\  if heading in direction:
 
- right, turn down
- down, turn right
- left, turn up
- up, turn left
^  if the value of the current memory cell is not 0, turn up
<  if the value of the current memory cell is not 0, turn left
>  if the value of the current memory cell is not 0, turn right
v  if the value of the current memory cell is not 0, turn down
!  jump over the next symbol (therefore ignoring it)

If the PATH interpreter does not understand a symbol, it simply passes over it without taking any action.

You have surely remarked that the PATH language strongly derives from Brainfuck which it uses the concepts while adding a second dimension to it. The control structure directly belongs to the language and enables us to write programs that look like ASCII art.

The aim of that page is not to teach you how to program in PATH, but to give you an interpreter written in PHP that will help you in that task. That interpreter implements a “Turing machine“ object as internal data structure, and simulates the standard input with a string given as parameter.

The media example is not real programming, but it uses ASCII art to encrypt some data (and it tests the interpreter by the way).

Source code :
PATH interpreter in PHP

This application is public domain: you can download it and use it for whatever you will. If you bring any modification to it you wish to share, the new version will be added on this site.


Link:
PATH on SourceForge


 back