www.pudn.com > pl0_compiler_c.rar > table.cpp
// table.cpp: implementation of the table class. ////////////////////////////////////////////////////////////////////// #include#include "cifa.h" #include "table.h" #include "yufa.h" Ctable::Ctable(CPlCompiler *p) { pl=p; lev=0; tx[0]=0; table[0].name[0]=0; } //开始登陆 void Ctable::Enter(enum object k) { if (pl->yufa->Level()>lev) tx[++lev]=tx[lev-1]; else if (pl->yufa->Level() =TABLE_SIZE) return; strcpy(table[tx[lev]].name,pl->cifa->id); table[tx[lev]].kind=k; switch (k) { case constant: //如果是常量名 table[tx[lev]].val=pl->cifa->num; break; case variable: //如果是变量名 table[tx[lev]].level=pl->yufa->Level();//记下它所属的层次号 table[tx[lev]].adr=pl->yufa->DataAddr(); break; case procedure: //如果要登陆的是过程名 table[tx[lev]].level=pl->yufa->Level(); break; } } int Ctable::Position(char *id) { int i=tx[lev]; while (stricmp(table[i].name,id) && i>0) i--; return i; }