Example #1
0
/**
* @brief analyseLine
* @param line Zeile für analyse
*/
void FileReport::analyseLine(string& line){
	int length = line.length();
	checkComment(line);
	for (int i = 0; i < length; ++i) {
		if (checkUpperCase(line[i])){
			continue;
		}
		if (checkLowerCase(line[i])){
			continue;
		}
		if (checkDigit(line[i])){
			continue;
		}
		checkSpecialCharacter(line[i]);
	}
	computeCommentDensity();
	lines++;
}
Example #2
0
void calculate(celula *stack, celula *headQueue){
	char token, z, y, x;
	int a, b, c;
	
	while (headQueue -> prox != NULL){
		token = dequeue(headQueue);
		
		if (checkDigit(token) == 1){//If token is operand
			push(stack, token);
		}
			
		else{  
			//If token is operator
			x = top(stack);
			pop(stack);
			y = top(stack);
			pop(stack);
			
			a = (int) (y) - 48;//Transform caracter to int
			b = (int) (x) - 48;
				
			if(token == '+') c = (a + b);
				
			else if(token == '-') c = (a - b);
				
			else if(token == '*') c = (a * b);
				
			else if(token == '/') {
				if(b != 0){
					c = (a / b);
				}
			}
			
			z = (char) (c+48);//Put the result as caracter in stack
			
			push(stack, z);
			
			
			}
	}
		
	printf("\n");
	printf ("Result = %c\n", top(stack)); 
}
Example #3
0
void inToPos(celula *stack, celula *headQueue, celula *tailQueue, char *list){
		int i=0;
		celula *topStack, *hQueue;
		
		
		
			//( = 2 / num = 1 / + AND - = 3 / * AND / = 4 , ) = 5
			while(list[i] != '\0'){
			//If token is an operator and is not parentheses
				if((checkDigit(list[i]) != 1) && (checkDigit(list[i]) != 2 && checkDigit(list[i]) != 5)){
					//While not empty stack and precedence of top stack > precedence of caracter in list
					while(stack->prox != NULL && (checkDigit(top(stack)) >= checkDigit(list[i]))){
						
						//Enqueue top stack
						enqueue(headQueue,tailQueue, top(stack));
						pop(stack);//Remove it from the top
						
					}
					
					
					push(stack, list[i]);//Puts the caracter on the top of stack
					
				}
				
				else{
					//If operator is parentheses
					if(checkDigit(list[i]) == 2 || checkDigit(list[i]) == 5){
						if(checkDigit(list[i]) == 5){//If operator is closes parentheses
							while(checkDigit(top(stack)) != 2){//While top stack is not open parentheses
								enqueue(headQueue,tailQueue, top(stack));//Enqueue top stack
								pop(stack);//Remove it from the top
							
							}
							pop(stack);//Just discard the open parentheses
						}
						
						else{//If not closes parentheses put it on the stack
							push(stack, list[i]);
						}
					
					}
				
					else{//If not parentheses enqueue the caracter
						enqueue(headQueue,tailQueue, list[i]);
					}
				}
				
				i++;//Increment control vector variable
				
			}
	
	//Removes the last operand from the stack
	enqueue(headQueue,tailQueue, top(stack));
	pop(stack);
	
	topStack = stack->prox;
	hQueue = headQueue -> prox;
	
	printf("Heap\n");
	
	while(topStack != NULL){
				printf("%c ", topStack -> cont);
				topStack = topStack->prox;
			}
			
	printf("\n");
	printf("Queue\n");
			
	while(hQueue != NULL){
				printf("%c ", hQueue->cont);
				hQueue = hQueue->prox;
			}
			
	printf("\n");
}