There are the following operations:
macro name {arguments} {code}
bfmacro name {arguments} {code}
Define macros of name with arguments and code. bfmacro has bf code, macro has macro code.
{arguments} is just a list of variables in the macro.
while variable {code}. Corresponds to "variable[code]".
add variable number. Corresponds to "variable(number amount of plusses)".
subtract variable number. Corresponds to "variable(number amount of minuses)".
out variable. Corresponds to "variable.".
in variable. Corresponds to "variable,".
bf {code}. Corresponds to "code".
@ variable number. Declares a variable at address number.
Now, to step through how this would be compiled:
@ var1 0
@ var2 1
@ var3 2
bfmacro copy {from to temp} {temp[-]to[-]from[to+temp+from-]temp[from+temp-]}
add var1 5
copy var1 var2 var3
EOF
We go through the macro expansion stage, resulting in:
@ var1 0
@ var2 1
@ var3 2
add var1 5
bf {var3[-]var2[-]var1[var2+var3+var1-]var3[var1+var3-] copy var1 var2 var3}
EOF
Then, we expand the builtins as follows:
@ var1 0
@ var2 1
@ var3 2
var1+++++ add var1 5
var3[-]var2[-]var1[var2+var3+var1-]var3[var1+var3-] copy var1 var2 var3
EOF
Finally, we map the variables onto their appropriate addressing:
@ var1 0
@ var2 1
@ var3 2
var1+++++ add var1 5
>>>[-]<[-]<[>>+>+<<<-]>>>[<<<+>>>-] copy var1 var2 var3
EOF
Note that the resulting code is fully commented, so that once compiled, one can still understand the code.