esolang

FEU

The whole input is one string. Every line of the program rewrites it with a regex, and what is left at the end is the output.

tuxcrafting · Turing complete: unknown · ●●○ moderate

Tested with 5 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

FEU stands for File Edition Utility. Its README calls it a sed-like utility that makes heavy use of regexes. A program is a list of lines, and each line is one edit, such as a substitution, an append or a prepend, or turning a number into a row of marks and back. There is no output command to speak of; the string the edits leave behind is printed when the program ends, with no newline added.

Read the story

Control flow comes from blocks. /regex/ runs its body once for each match and puts the results together in place of the whole input. loop repeats until an e line inside it finds its regex, and line runs its body on each line of the input in turn.

Numbers are handled the way sed users handle them, in unary. u/ turns 12 into twelve zeros and U/ counts them again, so adding is joining two rows of zeros.

The machine

LineDoes
s/re/text/gReplace the first match, or every match with g
m/re/text/re/text/gSeveral replacements, one after the other
a/text p/textAppend or prepend text
e/re e/re/!Leave the enclosing block when the regex matches, or when it does not
u/c U/cA number as that many c (a 0 by default); count the c
/re/g … endRun the body on each match; the results joined become the input
loop do 5 line … endRepeat until an e fires, 5 times, once per line
func f … end, call fName a block and run it
Es/V/re Ep/V EP/V Ea/VStore a match in V; push the input and take V; store the input in V and pop; append V
printWrite the input now

Texts go through a Ruby string literal, so \n and \x41 work. Everything after a line __DATA__ is the input instead of code.

This implementation follows the Ruby source that Try It Online runs, including two things its README does not say. Every regex ignores case, because the source hands its flags to Regexp.new as a string and the Ruby on Try It Online reads any string there as "ignore case". And the i/ comment lines the README describes do not exist in the source, so such a line stops the program.

Example

The second program adds.
Expected: 42
Expected: > one > two
Expected: Bye world

The second program adds. The block runs once for each number, u/ turns it into a row of zeros, the rows are joined, and U/ counts the zeros. The last line shows the ignored case. This truth machine stops on 0 and would print 1 forever.

Expected: 0

Patterns it teaches

  • String rewriting: the state is one string, changed by search and replace until a test says stop.

Try this

  1. Reverse the order of the lines of the input.
  2. Print the length of the input in decimal.
  3. Hard: multiply two numbers. The repository's example does it with three unary variables.

Further

Also in Rewriting

Write your own in Run Convert a program from FEU

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run feu -e 'a/Hello, World!'
shib manual feu

Source

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

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