Jump to content
Sign in to follow this  
  • entries
    292
  • comments
    557
  • views
    154312

BF Macros

Sign in to follow this  
TANSTAAFL

98 views

This is not a "new" EPL.
This is not an EPL "enhancement".
This is a tool to assist in the writing of BF by raising the level of abstraction.
And if you think of this as "cheating": unless you program solely in machine code, you can STFU.

I've got an idea of what the macro language should look like (it is rather C/C++-ish):


#define ZERO(x) >(x)[-]<(x)
#define POSITION 10

ZERO(POSITION)



ZERO(POSITION)

expands to:

>(POSITION)[-]<(POSITION)

which expands to:

>(10)[-]<(10)

which expands to:

>>>>>>>>>>[-]<<<<<<<<<<

a negative value is represented with a leading '~' instead of '-', because '-' is already a BF instruction.

>(~x) becomes <(x)
<(~x) becomes >(x)
+(~x) becomes -(x)
-(~x) becomes +(x)
.(~x) becomes ,(x)
,(~x) becomes .(x)
[(~x) becomes ](x)
](~x) becomes [(x)

in the end, everything still winds up as BF code, suitable for any BF interpreter.

Of course, I'm doing the thing backwards, so step one becomes:

turn this:


+(8)[>+(9)<-]>.<+(5)[>+(6)<-]>-.+(7).(2)+(3).<+(8)[>(2)+(4)<(2)-]>(2).<(2)+(4)[>-(6)<-]>.<+(3)[>+(6)<-]>.+(3).-(6).-(8).>+.


into:


++++++++[>+++++++++<-]>.<+++++[>++++++<-]>-.+++++++..+++.<++++++++[>>++++<<-]>>.<<++++[>------<-]>.<++++[>++++++<-]>.+++.------.--------.>+.

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!