help needed regarding Scanner class
hello
i'm really desperate for help, i'll mention that this is homework,but i need a small guidance.
i need to code a calculator,we need to use the Scanner class to break the expression to tokens(we CANNOT use other classes).
my main problem is about getting those tokens from the input string.
i tried breaking a string to tokens for hours but just couldnt do it.
a legal expression is something like:
xyzavbx1111+log(abc11*(2+5))+sin(4.5)
iilegal is : xx333aaaa111+2 or log()+2
where the alphanumerics are variables(sequence of letters followed by numbers)
i managed to get the tokens out of a string that looks like that:
String expression = "ax11111+32/3+4*2^2"
by doing:
_token = new Scanner(expression);
while(hasNext(_token))getNextToken(_token,"\\d+(\\.\\d+)?|(\\+)|(\\-)|(\\*)|(\\/)|(\\^)|([a-zA-Z]+(\\d+));
public static boolean hasNext(Scanner s) {
return s.hasNext();
}
public static String getNextToken(Scanner s,String str) {
return s.findInLine(str);
}
but i can't get the tokens when i have sin ,cos or log in the expression
either it just ignores it or i'm looping infinitely.
my question is how can i make the regular expression include the sin log and cos?
I also know that when i'll use the "matches" method ,i'll be able to spot illegal arguments like 5//2+ because it doesnt match the pattern.
so any help conecrning the regular expression would be great thanks alot.

