符号表与索引生成器:从文本索引到C语言交叉引用
1. 符号表与索引生成器概述
在许多flex或bison程序中,符号表是一个关键组件,用于跟踪输入中使用的名称。我们将从一个简单的索引生成程序开始,该程序会列出输入中每个单词出现的行号,随后将其修改为一个C语言交叉引用程序。
1.1 索引生成器的符号表管理
索引生成器的符号表主要用于跟踪每个单词及其所在的文件和行号。以下是索引生成器的声明部分示例:
/* fb2-4 text concordance */
%option noyywrap nodefault yylineno case-insensitive
/* the symbol table */
%{
struct symbol { /* a word */
char *name;
struct ref *reflist;
};
struct ref {
struct ref *next;
char *filename;
int flags;
int lineno;
};
/* simple symtab of fixed size */
#define NHASH 9997
struct symbol symtab[NHASH];
struct symbol *lookup(char*);
void addref(int, char*, char*,int);
char *curfilename; /* name of current input file */
超级会员免费看
订阅专栏 解锁全文
9178

被折叠的 条评论
为什么被折叠?



