BF Macros, Take 3

Published June 30, 2005
Advertisement
I got the second half of the BF macro preprocessor done, and I now have a collection of useful BF macros:

#define FALSE 0#define TRUE 1#define SET(position,value) >(position)[-]+(value)<(position)#define ZERO(position) SET(position,0)#define INC(position) >(position)+<(position)#define DEC(position) >(position)-<(position)#define IF(position) >(position)[<(position)#define ENDIF(position) >(position)[-]]<(position)#define WHILE(position) IF(position)#define ENDWHILE(position) >(position)]<(position)#define ADD(from,to) WHILE(from)DEC(from)INC(to)ENDWHILE(from)#define ADD_N(position,value) >(position)+(value)<(position)#define SUB_N(position,value) >(position)-(value)<(position)#define SUB(from,to) WHILE(from)DEC(from)DEC(to)ENDWHILE(from)#define COPY(original,copy,temp) ZERO(copy)ZERO(temp)WHILE(original)DEC(original)INC(copy)INC(temp)ENDWHILE(original)ADD(temp,original)#define COMPARE(first,second,temp) ZERO(temp)ADD(first,temp)SUB(second,temp)IF(temp)INC(first)ENDIF(temp)#define TESTNONZERO(position,temp) ZERO(temp)ADD(position,temp)IF(temp)INC(position)ENDIF(temp)#define TESTZERO(position,temp) ZERO(temp)ADD(position,temp)INC(position)IF(temp)SET(position,FALSE)ENDIF(temp)


I added a redundancy check on the tail end of my macro utility.

After all of the <(x) have been expanded, it recursively removes any instance of "<>", "><", "+-", and "-+" that it finds within the resulting code. Based on how simple the preprocessor is, I either had to make it do math, or eliminate adjacent pairs of instructions that cancel out. Removing adjacent pairs was simpler.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Music To My Ears

1716 views

Getting There...

1980 views

Guess Chess

1878 views

iPhone JetLag

1829 views

iPhone JetLag

1672 views
Advertisement