ZISC ultra
Jump to navigation
Jump to search
ZISC ultra is an esolang by User:Yourusername which uses a command that changes the brainfuck command the other command runs.
Commands
| Command | Description |
|---|---|
% |
increment accumulator by 1 then mod it by 8 |
|
index into this string and run the corresponding brainfuck command: ><+-.,[]
|
brainfuck to ZISC ultra
| brainfuck | ZISC ultra |
|---|---|
> |
|
< |
% %%%%%%%
|
+ |
%% %%%%%%
|
- |
%%% %%%%%
|
. |
%%%% %%%%
|
, |
%%%%% %%%
|
[ |
%%%%%% %%
|
] |
%%%%%%% %
|
Examples
Cat program
%%%%% % %%%%%% % %%
Hello, World!
The following program prints the message “Hello, World!” to the standard output:
%% %%%% %%%%% %%%%% %%% %%% %% %% %%%%%% %%% %%%%%% %%%%%% %% %% %%%%%% %% %%%% % %%% % %%%% %% %% %%%% %%%% %%%%%% %%%% %%%%%% %%%% %%%%%%% %% %%% %%%%%% %% %%%%%%% % %%%%% %% % %%%% %% %%
See also
Implementation
The following Common Lisp code provides functions dedicated to the transcription from ZISC ultra to brainfuck, and vice versa:
(deftype accumulator-state ()
"Defines the accumulator's range."
'(integer 0 7))
(deftype destination ()
"Defines a sink for printing operations."
'(or null (eql T) stream string))
(declaim (type (simple-string 8) +BRAINFUCK-IDENTIFIERS+))
(defparameter +BRAINFUCK-IDENTIFIERS+ "><+-.,[]"
"Associates the recognized brainfuck commands with their ZISC ultra
paregals in a bidirectional fashion by adminiculum of their
zero-based positions inside of the sequence.")
(defun convert-ZISC-to-brainfuck (zisc-code &optional (destination NIL))
"Converts the ZISC-CODE into a brainfuck equivalent and prints the
result to the DESTINATION, yielding for the same being non-NIL the
NIL value, otherwise producing a fresh string comprehending the
output."
(declare (type string zisc-code))
(declare (type destination destination))
(let ((accumulator 0))
(declare (type accumulator-state accumulator))
(the (or null string)
(if destination
(loop for zisc-token of-type character across zisc-code do
(case zisc-token
(#\% (setf accumulator (mod (1+ accumulator) 8)))
(#\Space (format destination "~c"
(schar +BRAINFUCK-IDENTIFIERS+ accumulator)))
(otherwise NIL)))
(with-output-to-string (brainfuck-code)
(declare (type string-stream brainfuck-code))
(convert-ZISC-to-brainfuck zisc-code brainfuck-code))))))
(defun get-accumulator-difference (start-value desired-value)
"Returns the number of incrementations required in order to change
from the accumulator START-VALUE into the DESIRED-VALUE."
(declare (type accumulator-state start-value))
(declare (type accumulator-state desired-value))
(the accumulator-state
(cond
((< start-value desired-value) (- desired-value start-value))
((> start-value desired-value) (+ (- 8 start-value) desired-value))
((= start-value desired-value) 0)
(T (error "Invalid combination of accumulator start value ~d ~
and desired value ~d." start-value desired-value)))))
(defun convert-brainfuck-to-ZISC (brainfuck-code &optional (destination NIL))
"Converts the BRAINFUCK-CODE into a ZISC ultra equivalent and prints
the result to the DESTINATION, yielding for the same being non-NIL
the NIL value, otherwise producing a fresh string comprehending the
output."
(declare (type string brainfuck-code))
(declare (type destination destination))
(let ((current-accumulator 0))
(declare (type accumulator-state current-accumulator))
(the (or null string)
(if destination
(loop for bf-token of-type character across brainfuck-code do
(let ((new-accumulator
(position bf-token +BRAINFUCK-IDENTIFIERS+
:test #'char=)))
(declare (type (or null accumulator-state) new-accumulator))
(when new-accumulator
(format destination "~v@{~a~:*~} "
(get-accumulator-difference current-accumulator new-accumulator)
#\%
(setf current-accumulator new-accumulator)))))
(with-output-to-string (zisc-code)
(declare (type string-stream zisc-code))
(convert-brainfuck-to-ZISC brainfuck-code zisc-code))))))