我正在開發一個類似於C的編譯器,我想知道編譯器如何與系統包含在一起。設計一個編譯器像C
編譯器讀取完整的代碼,並存儲所有包含在一個列表和解析器中包含的包含,讀完當前代碼後?
// file main.c
#include <stdio.h> // store in one list
// continue the parse ...
int main()
{
return 0;
}
// now, read the includes
// after finish the includes parse, gen code of sources
// just a sample
// file stdio.h
#include <types.h> // store in list
#include <bios.h> // store in list
void printf(...)
{
}
void scanf(...)
{
}
順便說一句,我developd的系統(僅測試)來讀取包括和,停止解析,閱讀包括...(這是一個令人厭惡的代碼,但是,工作...) (鏈接樣本) - >https://gist.github.com/4399601
btw,什麼是最好的方式來閱讀包括...和包括文件的工作?
我只是跳你沒有嘗試在C語言中實現解析器...有更好的語言,例如Bison – benjarobin
你需要小心的術語。 C不是編譯器,它是一種語言。你想編寫一個C編譯器,或者一個C語言的編譯器嗎? – Mat
或者你想讓一個完整的語言說「Alexa」?如果是這樣,那麼你可以用C或C++或Java創建完整的應用程序,一旦完成,然後用你的語言重構你的代碼。 –