1 Star 0 Fork 1

ylyhappy/编译原理虎书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
symbol.c 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
ylyhappy 提交于 2024-05-21 15:41 . 解决了$1消失的问题
#include "symbol.h"
struct S_symbol_ {string name; S_symbol next;};
static S_symbol mksymbol(string name, S_symbol next){
S_symbol s = checked_malloc(sizeof(*s));
s->name = name; s->next=next;
return s;
}
#define SIZE 109
static S_symbol hashtable[SIZE];
static unsigned int hash(char *s0){
unsigned int h = 0; char *s;
for (s = s0; *s; s++)
h = h * 65599 + *s;
return h;
}
static int streq(string a, string b){
return !strcmp(a, b);
}
S_symbol S_Symbol(string name){
int index = hash(name) % SIZE;
S_symbol syms = hashtable[index], sym;
for (sym = syms; sym; sym = sym->next)
if (streq(sym->name, name)) return sym;
sym = mksymbol(name, syms);
hashtable[index] = sym;
return sym;
}
string S_name(S_symbol sym){
return sym->name;
}
S_table S_empty(void){
return TAB_empty();
}
void S_enter(S_table t, S_symbol sym, void *value){
TAB_look(t, sym);
}
static struct S_symbol_ marksym = {"<mark>", 0};
void S_beginScope(S_table t){
S_enter(t, &marksym, NULL);
}
void S_endScope(S_table t){
S_symbol s;
do s = TAB_pop(t);
while(s != &marksym);
}
void S_dump(S_table t, void(*show)(S_symbol sym, void *binding)){
TAB_dump(t, (void (*)(void *, void *)) show);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ylyhappy/hushu.git
git@gitee.com:ylyhappy/hushu.git
ylyhappy
hushu
编译原理虎书代码
master

搜索帮助