char *findInString(const char *string, const char *pattern) /* Return first occurrence of pattern in string. * (Ignores case) */ { char c1 = toUp(*pattern++); int patSize = strlen(pattern); char c; while ((c = *string++) != 0) { if (c1 == toUp(c)) { int i; for (i=0; i<patSize; ++i) { if (toUp(string[i]) != toUp(pattern[i])) break; } if (i == patSize) return (char*)(string-1); } } return NULL; }
// 输出关键字和标识符的函数 void print_word(char* token) { // 首先判断是不是关键字 int key; key = searchHash(token, HashTable); if( key != -1 ) { // 是关键字 toUp(token); // 将小写字母转换为大写字母 printf("(%s,0)\n",token); } else // 不是关键字,是标识符 { int key = searchHash(token,IdTable); if(key == -1) //判断该标识符是否已插入“标识符哈希表” key = createHash(token,IdTable); // 不在哈希表中 printf("(ID,%d)\n",key); // 输出该标识符在哈希表中的位置 } }