Function Repository Resource:

BrainLanguageEvaluate

Source Notebook

Run code in the brain language virtual machine

Contributed by: Aster Ctor

ResourceFunction["BrainLanguageEvaluate"][code]

runs code in the brain language virtual machine.

Details and Options

Per Wikipedia, Brainf*** (the last three characters have been modified to remove offensive content) is a minimalist, esoteric programming language that uses just eight characters.
ResourceFunction["BrainLanguageEvaluate"] requires a Python installation for evaluation.
CompilationTarget supports the following parameters:
"Refined"remove all useless characters and standardize
"Operations"output as virtual machine instruction
"Output"default output
"OutputDebug"output as an u8-array
TranslationOptions has the following built-in dialect encodings:
"Normal"do not make any extra escaping
"Chinese"encode using "右左增减始终写读"
"Dao"encode using "☴☳☱☶☰☷☲☵"
"周易"encode using "巽震兌艮坤乾離坎"
"Ook"encode using the esoteric language Ook

Examples

Basic Examples (1) 

Translate from default brain language to a text string:

In[1]:=
ResourceFunction["BrainLanguageEvaluate"]["
+
[
	>>>->-
	[
		>->----<<<
	]
	>>
]

>.
---.
>+..
+++.
>>.
<.
>>---.
<<<.
+++.
------.
<-.
>>+.
"]
Out[1]=

Scope (1) 

The output is assumed to be UTF-8 encoded, which can support all Unicode characters:

In[2]:=
ResourceFunction["BrainLanguageEvaluate"]["
++++++++
[
	>>++
	>++++
	>++++++
	>++++++++
	>++++++++++
	>++++++++++++
	>++++++++++++++
	>++++++++++++++++
	>++++++++++++++++++
	>++++++++++++++++++++
	>++++++++++++++++++++++
	>++++++++++++++++++++++++
	>++++++++++++++++++++++++++
	>++++++++++++++++++++++++++++
	>++++++++++++++++++++++++++++++
	<<<<<<<<<<<<<<<<-
]

>>>>>>>>>>>>>>>++++.
<<---.
<<.
>>>>+.
<<<<+++++.
>>.
>>-.
<<-----.
<<<++++++.
>>>>>+++.
<<<<<-.
---------.
"]
Out[2]=

Options (6) 

CompilationTarget (4) 

Enter formatted source code:

In[3]:=
bf42 = "++++         +++
    +[>++++    ++[>+<-][
   <]<  -]>   >++    +++
  +.-   ---   ---    ---
 --.+++++++         +++
        +++       .++
        +++      +.-
        ---    -----.--.
";

Remove meaningless characters and convert to standard form:

In[4]:=
ResourceFunction["BrainLanguageEvaluate"][bf42, CompilationTarget -> "Refined"]
Out[4]=

Dump actual instructions:

In[5]:=
ResourceFunction["BrainLanguageEvaluate"][bf42, CompilationTarget -> "Operations"] // TableForm
Out[71]=

The default behavior is to display the output directly:

In[72]:=
ResourceFunction["BrainLanguageEvaluate"][bf42, CompilationTarget -> "Output"]
Out[72]=

TranslationOptions (2) 

Specify a dialect, such as the esoteric language Ook:

In[73]:=
ResourceFunction["BrainLanguageEvaluate"]["	Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook.
	Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
	Ook! Ook! Ook? Ook! Ook? Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook.
	Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
	Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
	Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
	Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
	Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
	Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook.",
 TranslationOptions -> "Ook"
 ]
Out[73]=

Another dialect using octal digit encoding:

In[74]:=
ResourceFunction["BrainLanguageEvaluate"][
 "0o221344120302033303111502225111112600061611122260333336133333600026",
 TranslationOptions -> "Number"
 ]
Out[74]=

Possible Issues (1) 

If the evaluation does not halt, the entire session will be stuck. In this case, run the following code to reinitialize:

In[75]:=
ResourceFunction["BrainLanguageEvaluate"][Initialize]
Out[75]=

Publisher

Aster Ctor (MoeNet)

Version History

  • 1.0.0 – 16 December 2019

Related Resources

Author Notes

The virtual machine is implemented in Python, so follow the Python environment in advance to utilize this function.

License Information