symbol.h

来自「c语言的简化编译器」· C头文件 代码 · 共 70 行

H
70
字号
#ifndef __SYMBOL_H__
#define __SYMBOL_H__

/* pxdscript symbol.h
 */

#include "tree.h"

/* It has been shown by experiments that using a hashtable size of 317 will lead to 
   the best distribution of symbol names under the hash-code function used here */ 
#define HashSize 317

/* functions defining the datastructure used */
typedef struct SymbolTable {
    SYMBOL *table[HashSize];
    struct SymbolTable *parent;
} SymbolTable;

/* Initialize the hash table which makes up the symbol table. */
SymbolTable *initSymbolTable();

SymbolTable *scopeSymbolTable(SymbolTable *t);

/* Insert into the symboltable. */
SYMBOL *putSymbol(SymbolTable *t, char *name, SymbolKind kind);

/* Retrieve from the symbol table. */
SYMBOL *getSymbol(SymbolTable *t, char *name);

/* Returns 1 (true) if a symbol of the given name is found in the symbol table, 0 otherwise */
int defSymbol(SymbolTable *t, char *name);




/* the functions that build the symboltable */

void symSCRIPTCOLLECTION(SCRIPTCOLLECTION *s);


/* First pass functions */

void sym1PassSCRIPTCOLLECTION(SCRIPTCOLLECTION *s);
void sym1PassTOPLEVEL(TOPLEVEL *t, SymbolTable *sym);
void sym1PassFUNCTION(FUNCTION *f, SymbolTable *sym);
void sym1PassPROGRAM(PROGRAM *s, SymbolTable *sym);
void sym1PassDECL(DECL *d, SymbolTable *sym);
void sym1PassFORINIT(FORINIT *f, SymbolTable *sym);
void sym1PassSTM(STM *s, SymbolTable *sym);
void sym1PassIDENTIFIER(IDENTIFIER *i, DECL *decl, SymbolTable *sym);
void sym1PassEXP(EXP * e, SymbolTable *sym);
void sym1PassLVALUE(LVALUE *l, SymbolTable *sym);

/* Second pass functions */

void sym2PassSCRIPTCOLLECTION(SCRIPTCOLLECTION *s);
void sym2PassTOPLEVEL(TOPLEVEL *t, SymbolTable *sym);
void sym2PassFUNCTION(FUNCTION *f, SymbolTable *sym);
void sym2PassPROGRAM(PROGRAM *s, SymbolTable *sym);
void sym2PassDECL(DECL *d, SymbolTable *sym);
void sym2PassFORINIT(FORINIT *f, SymbolTable *sym);
void sym2PassSTM(STM *s, SymbolTable *sym);
void sym2PassEXP(EXP * e, SymbolTable *sym);

/* chenhongyu, 2004-9-17. */
void sym1PassSIMPLEDECL(DECL *d, SymbolTable *sym);
void sym2PassSIMPLEDECL(DECL *d, SymbolTable *sym);
#endif

⌨️ 快捷键说明

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