Sashleyfuck

From Esolang
Jump to navigation Jump to search

Sashleyfuck is just like Brainfuck, but it uses the letters S, A, H, L, E, and Y, in addition to the conditional constructs [ and ]. It was made after MiroslavRD being the biggest Sashley hater.


Commands

Most of the commands utilize a letter from the term Sashley. Since the word sashley has 2 S's, sahley is used. That means [ and ] can be still used.

Command Description
s moves the pointer to the right, but it gives you a fake syntax error while it does the command anyway. It was referenced from Sashley's right eye, which is black with a purple X in it.
a Moves the pointer to the left.
h Increments the memory cell under the pointer.
l Decrements the memory cell under the pointer.
e Outputs the character signified by the cell at the pointer.
y Inputs a character and stores it in the cell at the pointer.
[ Jumps past the matching ] if the cell at the pointer is 0.
] Jumps back to the matching [ if the cell at the pointer is nonzero.

"Hello World!"

shhhhhhhh[ahhhhhhhhsl]ahhhhhhhheshhhhh[ahhhhhsl]ahhhhehhhhhhheehhheshhhhhhhhh[alllllllllsl]ahheshhhhhhh[ahhhhhhhsl]ahhhhhheshhhhh[ahhhhhsl]alehhhellllllelllllllleshhhhhhhh[allllllllsl]alllele

Output

Syntax error - JUST KIDDING: Hello World!

Cat program

The infinite cat program amounts to:

ye[ye]

Implementation

A very simple interpreter implementation in Common Lisp constitutes the following:

(defun interpret-Sashleyfuck (code &aux (position 0))
  "Interprets the Sashleyfuck CODE and returns NIL."
  (declare (type string code) (type fixnum position))
  (symbol-macrolet ((character (the character (char code position))))
    (let ((pointer         0)
          (memory          (make-hash-table :test #'eql))
          (error-printed-p NIL))
      (declare (type integer pointer) (type hash-table memory) (type boolean error-printed-p))
      (loop while (< position (length code)) do
        (case character
          (#\s (incf pointer)
               (unless error-printed-p
                 (format T "Syntax error - JUST KIDDING: ")
                 (setf error-printed-p T)))
          (#\a (decf pointer))
          (#\h (incf (gethash pointer memory 0)))
          (#\l (decf (gethash pointer memory 0)))
          (#\e (write-char (code-char (gethash pointer memory 0))))
          (#\y (format T "~&Please input a character: ")
               (setf (gethash pointer memory)
                 (prog1 (char-code (read-char))
                   (clear-input))))
          (#\[ (when (zerop (gethash pointer memory 0))
                 (loop with level of-type fixnum = 0 do
                   (incf position)
                   (when (>= position (length code))
                     (error "No matching ']' found."))
                   (case character
                     (#\[ (incf level))
                     (#\] (if (zerop level)
                            (loop-finish)
                            (decf level)))
                     (otherwise NIL)))))
          (#\] (unless (zerop (gethash pointer memory 0))
                 (loop with level of-type fixnum = 0 do
                   (decf position)
                   (when (minusp position)
                     (error "No matching '[' found."))
                   (case character
                     (#\] (incf level))
                     (#\[ (if (zerop level)
                            (loop-finish)
                            (decf level)))
                    (otherwise NIL)))))
          (otherwise NIL))
        (incf position)))))