我正在开发一个类似于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创建完整的应用程序,一旦完成,然后用你的语言重构你的代码。 –