?? lexicon.cpp
字號:
void Lexicon::set_standard_tokens()
{
int i = 0;
String symbols = ( String )
"; ( ) ~ abs sqr sqrt exp ln lg sin cos arctan round trunc ! % + - * / ^ x pi e";
String word;
while (get_word(symbols, i++, word) != fail) {
Token t = word;
}
token_data[23].value = 3.14159;
token_data[24].value = 2.71828;
}
int Lexicon::hash(const String &identifier) const
/*
Post: Returns the location in table Lexicon::index_code that
corresponds to the String identifier.
If the hash table is full and does not contain a record
for identifier, the exit function is called to terminate the
program.
Uses: The class String, the function exit.
*/
{
int location;
const char *convert = identifier.c_str();
char first = convert[0], second; // First two characters of identifier
if (strlen(convert) >= 2) second = convert[1];
else second = first;
location = first % hash_size;
int probes = 0;
while (index_code[location] >= 0 &&
identifier != token_data[index_code[location]].name) {
if (++probes >= hash_size) {
cout << "Fatal Error: Hash Table overflow. Increase table size\n";
exit(1);
}
location += second;
location %= hash_size;
}
return location;
}
Lexicon::Lexicon()
/*
Post: The Lexicon is initialized with
the standard tokens.
Uses: set_standard_tokens
*/
{
count = 0;
for (int i = 0; i < hash_size; i++)
index_code[i] = -1; // code for an empty hash slot
set_standard_tokens();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -