I tried to make some syntax checker for arithmetic expressions. So, one of the negative tests is: No operator between variable(or constant) and left brace. Something like that:
if (expression.matches(".*[a-zA-Z|0-9]+\\(.*")) {
throw new IllegalArgumentException("Syntax error in the expression: " + expression);
}
But I need to use functions(like sin, cos etc.) in expressions in the following format: sin(number), so the test doesn't work, because the rule above says that some operator between "sin" and "(" is needed.
Is it possible to add exceptions in the rule above to use sin, cos, tan, cot, etc.? I mean something like (^sin|cos|tan|cot) Or do I need to edit the syntax rules in my regex at all?