home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
microcrn
/
issue_40.arc
/
DAIMS.ARC
/
SYMCLASS.HXX
< prev
next >
Wrap
Text File
|
1988-02-10
|
2KB
|
51 lines
/* SYMCLASS.H header for symbol table class */
enum vartype { INTEGER, DOUBLE, MATRIX, STRTYPE, KEYWORD };
struct name {
char* label; /* identifier or keyword string */
vartype type; /* what kind of thing is this? */
name* next; /* link to next item in this hash entry */
union {
int intval;
double doubleval;
matrix * matptr;
string * cstrptr;
} value ;
};
enum insert_request { LOOKUP = 0, NEWNAME = 1, NEWKEYWORD = 2 };
const TBLSZ = 23;
/*
-*++ class sym_tab: symbol table object for the DAIMS interpreter
**
** (*++ history:
** 7 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
class sym_tab {
name* tb[TBLSZ]; /* hashed symbol table heads */
public:
sym_tab(); /* constructor */
~sym_tab(); /* destructor defined in symclass.c */
name* look(char* p, int ins = 0);
/* ins == 0 means look up name in table, return 0 if name not found, */
/* pointer to name structure containing the string if found */
/* ins != 0 means insert a new name or a new keyword */
/* ins == NEWNAME means insert new name in table */
/* ins == NEWKEYWORD means insert new keyword in table */
name* insert(char* s) { return look(s,NEWNAME); };
void remove(name*); /* remove a name from the table */
name* keyword(char *s) { return look(s,NEWKEYWORD); };
int iskeyword(char *s) { return (look(s)->type == KEYWORD); };
void dump(); /* dump symbol table to cout */
void error(char * msg) { cerr << "symbol table error: " << msg << "\n"; exit(1);};
};