⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbsym.c

📁 c编译器实现
💻 C
字号:
/* *  FBCC - A simple C compiler. *  *  Copyright (c) 1996 Fabrice Bellard * *  Contact addresses: *  mail: Fabrice Bellard, 451 chemin du mas de Matour, 34790 Grabels, France *  email: bellard@email.enst.fr *  url: http://www.enst.fr/~bellard * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <stdlib.h>#include <stdio.h>#include <string.h>#include "fbcc.h"BLOCK *block_global;BLOCK *block_current;BLOCK *block_function;SYM *sym_hash[SYM_HASH_SIZE];int hash_func(char *str,int sym_table){	 char *p;	 int h;  	 p=str;	 h=sym_table % SYM_HASH_SIZE;	 while (*p!=0) {			h=((h<<8)+(*p)) % SYM_HASH_SIZE;			p++;	 }	 return h;}SYM *Sym_Search(char *str,int sym_table){	 int h;	 SYM *p;	 	 h=hash_func(str,sym_table);	 p=sym_hash[h];	 while (p!=NULL) {			if ( strcmp(p->str,str) == 0 && p->sym_table == sym_table ) return p;			p=p->hash_next;	 }	 return NULL;}/* * Cr閍tion d'un nouveau symbole dans un bloc */SYM *Sym_New1(char *str,int sym_table,BLOCK *b,LIST *l){	 SYM *s;	 int h;	 	 s=malloc(sizeof(SYM));	 	 strcpy(s->str,str);	 	 h=hash_func(s->str,sym_table);	 s->hash_next=sym_hash[h];	 if (s->hash_next!=NULL) s->hash_next->hash_prev=&s->hash_next;	 sym_hash[h]=s;	 s->hash_prev=&sym_hash[h];	 s->block_next=b->sym_first;	 b->sym_first=s;	 s->block=b;	 	 s->list=l;	 s->sym_table=sym_table;	 return s;}/* * Cr閍tion d'un nouveau symbole dans le bloc de d閏laration courant */SYM *Sym_New(char *str,int sym_table,LIST *l){	 return Sym_New1(str,sym_table,block_decl,l);}/*  * Retour d'un nouveau nom de symbole assurante son unicit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -