This comment is reply for 3955 mtsuyugu: 出力のインデント処理と配列の長さを引数で...(BFコンパイラー). Go to thread root.
dankogai #3961(2007/11/13 14:30 GMT) [ C ] Rating1/1=1.00
ケースが嫌いな私は、以下のように書き換えてしまいました。機能的には#3955と互換ですが、出力されたCコードのコンパイルには差し支えないのでインデントは省略しました。
Dan the Brainf.cker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <stdio.h> #include <stdlib.h> int main( int argc, char *argv[] ){ int c; char *code[256]; int length; FILE *fp; if( argc < 2 ){ fprintf(stderr,"Usage: %s sourcefile\n", argv[0] ); return EXIT_FAILURE; } if( (fp = fopen( argv[1], "r" )) == NULL ){ fprintf(stderr,"Error: %s cannot opened\n", argv[1] ); return EXIT_FAILURE; } if( !argv[2] || (length = atoi( argv[2] )) <= 0 ){ length = 256; } for (c = 0; c < 256; c++) code[c] = NULL; code['>'] = "sp++;"; code['<'] = "sp--;"; code['+'] = "(*sp)++;"; code['-'] = "(*sp)--;"; code['.'] = "putchar(*sp);"; code[','] = "*sp = getchar();"; code['['] = "while(*sp){"; code[']'] = "}"; puts("#include <stdio.h>"); puts("#include <stdlib.h>"); printf("#define DATA_LEN %d\n", length); puts("char code[DATA_LEN];"); puts("int main (void){"); puts(" char *sp = code;"); while( (c=fgetc( fp )) != EOF ) if (code[c]) printf("%s\n", code[c]); puts(" return EXIT_SUCCESS;"); puts("}"); fclose(fp); return EXIT_SUCCESS; }
Rating1/1=1.00-0+
[ reply ]
dankogai
#3961()
[
C
]
Rating1/1=1.00
ケースが嫌いな私は、以下のように書き換えてしまいました。機能的には#3955と互換ですが、出力されたCコードのコンパイルには差し支えないのでインデントは省略しました。
Dan the Brainf.cker
Rating1/1=1.00-0+