Hi I'm writing a program that parses a String into individual component as but when I try to test it out, I get an Out of Memory Error. I feel as if my for/while loops are infinite but I can't seem to find the reason why.
    //for loop to loop through char of string
    for(int i=0; i<expressionString.length(); i++) {
        //cast char into ascii int
        int ascii = (int) charAt(i);
        //appending to token if one of  singly operator symbols: *,/,(,),[,]
        if(ascii == 40 || ascii == 41 || ascii == 42 || ascii == 47 || ascii == 91 || ascii == 93){
            token.append((char) ascii);
            tokenList.add(token.toString());
        } //append if +, -
        else if(ascii == 43 || ascii == 45) {
            token.append((char) ascii);
            //check next char if + or /, if so append to token again
            int nextChar = (char) charAt(i+1);
            if(nextChar == 43 || nextChar == 45) {
                token.append((char) nextChar);
            }
            tokenList.add(token.toString());
        } //appending to token if it's a num
        else if ( ascii >= 48 || ascii <=57) {
            token.append((char) ascii);
            //check if next char is a num
            while ((int) charAt(i+1) >= 48 || (int) charAt(i+1) <= 57) {
                //increment i in for loop to check
                i++;
                token.append((int) charAt(i));
            }
            tokenList.add(token.toString());
        }
        //  
    }
Please let me know if this is an error with my code as I can't seem to detech where the problem is. Thank you!

 
     
    