esolang

Incident

There is no list of commands. A token is any piece of text that occurs exactly three times in the program.

ais523, 2016 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: meow

The idea

ais523 made Incident for the CALESYTA 2016 contest. The goals were a real puzzle, and a language whose programs can obey almost any restriction on their source: banned characters, a polyglot with another language, a file that is also an image.

Read the story

So the lexer is decided by the program. Every substring that appears exactly three times is a token, unless it sits inside a longer token or overlaps another one. Everything else is a comment. Changing one character anywhere can change how the whole program parses.

The machine

Each token is a command with its own stack of bits, and what a copy does depends on which of the three it is.

CopyDoes
FirstPush 0, jump to just after the second copy
ThirdPush 1, jump to just after the second copy
SecondPop a bit; on 0 jump to just after the first copy, on 1 after the third

Input and output hang off the same rules. Every bit pushed onto the stack of the centremost token is written out, least significant bit first. Popping an empty stack reads a bit from the input; at the end of input the command is skipped. A push that would only repeat itself with no pop in between is skipped, so it cannot loop forever.

Example

The cat from the specification is a face.

The cat from the specification is a face. Its tokens are bits of the drawing that happen to occur three times, and the rest of the picture is comment.

The Hello World on the specification is 2080 bytes of labels like A1.A2.A3,. Each label occurs three times and so becomes a token; a dot or a comma on its own occurs hundreds of times, so it is no token.

Patterns it teaches

  • Hostile design: the parse depends on the whole program at once.
  • Polyglot: tokens can be any bytes, so an Incident program can hide in almost any other file.
  • Turing completeness: it can run a Minsky machine, by way of The Amnesiac From Minsk.

Further

Pattern-based

Stack-based

Write your own in Run Convert a program from Incident

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: incident.

Command line

shib run incident -e '    |\ /|
    /"^"\
    (0 0)
    \_*_/_________
      (          _^^,
      (_________) ( )
cat    |||   |||   "
       ||^   ||^
       ^^    ^^' --input 'meow'
shib manual incident

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/incident.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org