bAdkOde

Importing files

Usage:
%[filename];

After I implemented labels and macros, I figured that it would be nice if I was able to define them all in one place and then re-use them over and over again. Hence, the concept of imports.

Examples:
In file macros.b:

# Macro to convert ASCII representation of integer to actual
# integer value
*OFFSET = 48;
@atoi(CHR) = -$OFFSET$CHR;

# Macro to convert integer value to ASCII representation of
# integer value
@itoa(NUM) = +$OFFSET$NUM;

In file macro-use.bad:

%macros.b
# Input a character
?a
# Convert to actual integer value
&atoi(a)

# Store the number 9 in location pointed to by value in 
# register a
>9[a
# Convert 9 to ASCII value of the character '9' (57)
&itoa([a)

By convention, bAdkOde scripts end with the extension bad, whereas macro-definition files end with the extension b. Also, macro-definition files shouldn’t contain any actual code. Any such code is ignored. It’s possible to “overload” macros. You can have macros that share the same name, but they must have different numbers of parameters.

Example bAdkOde scripts

Here are a few example scripts:

hello-world.bad

)0)33)100)108)114)111)87)32)111)108)108)101)72(a{!a"a(a}

fibonacci.bad

# prints the first 10 fibonacci numbers
)0
)1
>10a
>a[a
{![a
 (a
 (b
 )b
 'b"32
 +ab
 (a
 )b
 )a
 >10a
 -1[a
}
"8"10

reverse.bad

# reverse prints what ever the user enters
)0
>1a
{!a
 ?a
 )a
 -10a
}
>1a
{!a
 (a
 "a
}

echo.bad

# takes whatever the user enters and stores it in memory
# and then prints it out
>0b>1a{!a?a>a[b+1b-10a}>0b>1a{!a>[ba"a+1b-10a}

As you can see, pretty unreadable. I’ve tried to provide a semblance of readability in some scripts by indenting. But you can pretty much write everything in one line and it’ll work.