#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.