/*
* The Braktif Cellular Automaton
* A brainfuck-like programming language in a 28-state cellular automaton.
* Covered under a BSD-style license; see LICENSE for more information.
*
* June 2005: original design and definition of the Braktif CA.
* May 3 2007: added BSD license.
*/
/* -------------------- Transmission Media --------------------- */
state Space " "
to SkipBack when (^ WakeMark and ^> WendCmd) or (> SkipBack),
to SkipStart when ^< SkipReply and ^ InstrMark,
to SkipFore when v< SkipStart or < SkipFore;
state Bus "-"
to > when > is Signal,
to ^> when ^> is Signal,
to v> when v> is Signal,
to < when < is Reply,
to ^< when ^< is Reply,
to v< when v< is Reply,
to ContTool when > LeftTool or < RightTool,
to ContReply when < ContTool,
to SkipReply when < SkipTool,
to LeftSig when > InstrPtr and ^> LeftCmd,
to RightSig when > InstrPtr and ^> RightCmd,
to FlipSig when > InstrPtr and ^> FlipCmd,
to QuerySig when > InstrPtr and ^> WhileCmd,
to InstrPtr when < WakeMark or v< WakeMark or ^< Wakemark,
to InstrPtr when < InstrPtr and ^< Space,
to InstrPtr when > SkipBack,
to SkipStop when < SkipFore,
to InstrPtr when < SkipStop;
/* -------------------- Signals and Replies -------------------- */
class Signal
to Bus;
class Reply
to Bus;
state LeftSig "L" is Signal;
state RightSig "R" is Signal;
state FlipSig "F" is Signal;
state QuerySig "Q" is Signal;
state ContReply "C" is Reply;
state SkipReply "S" is Reply;
/* ------------------- Data Store: Data Pointer ---------------- */
state DataPtr "d"
to FlipTool when > FlipSig,
to LeftTool when > LeftSig,
to RightTool when > RightSig,
to SkipTool when > QuerySig and ^ OffBit,
to ContTool when > QuerySig and ^ OnBit;
state FlipTool "f"
to ContTool;
state LeftTool "l"
to Bus;
state RightTool "r"
to Bus;
state ContTool "c"
to DataPtr;
state SkipTool "s"
to DataPtr;
/* ----------------- Data Store: Tape Contents ----------------- */
state OnBit "1"
to OffBit when v FlipTool;
state OffBit "0"
to OnBit when v FlipTool;
/* ----------------- Program: Instruction Pointer -------------- */
state InstrPtr "i"
to Bus when ^ Space,
to InstrMark;
state InstrMark "I"
to WakeMark when < ContReply,
to Bus when < SkipReply;
state WakeMark "W"
to Bus;
/* ----------------- Program: Instruction Skipper -------------- */
state SkipStart "!"
to Space;
state SkipStop "%"
to Bus;
state SkipFore "}"
to Space;
state SkipBack "{"
to Space;
/* -------------------- Program: Instructions ------------------- */
state FlipCmd "*";
state LeftCmd "<";
state RightCmd ">";
state WhileCmd "[";
state WendCmd "]".