Brainfuccuccino is a Java scripting engine which allows brainfuck programs to be embedded and run in Java applications. It conforms to the Java Scripting API (JSR 223).
One key feature of Brainfuccuccino is that it conforms to the Java Scripting API (JSR 223).
This allows using the ScriptEngine
interface to execute brainfuck programs:
ScriptEngine bfScriptEngine = new ScriptEngineManager().getEngineByName("brainfuccucino");
ScriptContext context = bfScriptEngine.getContext();
// Set up a writer for the brainfuck program to output to.
Writer writer = new StringWriter();
context.setWriter(writer);
// Hello World program from https://esolangs.org/wiki/Brainfuck (CC0 public domain)
bfScriptEngine.eval(
"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>" +
"---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.",
context
);
// Prints "Hello World!"
System.out.println(writer.toString());
Another straightforward option to run brainfuck programs is to call Brainfuccuccino directly.
The following is a full example of cat
or a program that echoes back standard input to standard output.
import java.io.IOException;
public class Cat {
public static void main(String[] args) throws IOException {
// Exit by sending an end-of-transmission (Ctrl-D) or terminating the application.
Brainfuccuccino.brew(",[.,]");
}
}
Brainfuccuccino.brew
attaches System.in
and System.out
to the input and output (respectively) of the brainfuck program automatically.
This allows quick experimentation with brainfuck programs that involve I/O.
Java 8 or higher.
Brainfuccuccino is not yet available on Maven Central. Currently, it is only available as SNAPSHOT artifacts on OSSRH repository provided by Sonatype.
NOTE: The SNAPSHOT artifacts will likely not be provided once the first release artifact is available.
It takes two modifications in your application's pom.xml
to use the SNAPSHOT artifacts:
First, add the following to get SNAPSHOT artifacts from the OSSRH repository:
<repositories>
<repository>
<id>ossrh-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
Second, add the following the <dependencies>
section of the POM:
<dependency>
<groupId>net.coobird.labs.brainfuccuccino</groupId>
<artifactId>brainfuccuccino</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Brainfuccuccino is very early in its development. The APIs are subject to change at any time.
Brainfuccuccino is released under the MIT License.