dev/bash/bff/text2bf.c

41 lines
578 B
C

/*
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;
}