Commentator
Every command is a comment marker from some other language, so a program looks like the debris of commented out code.
caird coinheringaahing · Turing complete: unknown · ●●○ moderate
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
caird coinheringaahing made Commentator out of the characters that start and end comments: //, /*, */, #, {-, -}, <! and friends. A space adds one. So a Hello World is mostly spaces, 72 of them and then /* to print an H.
Read the story
The machine is a row of accumulators. One of them is active, and most commands change it, often using the next one along as a second operand.
The machine
| Code | Does |
|---|---|
| space | Add one |
# | Set to 0 |
// | Add the next input number, or the next accumulator once the input is used up |
{- -} | Move to the next accumulator, making it if needed; move back |
/* */ | Print as a character, print as a number |
! % <! | Multiply, remainder, floor divide by the next accumulator |
e# <# <- | Negate, flip the lowest bit, logical not |
-- | 1 if prime, else 0 |
A line that starts with ; runs as many times as the active value says, one with : runs once if it is not 0, and one with ? runs while it is not 0. If nothing was printed, the active value is printed at the end.
This implementation follows the Python interpreter at github.com/cairdcoinheringaahing/Commentator, quirks and all. <- gives a Python boolean, which */ prints as True or False. Any Python error, an empty line included, ends the program quietly. The input numbers that TIO passes as arguments are read from the input.
Example
The first reads 6 and 7 into two accumulators and multiplies them; nothing was printed, so the result is.
The first reads 6 and 7 into two accumulators and multiplies them; nothing was printed, so the result is. The second makes 5 and prints its logical not. The third sets 3, then runs a line 3 times that adds one to the second accumulator, and prints that.
Patterns it teaches
- Camouflage: a program reads like a pile of comments.
- Counter machines: a row of counters, increments and a while loop.
Further
See also
Also in Camouflage
Write your own in Run Convert a program from Commentator
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: commentator.
Command line
shib run commentator -e ' 'shib manual commentatorSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/commentator.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language