text to brainfuck converter

a simple text to brainfuck converter, written in lex

--- download ---

source code

/*
	text to brainfuck converter
	-- saves any input text inside the brainfuck registers and prints it all out.
	
	2004-07-22 - BeF <bef@erlangen.ccc.de>
	
	compile hint:
		lex -o text2bf.lex.c text2bf.lex.l
		cc -pipe -O2 text2bf.lex.c -o text2bf -ll
*/
%{
int prevchar = 0;
%}

%%

(.|\n) {
	printf("<[->+>+<<]>>[-<<+>>]<");
	if (prevchar < yytext[0])
		while (yytext[0]-prevchar++)
			putchar('+');
	else
		while (yytext[0]-prevchar--)
			putchar('-');
	putchar('>');
	prevchar = yytext[0];
	}


%%

int main ()
{
	int ret = yylex();
	printf("<[<]>[.>]\n");
	return ret;
}