double solveEq(List *list) { int a = 0, b = 0; int left = 1; int first = 1; while (list != NULL) { if (left) { // If first number from the left side of the equation, number gets added to a or b if (first) { if (acceptNumber(&list)) { if (list -> next !=NULL && acceptIdentifier(&list -> next)) { a += list -> token.number; list = list -> next; } else { b += list -> token.number; } } first = 0; } // If '=' symbol is met, change the condition rules if (acceptSymbol('=', &list)) { left = 0; first = 1; } // If + num [x] is met, number gets added to either a or b if (acceptSymbol ('+', &list) && acceptNumber(&list -> next)) { if (list -> next -> next !=NULL && acceptIdentifier(&list -> next -> next)) { a += list -> next -> token.number; list = list -> next -> next; } else { b += list -> next -> token.number; list = list -> next; } } // // If - num [x] is met, number gets subsracted from either a or b if (acceptSymbol ('-', &list) && acceptNumber(&list -> next)) { if (list -> next -> next !=NULL && acceptIdentifier(&list -> next -> next)) { a -= list -> next -> token.number; list = list -> next -> next; } else { b -= list -> next -> token.number; list = list -> next; } } } if (!left) { // If first number from the right side of the equation, number gets substracted from either a or b if (first) { if (acceptNumber(&list)) { if (list -> next != NULL && acceptIdentifier(&list -> next)) { a -= list -> token.number; list = list -> next; } else { b -= list -> token.number; } first = 0; } } // If + num [x] is met, number gets substracted from either a or b if (acceptSymbol ('+', &list) && acceptNumber(&list -> next)) { if (list -> next -> next !=NULL && acceptIdentifier(&list -> next -> next)) { a -= list -> next -> token.number; list = list -> next -> next; } else { b -= list -> next -> token.number; list = list -> next; } } // If 0 num [x] is met, number gets added to a or b if (acceptSymbol ('-', &list) && acceptNumber(&list -> next)) { if (list -> next -> next !=NULL && acceptIdentifier(&list -> next -> next)) { a += list -> next -> token.number; list = list -> next -> next; } else { b += list -> next -> token.number; list = list -> next; } } } list = list->next; } printf("check 1\n"); return (-b / a); }