【自作プログラミング言語】1.シンプルなインタフェースを実現


シンプルなインタラクションを実現


まず簡単なインタラクティブインターフェースを実現し、Windowsの下で主にputs、gets、printfの3つの関数を使用して入力と出力を実現します.linuxまたはmacではreadlineという関数を使用します.前処理を使用してプラットフォーム間符号化を実現することができ、具体的なコードは以下の通りである.
#include 
#include 

#ifdef _WIN32
#include
static char buffer[2048];
//windows readline
char* readline(char* prompt)
{
    fputs(prompt, stdout);
    fgets(buffer,2048,stdin);
    char* cpy = (char*)malloc(strlen(buffer)+1);
    strcpy(cpy, buffer);
    cpy[strlen(cpy)-1] = '\0';
    return cpy;
}

void  add_history(char* unused){}


#else
#include
#include
#endif

int main(int argc,char** argv)
{
    puts("Lispy Version 0.01");
    puts("Press Ctrl+c to Exit
"
); while(1) { char* input = readline("lispy> "); add_history(input); printf("No you're a %s
"
,input); free(input); } return 0; }

リファレンスアドレス


シンプルなインタフェースを実現