// Key genierieren Key Symboltable::insert(Lexem lexem, TokenType type) { List* currentList = this->table; TableEntry* entry; currentList += hash(lexem); Information* info; for (int i = 0; i < currentList->getSize(); i++) { entry = currentList->getLexem(i); if (strcmp(entry->getLexem(), lexem) == 0) { Information* entryInfo = entry->getInfo(); //Neu Info anlegen, wenn sich Token Type geändert hat //FIX: Mööööööööööööp! Nenene, der Typ des eingetragenen Tokens muss immer //beibehalten werden! Sonst klappt das mit den reservierten Wörtern wie "print" //nichtmehr! /* if (entryInfo->getType() != type) { delete entryInfo; info = new Information(); info->setLexem(lexem); info->setType(type); entry->setInfo(info); } */ //Gebe key zurück, wenn Eintrage gefunden return (Key) info; } } //Wenn kein eintrag gefunden wurde, füge neuen Eintrag an Liste an. info = new Information(); info->setLexem(lexem); info->setType(type); //entry->setLexem(lexem); //entry->setInfo(info); currentList->add(lexem, info); return (Key) info; }
void Symboltable::initSymbols(){ Information* whileInfo = new Information("while"); whileInfo->setType(Token::WHILE); Information* WHILEInfo = new Information("WHILE"); WHILEInfo->setType(Token::WHILE); Information* ifInfo = new Information("if"); ifInfo->setType(Token::IF); Information* IFInfo = new Information("IF"); IFInfo->setType(Token::IF); Information* readInfo = new Information("read"); readInfo->setType(Token::READ); Information* writeInfo = new Information("write"); writeInfo->setType(Token::WRITE); Information* elseInfo = new Information("else"); elseInfo->setType(Token::ELSE); Information* ELSEInfo = new Information("ELSE"); ELSEInfo->setType(Token::ELSE); Information* intInfo = new Information("int"); intInfo->setType(Token::INT); Information* plusInfo = new Information("+"); plusInfo->setType(Token::PLUS); Information* minusInfo = new Information("-"); minusInfo->setType(Token::MINUS); Information* starInfo = new Information("*"); starInfo->setType(Token::STAR); Information* colonInfo = new Information(":"); colonInfo->setType(Token::COLON); Information* smallerInfo = new Information("<"); smallerInfo->setType(Token::SMALLER); Information* greaterInfo = new Information(">"); greaterInfo->setType(Token::GREATER); Information* equalsInfo = new Information("="); equalsInfo->setType(Token::EQUALS); Information* assignmentInfo = new Information(":="); assignmentInfo->setType(Token::ASSIGNMENT); Information* weirdthingInfo = new Information("=:="); weirdthingInfo->setType(Token::WEIRDTHING); Information* exmarkInfo = new Information("!"); exmarkInfo->setType(Token::EXMARK); Information* andandInfo = new Information("&&"); andandInfo->setType(Token::ANDAND); Information* semicolonInfo = new Information(";"); semicolonInfo->setType(Token::SEMICOLON); Information* bracketopenInfo = new Information("("); bracketopenInfo->setType(Token::BRACKETOPEN); Information* bracketcloseInfo = new Information(")"); bracketcloseInfo->setType(Token::BRACKETCLOSE); Information* curlybracketopenInfo = new Information("{"); curlybracketopenInfo->setType(Token::CURLYBRACKETOPEN); Information* curlybracketcloseInfo = new Information("}"); curlybracketcloseInfo->setType(Token::CURLYBRACKETCLOSE); Information* squarebracketopenInfo = new Information("["); squarebracketopenInfo->setType(Token::SQUAREBRACKETOPEN); Information* squarebracketcloseInfo = new Information("]"); squarebracketcloseInfo->setType(Token::SQUAREBRACKETCLOSE); this->insert(whileInfo); this->insert(WHILEInfo); this->insert(ifInfo); this->insert(IFInfo); this->insert(readInfo); this->insert(writeInfo); this->insert(elseInfo); this->insert(ELSEInfo); this->insert(intInfo); this->insert(plusInfo); this->insert(minusInfo); this->insert(starInfo); this->insert(colonInfo); this->insert(smallerInfo); this->insert(greaterInfo); this->insert(equalsInfo); this->insert(assignmentInfo); this->insert(weirdthingInfo); this->insert(exmarkInfo); this->insert(andandInfo); this->insert(semicolonInfo); this->insert(bracketopenInfo); this->insert(bracketcloseInfo); this->insert(curlybracketopenInfo); this->insert(curlybracketcloseInfo); this->insert(squarebracketopenInfo); this->insert(squarebracketcloseInfo); }