2 releases
0.1.1 | Oct 1, 2023 |
---|---|
0.1.0 | Feb 22, 2023 |
#494 in Programming languages
46KB
968 lines
bfup
Preprocessor for brainfuck-like languages.
It allows the user, like every decent preprocessor should, to obfuscate their code with weird macros and obtuse syntax, even being able to arrange the output code in a rectangle of set width.
bfup is meant to be used primarily on top of brainfuck or languages with brainfuck-like syntaxes, as it operates mainly on single, utf-8 encoded characters. It is possible to wholly configure the recognized operators (characters) and the defined preprocessor directives' prefixes.
Usage
Basic usage:
bfup [OPTIONS]... [FILE]
The list of all available flags can be seen by
using the --help
flag.
Behavior
The program tries to preprocess the provided file, outputting only characters (to stdin by default) specified as operators (brainfuck operators by default). By default, the output is also arranged in a rectangle.
Configuring
Recognized operators, as well as every directive character used by the parser can be configured with corresponding command-line options or read from a RON config file.
Syntax
The preprocessor recognizes 5 basic types of 'tokens':
Token | Preprocessed as |
---|---|
Operators | copied directly to the output |
Tokens enclosed by ( ) |
groups the tokens and treats them as a single token. |
# followed by a number |
multiplies the next token number times |
$ followed by any character, followed by a token |
defines a macro that substitutes every subsequent occurrence of character with token |
\ |
skips the next character |
Example
Code evaluating to a brainfuck program
that prints Hello World!
followed by a newline:
$z([-]) $p(.z)
$H(#72+p)
$e(#101+p)
$l(#108+p)
$o(#111+p)
$,(#44+p)
$ (#32+p)
$W(#87+p)
$r(#114+p)
$d(#100+p)
$!(#33+p)
$/(#10+p)
Hello, World!/
Caveats
Be wary, that every character can be defined as a macro; you can overwrite operators, preprocessor directive prefixes and even whitespace characters. For example:
$+(-) $
< $$([[[-]]])
+++$
evaluates to:
<---([[[-]]])
In addition, macro definitions take the very first valid token they encounter, this means that:
$m($z$a+([-])aa)
mz
evaluates to:
++[-]
Contributing
I appreciate any bug report/contribution/criticism.
Dependencies
~2–12MB
~97K SLoC