符号表与索引生成器
1. 引言
在许多程序中,符号表是一种重要的数据结构,用于跟踪输入中使用的名称。本文将介绍如何使用符号表来实现一个简单的索引生成器,以及如何将其扩展为一个 C 语言交叉引用工具。
2. 索引生成器
2.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 */
%}
这里定义了两个结构体 symbol 和 ref ,分
超级会员免费看
订阅专栏 解锁全文
5万+

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



