/*****
* symbol.h
* Andy Hammerlindl 2002/06/18
*
* Creates symbols from strings so that multiple calls for a symbol of
* the same string will return an identical object.
*****/
// Put the symbol table into a state where symbols can be translated.
initTable();
}
};
typedef unsigned int uint;
/* The symbol class, just a wrapper around the augmented hash value. This
* wrapper is so that
* cout << s << endl;
* prints the symbol name instead of a meaningless integer.
*
* This is a lightweight class and should have no virtual functions for speed
* reasons.
*/
struct symbol {
// Is there any particular reason why this is in symbol?
static GCInit initialize;
// Translate a string into a unique symbol, such that two strings are equal
// if and only if their resulting symbols are equal.
// len should be equal to strlen(s)+1
static symbol rawTrans(const char *s, size_t len);
static symbol opTrans(string s) {
return literalTrans("operator "+s);
}
static symbol trans(string s) {
// Figure out whether it's an operator or an identifier by looking at the
// first character.
char c=s[0];
return isalpha(c) || c == '_' ? literalTrans(s) : opTrans(s);
}
// Make a symbol that is guaranteed to be unique. It will not match any other
// symbol in the namespace.
static symbol gensym(string s);