int BSTSearch (tBSTNodePtr RootPtr, char K, int *Content) { if ( RootPtr != NULL ) { /* Pokud naje klic */ if ( RootPtr -> Key == K ) { /* Vrati obsah prislusneho uzlu a hodnotu TRUE */ *Content = RootPtr -> BSTNodeCont ; return TRUE ; } /* Pokud klic nenajde */ else { /* Pokud je klic vetsi nez K */ if ( RootPtr -> Key > K ) { /* Hledani pokracuje v levem podstromu */ return BSTSearch ( RootPtr -> LPtr , K , Content ) ; } /* Jinak pokracuje v pravem podstromu */ else { return BSTSearch ( RootPtr -> RPtr , K , Content ) ; } } } return FALSE ; }
int BSTSearch (tBSTNodePtr RootPtr, char K, int *Content) { /* --------- ** Funkce vyhledá uzel v BVS s klíèem K. ** ** Pokud je takový nalezen, vrací funkce hodnotu TRUE a v promìnné Content se ** vrací obsah pøíslu¹ného uzlu.´Pokud pøíslu¹ný uzel není nalezen, vrací funkce ** hodnotu FALSE a obsah promìnné Content není definován (nic do ní proto ** nepøiøazujte). ** ** Pøi vyhledávání v binárním stromu bychom typicky pou¾ili cyklus ukonèený ** testem dosa¾ení listu nebo nalezení uzlu s klíèem K. V tomto pøípadì ale ** problém øe¹te rekurzivním volání této funkce, pøièem¾ nedeklarujte ¾ádnou ** pomocnou funkci. **/ if ( RootPtr == NULL ) // strom je prazdny return FALSE; else{ // jestlize neni prazdny if ( RootPtr->Key == K){ // nasel *Content = RootPtr->BSTNodeCont; //vracime obsah uzlu return TRUE; }else{ if ( RootPtr->Key > K ) // jestli je klic vetsi return BSTSearch(RootPtr->LPtr, K, Content); // hledej v levem podstromu else return BSTSearch(RootPtr->RPtr, K, Content); // hledej v pravem podstromu } } }
int BSTSearch (tBSTNodePtr RootPtr, char K, int *Content) { /* --------- ** Funkce vyhledá uzel v BVS s klíèem K. ** ** Pokud je takový nalezen, vrací funkce hodnotu TRUE a v promìnné Content se ** vrací obsah pøíslu¹ného uzlu.´Pokud pøíslu¹ný uzel není nalezen, vrací funkce ** hodnotu FALSE a obsah promìnné Content není definován (nic do ní proto ** nepøiøazujte). ** ** Pøi vyhledávání v binárním stromu bychom typicky pou¾ili cyklus ukonèený ** testem dosa¾ení listu nebo nalezení uzlu s klíèem K. V tomto pøípadì ale ** problém øe¹te rekurzivním volání této funkce, pøièem¾ nedeklarujte ¾ádnou ** pomocnou funkci. **/ if(RootPtr!=NULL){ if(RootPtr->Key==K){ //prvek nalezen *Content=RootPtr->BSTNodeCont; return TRUE; } if(RootPtr->Key>K){ //prvek je u leveho syna if(BSTSearch(RootPtr->LPtr,K,Content)) return TRUE; }else{ //prvek je u praveho syna if(BSTSearch(RootPtr->RPtr,K,Content)) return TRUE; } } //dosli jsme na konec stromu -> prvek nenalezen return FALSE; }
int BSTSearch (tBSTNodePtr RootPtr, char K, int *Content) { /* Vyhledávání uzlu v BVS podle zadaného klíèe K. Pokud je nalezen, vrací ** funkce hodnotu TRUE a v promìnné Content se vrací obsah pøíslu¹ného uzlu. ** Pokud pøíslu¹ný uzel není nalezen, vrací funkce hodnotu FALSE a obsah ** promìnné Content není definován (to znamená, ¾e do ní nebudete nic ** pøiøazovat). Pøi vyhledávání v binárním stromu bychom typicky pou¾ili ** cyklus ukonèený testem zahrnujícím stav dosa¾ení listu nebo nalezení ** uzlu s klíèem. V tomto pøípadì ov¹em test nepou¾ijte a problém øe¹te ** rekurzivním volání této funkce (nedeklarujte ¾ádnou pomocnou proceduru ** nebo funkci). **/ if(!RootPtr){ return FALSE; } else if(RootPtr->Key > K) { return BSTSearch(RootPtr->LPtr, K, Content); } else if(RootPtr->Key < K) { return BSTSearch(RootPtr->RPtr, K, Content); } else { *Content = RootPtr->BSTNodeCont; return TRUE; } }
// search for a key in the BST Item * BSTSearch(TreeNode * tree, int searchKey ) { // easy, tree is null, so it's not here if ( tree == NULL ) return( NULL ); // found it! return the item pointer if ( tree->item->key == searchKey ) return( tree->item ); if ( tree->item->key > searchKey ) return( BSTSearch(tree->pLeft,searchKey)); else return( BSTSearch(tree->pRight,searchKey)); }
BST BSTSearch (BST b, Item i) { if (b == NULL) { return NULL; } if (b->itm->c == i->c) { return b; } if (i->c<b->itm->c) { // left return BSTSearch(b->l,i); } else { //right; return BSTSearch(b->r,i); } }
int globalDecl() { //za decl nebrat token if ((error = testToken(T_ID)) != E_OK) return error; //ID if(BSTSearch(TempTree, T.s) != NULL){ return E_SEMA; } strInit(&IDstr); strCopystring(&IDstr, &T.s); gettoken(); if ((error = testToken(T_COLON)) != E_OK) return error; gettoken(); if ((error = testToken(T_DATATYPE)) != E_OK) return error; /******************************************INSERT***************************************************************/ if(!(strCmpConstStr(&(T.s), "boolean"))) TempVar->type = O_BOOL; if(!(strCmpConstStr(&(T.s), "integer"))) TempVar->type = O_INT; if(!(strCmpConstStr(&(T.s), "real"))) TempVar->type = O_REAL; if(!(strCmpConstStr(&(T.s), "string"))){ TempVar->type = O_STRING; strInit(&TempVar->value.sval); } BSTInsert (&TempTree, IDstr, TempVar); /******************************************INSERT***************************************************************/ gettoken(); if ((error = testToken(T_SEMICOLON)) != E_OK) return error; // ";" gettoken(); //strFree(&IDstr); if (testToken(T_ID) == E_OK) if ((error = globalDecl()) != E_OK) return error; //dalsia promena? return E_OK; }
int writefun() { if((error = testToken(T_ID)) == E_OK){ if(afun == 1){ if(strCmpstring(&(T.s), &ActFun) != 0){ //added: Jmeno fkce, params, global, local if (searchParam(paramlist, &(T.s)) == NULL){ if((TempVar = BSTSearch (TempTreeL, T.s)) == NULL){ if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA; } } } } else{ if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA; } gettoken(); if((error = testToken(T_RB)) == E_OK){ return E_OK; } else if((error = testToken(T_COMMA)) == E_OK){ gettoken(); if((error = writefun()) != E_OK) return error; } else return error; } else if((error = testToken(T_STRING)) == E_OK){ gettoken(); if((error = testToken(T_RB)) == E_OK){ return E_OK; } else if((error = testToken(T_COMMA)) == E_OK){ gettoken(); if((error = testToken(T_STRING)) == E_OK) return error; if((error = writefun()) != E_OK) return error; } else return error; } else return error; return E_OK; }
//########################## HLEDANI ID V BVS ########################### tVariable *SearchDataType(tBSTNodePtr TTree, tBSTNodePtr TTreeL) { tVariable *TreePtr; // ukazatel TreePtr na strukturu tVariable if(TTreeL != NULL) // pokud neni LBVS prazdny { if ((TreePtr = BSTSearch (TTreeL, T.s))!= NULL) // hledej dany token v LOKALNIM BVS a pokud ho najdes { return TreePtr; // vrat ukazatele na nej } } if(TTree != NULL) // pokud neni BVS prazdny { if ((TreePtr = BSTSearch (TTree, T.s))!= NULL) // hledej dany token v GLOBALNIM BVS a pokud ho najdes { return TreePtr; // vrat ukazatele na nej } } return NULL; // pokud token nenajdes v BVS, vrat NULL }
int main(void) { BTreeNode * bstRoot; BTreeNode * sNode; BSTMakeAndInit(&bstRoot); BSTInsert(&bstRoot, 9); BSTInsert(&bstRoot, 1); BSTInsert(&bstRoot, 6); BSTInsert(&bstRoot, 2); BSTInsert(&bstRoot, 8); BSTInsert(&bstRoot, 3); BSTInsert(&bstRoot, 5); sNode = BSTSearch(bstRoot, 1); if(sNode == NULL) printf("탐색 실패 \n"); else printf("탐색에 성공한 키의 값: %d \n", BSTGetNodeData(sNode)); sNode = BSTSearch(bstRoot, 4); if(sNode == NULL) printf("탐색 실패 \n"); else printf("탐색에 성공한 키의 값: %d \n", BSTGetNodeData(sNode)); sNode = BSTSearch(bstRoot, 6); if(sNode == NULL) printf("탐색 실패 \n"); else printf("탐색에 성공한 키의 값: %d \n", BSTGetNodeData(sNode)); sNode = BSTSearch(bstRoot, 7); if(sNode == NULL) printf("탐색 실패 \n"); else printf("탐색에 성공한 키의 값: %d \n", BSTGetNodeData(sNode)); return 0; }
int BSTSearch (tBSTNodePtr RootPtr, char K, int *Content) { /* --------- ** Funkce vyhledá uzel v BVS s klíèem K. ** ** Pokud je takový nalezen, vrací funkce hodnotu TRUE a v promìnné Content se ** vrací obsah pøíslu¹ného uzlu.´Pokud pøíslu¹ný uzel není nalezen, vrací funkce ** hodnotu FALSE a obsah promìnné Content není definován (nic do ní proto ** nepøiøazujte). ** ** Pøi vyhledávání v binárním stromu bychom typicky pou¾ili cyklus ukonèený ** testem dosa¾ení listu nebo nalezení uzlu s klíèem K. V tomto pøípadì ale ** problém øe¹te rekurzivním volání této funkce, pøièem¾ nedeklarujte ¾ádnou ** pomocnou funkci. **/ if (RootPtr != NULL) { if (RootPtr->Key == K) { // nalezl uzel s klicem K *Content = RootPtr->BSTNodeCont; return TRUE; } else { if ( K < RootPtr->Key) { // K je mensi nez aktualni klic -> dal hledam v leve vetvi if (BSTSearch(RootPtr->LPtr, K, Content) ) { return TRUE; } else { return FALSE; } } else { // K je vetsi nez aktualni klic -> dal hledam v prave vetvi if (BSTSearch(RootPtr->RPtr, K, Content)) { return TRUE; } else { return FALSE; } } } } else { return FALSE; } }
int test_BSTSearch(tBSTNodePtr TempTree, char K, int *Content) { solved=TRUE; int FOUND=FALSE; FOUND=BSTSearch(TempTree,K,Content); if (!solved) { printf("Operace BSTSearch() nebyla implementovana \n"); return(FALSE); } else { if(!FOUND) printf("Polozka nebyla nalezena !\n"); else { printf("Polozka byla nalezena !\n"); printf("Polozka obsahuje hodnotu %d \n", *Content); } return(TRUE); } }
void *BSTGetPrev (BST b, void *i, int ivalue) { BST a; if (ivalue == ITEM) { a = BSTSearch(b,(Item)i); } else { a = (BST)i; } if (a==NULL) { return NULL; } if (a->l != NULL) { for (a=a->l;a->r!=NULL;a=a->r); return a->itm; } for (;a->parent->r!=a;a=a->parent); return a->parent->itm; }
void main(){ BiTree T=NULL,p; DataType table[]={37,32,35,62,82,95,73,12,5}; int n=sizeof(table)/sizeof(table[0]); DataType x={73},s={32}; int i; for(i=0;i<n;i++) BSTInsert(&T,table[i]); printf("中序遍历二叉排序树得到的序列为:\n"); InOrderTraverse(T); p=BSTSearch(T,x); if(p!=NULL) printf("\n二叉排序树查找,关键字%d存在\n",x.key); else printf("查找失败!\n"); BSTDelete(&T,s); printf("删除元素%d后,中序遍历二叉排序树得到的序列为:\n",s.key); InOrderTraverse(T); printf("\n"); system("pause"); }
void BSTDelete (BST b, Item i) { BST a; Item c; a = BSTSearch(b,i); if (a->l == NULL && a->r == NULL) { if (a->parent->l==a) { a->parent->l = NULL; } else { a->parent->r = NULL; } } else if (a->l == NULL && a->r != NULL) { if (a->parent->l==a) { a->parent->l = a->r; } else { a->parent->r = a->r; } a->r->parent = a->parent; //a = a->r; } else if (a->l != NULL && a->r == NULL) { if (a->parent->l==a) { a->parent->l = a->l; } else { a->parent->r = a->l; } a->l->parent = a->parent; //a = a->l; } else { c = BSTGetNext (NULL,(void*)a,BINSER); BSTDelete (b, c); a->itm = c; } }
int localDecl() { //za decl nebrat token if ((error = testToken(T_ID)) != E_OK) return error; //ID if (searchParam(paramlist, &(T.s)) != NULL){ //zde budu muset nejspis dat jen jmenu aktualni fkce return E_SEMA; } if(strCmpstring(&(T.s), &ActFun) == 0){ //ADDED return E_SEMA; } if(BSTSearch (TempTreeL, T.s) != NULL){ return E_SEMA; } strInit(&IDstr); strCopystring(&IDstr, &T.s); gettoken(); if ((error = testToken(T_COLON)) != E_OK) return error; gettoken(); if ((error = testToken(T_DATATYPE)) != E_OK) return error; // typ /******************************************INSERT***************************************************************/ if(!(strCmpConstStr(&(T.s), "boolean"))) TempVar->type = O_BOOL; if(!(strCmpConstStr(&(T.s), "integer"))) TempVar->type = O_INT; if(!(strCmpConstStr(&(T.s), "real"))) TempVar->type = O_REAL; if(!(strCmpConstStr(&(T.s), "string"))){ TempVar->type = O_STRING; strInit(&TempVar->value.sval); } BSTInsert (&TempTreeL, IDstr, TempVar); /******************************************INSERT***************************************************************/ gettoken(); if ((error = testToken(T_SEMICOLON)) != E_OK) return error; // ";" gettoken(); //strFree(&IDstr); if (testToken(T_ID) == E_OK) if ((error = localDecl()) != E_OK) return error; //dalsia promena? return E_OK; }
int main(void) { BTreeNode* bstRoot; BTreeNode* sNode; BSTMakeAndInit(&bstRoot); BSTInsert(&bstRoot, 5); BSTInsert(&bstRoot, 8); BSTInsert(&bstRoot, 1); BSTInsert(&bstRoot, 6); BSTInsert(&bstRoot, 4); BSTInsert(&bstRoot, 9); BSTInsert(&bstRoot, 3); BSTInsert(&bstRoot, 2); BSTInsert(&bstRoot, 7); BSTShowAll(bstRoot); printf("\n"); sNode = BSTSearch(bstRoot, 1); if(sNode == NULL) printf("search fail!\n"); else printf("key : %d\n", BSTGetNodeData(sNode)); printf("-------------------------------------------\n"); sNode = BSTSearch(bstRoot, 4); if(sNode == NULL) printf("search fail!\n"); else printf("key : %d\n", BSTGetNodeData(sNode)); printf("-------------------------------------------\n"); sNode = BSTSearch(bstRoot, 6); if(sNode == NULL) printf("search fail!\n"); else printf("key : %d\n", BSTGetNodeData(sNode)); printf("-------------------------------------------\n"); sNode = BSTSearch(bstRoot, 7); if(sNode == NULL) printf("search fail!\n"); else printf("key : %d\n", BSTGetNodeData(sNode)); printf("-------------------------------------------\n"); BSTShowAll(bstRoot); printf("\n"); sNode = BSTRemove(&bstRoot, 3); free(sNode); printf("Remove 3-------------------------------------------\n"); BSTShowAll(bstRoot); printf("\n"); sNode = BSTRemove(&bstRoot, 8); free(sNode); printf("Remove 8-------------------------------------------\n"); BSTShowAll(bstRoot); printf("\n"); sNode = BSTRemove(&bstRoot, 1); free(sNode); printf("Remove 1-------------------------------------------\n"); BSTShowAll(bstRoot); printf("\n"); sNode = BSTRemove(&bstRoot, 6); free(sNode); printf("Remove 6-------------------------------------------\n"); BSTShowAll(bstRoot); printf("\n"); return 0; }
void PollingWorker::PollRS232() { char * readBuf; char * rawByte; char * unCompressed; Header * headerBuffer; Item * sender; long numBytesToGet; char receiveID; DWORD dwCommEvent, dwBytesTransferred; Msg * newMsg; isFinish = 0; while(!isFinish) { SetUpDCB(baudRate); // set up the mask, EV_RXCHAR is the event when we receive a character if (!SetCommMask(hComm, EV_RXCHAR)) emit error(QString("Error setting communications mask."), (int)GetLastError()); // wait for a character to come in if (!WaitCommEvent(hComm, &dwCommEvent, NULL)) emit error(QString("Error waiting for a character."), (int)GetLastError()); // we have a character, read the header to see if its good else { if(!isRaw->isChecked()) { // set up the header buffer if(!(headerBuffer = (Header *)malloc(sizeof(struct Header)))) emit error(QString("Error malloccing headerBuffer."), (int)GetLastError()); // get the header if(!ReadFile(hComm, (BYTE *)headerBuffer, HEADERSIZE, &dwBytesTransferred, 0)) emit error(QString("Error getting the header buffer."), (int)GetLastError()); if(headerBuffer->lSignature == 0xDEADBEEF) { // get the data length from the header numBytesToGet = headerBuffer->lDataLength; readBuf = (char*)calloc(numBytesToGet,sizeof(char)); if (readBuf == NULL) emit error(QString("Error mallocing readBuf."), (int)GetLastError()); // get the message if(!ReadFile(hComm, readBuf, numBytesToGet, &dwBytesTransferred, 0)) emit error(QString("Error getting the message."), (int)GetLastError()); emit error(QString("Bytes gotten"), (int)(dwBytesTransferred)); unCompressed = readBuf; // calculate the checksum and compare if(headerBuffer->sChecksum != CalculateChecksum(readBuf, headerBuffer->lDataLength)) { emit transmitError(); //emit error (QString ("Checksum reports errors"),0); } if (headerBuffer->bVersion == 0xFF) { if(!(unCompressed = (char *)calloc(headerBuffer->lDataUncompressed,sizeof(char)))) emit error(QString("Error malloccing unCompressed."), (int)GetLastError()); Huffman_Uncompress((unsigned char*)readBuf, (unsigned char*)unCompressed, headerBuffer->lDataLength, headerBuffer->lDataUncompressed); // For testing purposes. emit error (QString("We have a Huffman buffer."),0); }else if (headerBuffer->bVersion == 0xF0) { if(!(unCompressed = (char *)calloc(headerBuffer->lDataUncompressed,sizeof(char)))) emit error(QString("Error malloccing unCompressed."), (int)GetLastError()); unCompressed = RunLengthDecode(readBuf, headerBuffer->lDataLength); // For testing purposes. emit error (QString("We have an RLE buffer."),0); }else if (headerBuffer->bVersion == 0x0F) { if(!(unCompressed = (char *)calloc(headerBuffer->lDataUncompressed,sizeof(char)))) emit error(QString("Error malloccing unCompressed."), (int)GetLastError()); unCompressed = (char*)DifferentialExpand(readBuf, headerBuffer->lDataLength); // For testing purposes. emit error (QString("We have a Differential buffer."),0); } else emit error (QString("We have an uncompressed buffer."),0); receiveID = GetReceiverId(headerBuffer->lReceiverAddr); if (headerBuffer->bDataType == 0) { // If the data is text. // create a new message structure and put it on the queue // not all the header options we need are available - ask Jack! if(!(newMsg = (Msg *)malloc(sizeof(struct message)))) emit error(QString("Error malloccing newMsg."), (int)GetLastError()); strcpy(newMsg->txt, unCompressed); newMsg->senderID = headerBuffer->bSenderAddr; newMsg->receiverID = (short)receiveID; newMsg->msgNum = rand() % 100; newMsg->priority = headerBuffer->bPriority; AddToQueue(newMsg); // Check if the senderID has already been created. If not, create one. if ((sender = BSTSearch(root, headerBuffer->bSenderAddr))== NULL) { Item * newItem = (Item*)(malloc (sizeof(Item))); int * count = (int*)(malloc (sizeof(int))); *count = 1; newItem->key = headerBuffer->bSenderAddr; newItem->data = count; root = BSTInsert(root,newItem); } else // If it has been created, increment *((int*)sender->data) = *((int*)sender->data) + 1; emit labelEdit(QString("Number of Messages: %1").arg(numberOfMessages)); } else { // we have audio, emit the data, the length of the data, and the sample rate emit audioReceived(headerBuffer->lDataUncompressed, unCompressed, headerBuffer->sSamplesPerSec); } } } else { // in raw mode, just grab chunks of bytes as they come do { if(!(rawByte = (char *)calloc(1, sizeof(char)))) emit error(QString("Error malloccing rawByte."), (int)GetLastError()); if(!ReadFile(hComm, rawByte, 1, &dwBytesTransferred, 0)) emit error(QString("Error getting the raw data."), (int)GetLastError()); if(dwBytesTransferred != 0) emit messageEdit(*rawByte); }while(dwBytesTransferred != 0); } } } emit finished(); }
int commands() { tVariable *glob = NULL; tVariable *loc = NULL; tParamList *par = NULL; string *name = allocate(sizeof(string)); tTapeItem *previous = Tape->last; tVariable *op1 = allocate(sizeof(tVariable)); tVariable *op2 = allocate(sizeof(tVariable)); tVariable *result = allocate(sizeof(tVariable)); if((name == NULL) || (op1 == NULL) || (op2 == NULL) || (result == NULL)) return E_INTERN; switch(T.type){ case T_ID: /* if(afun == 1){ //ADDED pokud neni ve funkci kontroluje jen global if ((par = searchParam(paramlist, &(T.s))) == NULL){ //added if(strCmpstring(&(T.s), &ActFun) != 0){ //zde budu muset nejspis dat jen jmenu aktualni fkce if((loc = BSTSearch (TempTreeL, T.s)) == NULL){ if((glob = BSTSearch (TempTree, T.s)) == NULL){ return E_SEMA; }*/ // else{ // Tape->last->op1 = glob; // } // } // else{ // Tape->last->op1 = loc; // } // } // else{ // Tape->last->op1 = item; // } //} // else{ // Tape->last->op1 = par; // } // } /* else {*/ if((glob = BSTSearch (TempTree, T.s)) == NULL){ return E_SEMA; } /*else{ Tape->last->op1 = glob; }*/ //} gettoken(); if ((error = testToken(T_ASSIGN)) != E_OK) return error; if ((error = ExpParser()) != E_OK) return error; //if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = ASSIGN; if (loc != NULL){ Tape->last->op1 = loc; } else if (glob != NULL){ Tape->last->op1 = glob; } if (res != Tape->last->op1->type ) return E_SEMB; Tape->last->op2 = Tape->last->previous->result; Tape->last->result = Tape->last->op1; printf("parser adresa resultu v parseri %d \n",Tape->last->op2); if ((strCmpConstStr (&(T.s), "end"))) { if ((error = testToken(T_SEMICOLON)) != E_OK) return error; semi = 1; } break; case T_KEYWORD: if(!strCmpConstStr (&(T.s), "begin")){ gettoken(); if((error = blockList()) != E_OK) return error; gettoken(); if ((strCmpConstStr (&(T.s), "end"))) { if ((error = testToken(T_SEMICOLON)) != E_OK) return error; semi = 1; } break; } if(!strCmpConstStr (&(T.s), "if")){ //if tTapeItem *label; tTapeItem *endelse; tVariable *op11 = allocate(sizeof(tVariable)); tVariable *op22 = allocate(sizeof(tVariable)); if((op11 == NULL) || (op22 == NULL)) return E_INTERN; if((error = ExpParser()) != E_OK) return error; //vyraz if (res != 3 ) return E_SEMB; //ZAKONECNTOVANO if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = JUMPN; Tape->last->op1 = Tape->last->previous->result; Tape->last->op2 = op2; Tape->last->op2->type = TAPE_POINTER; label = Tape->last; if((error = testToken(T_KEYWORD)) == E_OK){ if(strCmpConstStr (&(T.s),"then")) return E_SYN; //then } else return error; gettoken(); if((error = testToken(T_KEYWORD)) == E_OK){ if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu } else return error; gettoken(); if((error = blockList()) != E_OK) return error; //blocklist gettoken(); Tape->last->instruction = JUMPN; Tape->last->op1 = op11; Tape->last->op1->type = O_BOOL; Tape->last->op1->value.bval = false; if(strInit(&(Tape->last->op1->name)) != STR_SUCCESS) return E_INTERN; Tape->last->op2 = op22; Tape->last->op2->type = TAPE_POINTER; endelse = Tape->last; if((error = testToken(T_KEYWORD)) != E_OK) return error; if(strCmpConstStr (&(T.s),"else")) return E_SYN; if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = NOP; label->op2->value.tape_pointer = Tape->last; gettoken(); if((error = testToken(T_KEYWORD)) != E_OK) return error; if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu gettoken(); if((error = blockList()) != E_OK) return error; //blocklist gettoken(); if ((strCmpConstStr (&(T.s), "end"))) { if (testToken(T_SEMICOLON) != E_OK) return E_SYN; semi = 1; } if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = NOP; endelse->op2->value.tape_pointer = Tape->last; break; } if(!strCmpConstStr (&(T.s), "while")){ if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = NOP; tTapeItem *label1; tTapeItem *label2 = Tape->last; // ukazatel na pasku kam se bude cyklus vracet tVariable *op11 = allocate(sizeof(tVariable)); tVariable *op22 = allocate(sizeof(tVariable)); if((op11 == NULL) || (op22 == NULL)) return E_INTERN; if((error = ExpParser()) != E_OK) return error; //vyraz if (res != 3 ) return E_SEMB; //ZAKONECNTOVANO if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = JUMPN; Tape->last->op1 = Tape->last->previous->result; Tape->last->op2 = op22; Tape->last->op2->type = TAPE_POINTER; label1 = Tape->last; if((error = testToken(T_KEYWORD)) == E_OK){ if(strCmpConstStr (&(T.s),"do")) return E_SYN; //begin slozeneho prikazu } else return error; gettoken(); if((error = testToken(T_KEYWORD)) == E_OK){ if(strCmpConstStr (&(T.s),"begin")) return E_SYN; //begin slozeneho prikazu } else{ return error; } gettoken(); if((error = blockList()) != E_OK) return error; //blocklist gettoken(); if ((strCmpConstStr (&(T.s), "end"))) { if ((error = testToken(T_SEMICOLON)) != E_OK) return error; semi = 1; } if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = JUMP; Tape->last->op1 = op1; Tape->last->op1->type = O_BOOL; Tape->last->op1->value.bval = false; if(strInit(&(Tape->last->op1->name)) != STR_SUCCESS) return E_INTERN; Tape->last->op2 = op2; Tape->last->op2->type = TAPE_POINTER; Tape->last->op2->value.tape_pointer = label2; // nepodmineny skok zpet na zacatek vyhodnocovani podminky cyklu if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = NOP; // instrukce, na kterou se skoci v pripade nesplneni podminky whilu label1->op2->value.tape_pointer = Tape->last; break; } if (!strCmpConstStr (&(T.s), "readln")) { gettoken(); if((error = testToken(T_LB)) != E_OK) return error; gettoken(); if((error = testToken(T_ID)) != E_OK) return error; if(afun == 1){ if(strCmpstring(&(T.s), &ActFun) != 0){ //added: Jmeno fkce, params, global, local if (searchParam(paramlist, &(T.s)) == NULL){ if((TempVar = BSTSearch (TempTreeL, T.s)) == NULL){ if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA; } } } } else{ if((TempVar = BSTSearch(TempTree, T.s)) == NULL) return E_SEMA; } if (TempVar->type == O_BOOL){ TempVar = NULL; return E_SEMB; } gettoken(); if((error = testToken(T_RB)) != E_OK){ TempVar = NULL; return error; } gettoken(); if ((strCmpConstStr (&(T.s), "end"))) { if ((error = testToken(T_SEMICOLON)) != E_OK){ TempVar = NULL; return error; } semi = 1; } TempVar = NULL; break; } if (!strCmpConstStr (&(T.s), "write")) { //write(ID) !!! integer or real !!! gettoken(); if(InsertEmptyItemTape() != E_OK) return E_INTERN; Tape->last->instruction = JUMP; Tape->last->op1 = op1; Tape->last->op1->type = O_BOOL; Tape->last->op1->value.bval = false; if((error = testToken(T_LB)) != E_OK) return error; gettoken(); if((error = writefun()) != E_OK) return error; gettoken(); if ((strCmpConstStr (&(T.s), "end"))) { if ((error = testToken(T_SEMICOLON)) != E_OK) return error; semi = 1; } break; } default: return E_SYN; } return E_OK; }