我正在开发一个类似 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(...)
{
}
顺便说一句,我开发了一个系统(仅测试)来读取包含并停止解析,读取包含......(这是一个令人作呕的代码,但是,工作......)(示例链接)-> https: //gist.github.com/4399601
顺便说一句,阅读包含...并使用包含文件的最佳方法是什么?