| -y | Print the syntax tree of the
input_file. This is the structure of the syntax parse tree made by
bison/yacc |
|
| -v | Verbosity mode. Can pile up till level 10. | |
| -q | Quiety mode. Success/failure is reported in $? or ERRORLEVEL. | |
| -o
output-file |
Output file name. | |
| -g | Generate binary file with debug symbols to be used with gdb. | |
| -cw | Show warranty. | |
| -c[c] | Show copying license. | |
| -h | Print this help. -v -h for
advanced help. -vv for expert help. -vv... for debug information. |
| -E | (not
implemented)
stop after gcc preprocessor and write
output_file.i. |
|
| -S [syntax] | stop after gcc assembler and write output_file.s in the selected syntax. | |
| [-S [att]] | (default) %% prefix regs, addresses use (), op order src->dst, etc. | |
| -S intel | keywords for data size, addresses use [], op order dst<-src, etc. | |
| -C | stop after native C generator and write output_file.c. | |
| -K | keep intermediate C source code output_file.c. | |
| -B | (default) compile and write output_file.bin. | |
| If none is given, outputs executable binary (depends on existing GCC in the PATH). |
| -z opt | Minimum and maximum value of a
cell. Options are: |
|
| -z n,m |
n=minimum (>= 0), m=maximum
(<= UINTMAX) and n<m The maximum value may change with architecture, being it the size of an unsigned int minus 1 (usually 4 bytes). Unless told otherwise explicitaly by -t we have:
|
|
| -z bit | Same as -z 0,1 | |
| -z print | Same as -z 32,126 (ASCII
printable). Nice print if used with -p uchar or -p both, and -r on |
|
| -z number | Same as -z 48,57 (ASCII '0' to '9') | |
| -z letter | Same as -z 65,90 (ASCII 'A' to 'Z') | |
| [-z uchar] | (default) Same as -z 0,UCHARMAX | |
| -z ushort | Same as -z 0,USHORTMAX. Set -t ushort, unless told otherwise explicitaly by -t |
|
| -z uint |
Same as -z 0,UINTMAX (~ 4
billions). Set -t uint, unless told otherwise explicitaly by -t |
|
| If -r on or -r off is used, it is useful to read warnings given by verbosity level 1 or more (-v) | ||
| -t type | Type of array. The type of array
must hold the range of values set by
-z options (This values are architecture dependent.) Type is one of: |
|
| [-t uchar] |
(default) In the interval of [0, UCHARMAX] (1 byte) | |
| -t ushort | In the interval of [0, USHORTMAX] (2 bytes) | |
| -t
uint |
In the interval of [0, UINTMAX] (4 bytes) | |
| -a n |
(default)
-a USHORTMAX+1. Array size (quantity of cells), n=[1,
USHORTMAX+1] The pointer is type ushort unless:
|
|
| -# [n] | Debug mode on: interpret # command to dump array. | |
| [-# 0] |
(default) Debug mode off, ignore all #'s in resulted C source and compiled binary. | |
| -# 1 |
Debug mode off, ignore all #'s in the resulted binary, but show it as comments in C source. | |
| -# | Same as -# 11, debug mode on with 11 cells dump. | |
| -# n | n=[3, 5, 7, 9, 13, ... 99] debug mode on with n cells dump. | |
| Debug mode on: interpret # command to dump array is better if set together with -p both. | ||
| -r wrap | Set option for wrapping around
cell values when they reach a limit. Wrap can be: |
|
| -r on |
Causes wrap around if cell overflow or underflow. | |
| -r off | Causes error if cell overflow or underflow. | |
| [-r none] | (default) Do not check bounds. Be careful:
bounds depends on type size of the target machine. If -r is not given, [-r none] is the default. Cell maximum and minimum values are set by -z option Not checking bounds around the limits of the types produces better code (see options -z uchar, -z ushort or -z uint) Unlike -w, where -a option is checked, -r don't auto check -z (or -t). That means that if you set -r on or -r off, and set for example -z 200,255, overflow errors cannot be checked! That is because cell will wrap to 0 before check, and then leaving the cell with an invalid value (zero). The same goes to -z 0,100, for example, and underflow error. Suggestion: use a bigger type to hold a number outside the chosen range, so checks can occurr. Example:
|
|
| -w wrap | Set option for wrapping around
the pointer when it reachs any limit. If -w is not given, [-w none] is the default. Pointer maximum limit is (n-1) set by -a n. Minimum is allways cell number 0. Wrap can be: |
|
| -w on | Causes wrap around if pointer
overflow or underflow If array size (-a) is UCHARMAX or USHORTMAX, see -w none to create simple code. With -w on conditionals are written to check bounds Conditional used : if(pointer>=MAX). Both underflow or overflow might have happen. If MAX is unreacheble by pointer, wrap occurr before the test. In this case, use -w none to wipe unnecessary code. With -a n and:
|
|
| |
-w off | Causes (controled) error if pointer
overflow or underflow. Need conditionals to test for bounds Maximum array size for this option is -a USHORTMAX (the last number is used as overflow/underflow error code) Conditional used : if(i>=MAX), for underflow or overflow. MAX cannot be unreacheble by the pointer to guarantee the desired behavior. With -a n and:
|
| [-w none] | (default)
Do not check for limis. Creates simpler code WARNING! If -a is not UCHARMAX+1 or USHORTMA+1, the pointer can raise real Segmentation Fault errors depending on the BrainForce user source code! How nice: If -a is set to those magic numbers, overflow/underflow just wraps around like -w on |
|
| -w expand | (not
implemented)
If pointer reaches the right limit, redimension array, till it gets the maximum size (or the memory is over). When it cannot allocates more memory, it becomes -w off. |
|
| -p style | Set how to print and read. Style can be: |
|
| -p uchar | uses putc() and getc() | |
| -p uint | (default) uses printf("%d") and scanf("%d") | |
| -p both | uses printf("%c %d") and scanf("%c %d") (or scanf("%d") if iterative mode on
-- see -i on) |
|
| -i [opt] |
Iterative mode, set input/output
from/to file or iterativelly (keyboard/monitor). Options are: |
|
| -i on |
Read/write from keyboard/screen Uses ungetc(), or simplified scanf("%d"), depending on -p |
|
| -i off |
(default) read/write from/to file.
Its necessary to use redirection symbols '<' and '>' from SO command line. Match getc()/putc() or scanf()/printf() (see -p) |
|
| -i switch | The compiled program inherit '-i' switch to chose from command
line before each execution. set argc/argv to read the switch that changes mode. So after compiling a test.bf, lets say: $brainforce test.bf -o test.exe -i switch One can run test.exe in both forms: read/write simplified mode (from/to file): $test.exe read/write iteratively (from/to keyboard/screen): $test.exe -i |
|
| -e |
Simplified source code (good to
use with -S), disable
read/write functions. Also set -z ushort, -t ushort, -a USHORTMAX+1, debug mode off -# 0, -r none, -w none, -p uchar, -i off. Its incompatible with any other runtime option. |
Brain Force complains with the language definition
by Urban Mueller. It
the most
simple language capable of executing all Turing class of algorithms
(that is: its Turing-Complete).
The
language
consists in only 8 commands, that manipulate to data: a
pointer to a tape composed of theorically infinity number of cells,
each of one holding a symbol (meaning here a numerical code that
represents a symbol). The implementation limits the tape to have at
maximum USHORTMAX cells (65535 for a machine with a short type of 2
bytes), and the values of cells any positive number from 0 to UINTMAX-1
(more than 4 billions).
The 8 commands can be summarized in this table:
| Command |
Effect |
Equivalent in C |
BrainForce Compiler switch that
affect the command |
| + |
Increases element under pointer | t[i]++; |
-z to chose the minimu/maximum
value of the cell -t to chose the type of the array -r to wrap around, cause errors, or don't check |
| - |
Decrases element under pointer | t[i]--; |
Same as + |
| > |
Increases the pointer (move it
to the right) |
i++; |
-a to chose the maximum value of
the pointer -w to wrap around, cause errors, or don't check |
| < |
Decreases the pointer (move it to the left) | i--; |
Same as > |
| [ |
Starts a loop if the value under
the pointer is not zero |
while(t[i]) { |
Can be made while(t[i]!=ZMIN) if
minimum chosen by -z is different of zero |
| ] |
Loop back to the begginning of
the loop |
} |
|
| . |
Print the cell value under the
pointer |
putchar(t[i]) |
-p to print decimal values
instead of characters, or both -i to print newlines in iterative mode |
| , |
Read a value from the standard
input and saves it in the cell under the pointer |
getchar(t[i]) |
-p to read decimal values
instead of characters -i to read from file when iterative mode is off |
The language was all written using the powerfull tools flex/bison
(lex/yacc gnu compatibles). The compiler raises errors during the
compilation time alerting problems with unbalanced brackets, and
nothing else (as it ignores all chars, and all commands are single
char, there is not much syntax error beside that).
As for today there is no know bugs, but you are welcome to test and
send bug reports. Be brave and do beta-test on the Brain Force Compiler if you can. ;)