binary - operator (subtraction) and a unary - operator (negation)


how can i let the computer distinguish between a binary + operator (addition) and a unary + operator (identity) and between a binary - operator (subtraction) and a unary - operator (negation) ?


for example if i have -(-3--4)-5

the tokens would be:

negation negation 3 subtraction negation 4 subtraction 5 ?
For -(-3--4)-5 we would get an error.
The C++ parser is a greedy parser; the -- here is the prefix decrement operator.

This is fine: -(-3- -4)-5 and would be parsed as outlined in your post.
Topic archived. No new replies allowed.