Create a bijective function between the syntactically valid BF programs and the natural numbers
This means that you will assign each BF program a nonnegative integer (0,1,2,...) in such a way that each number gets a BF program without syntax errors (and without whitespace or comments).
Note that something like Binaryf***, for two reasons. Both +>
and >
map to 2, and no valid program maps to 6
(since [
is not a valid BF program).
You may either create two programs, one to map BF programs to numbers, one to map numbers to valid BF programs (which will be inverses) (in which case your score is the sum of their lengths), or you can create one program which does both tasks (in which case your score is just length of that one program).
Note: The program(s) must run in polynomial time (in terms of the length of the input). (This rule is to prevent boring brute force approaches.)
This is code-golf, so the shortest program(s) wins!