Ah, I understand.
The problem is how you are thinking about it. A minus sign is
always an operator. Yep. Always.
Between two numbers it is a
binary operator:
12 - 5
But when only prefixing a number, it is a
unary operator:
- 5
12 + - 5
(which is the same as
0 - 5 and
12 + (0 - 5).)
So, the question becomes, "how do I know the difference?"
The way to tell is by knowing what kind of thing you expect to read next: is it a number or an operator? If you are expecting an operator and you get a minus sign, then it is a binary operator. If you are expecting a number and you find a minus sign, then it is a unary operator. You can always know what to expect next:
12 - 5
↑ ↑ ↑
│ │ number
│ operator
number
It is always 'number, operator, number', in that order. A 'number' may itself be a more complex expression...
Here's a good page on parsing mathematical expressions using recursive-descent:
http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
I don't know how extensive your homework assignment is, but this probably goes a little deeper than you need. It is the principle that is important as you implement your expression parser.
Hope this helps.