Original Post
Greetings,
I am trying to design a C-like scripting language of my own, and I have a problem now. This is about the ambiguity of unary and binary minus operators. My regular expression for numbers is:
digit = [0-9]
nat = digit+
singedNat = (+|-)?nat
number = signedNat(¡°.¡±nat)?(E signedNat)?
This can represent both integers and floating point numbers. However, note that there is the unary minus operator in the regular expression, problems occur. To see how that happens, consider the following expression:
a = 1-1.5;
b = 1- -1.5;
The first minus operator in the first statement is binary, and the first minus operator in the second statement is binary too, but the sencond one is unary. How can the scanner tell the difference?
Any suggestions about this very welcome! Thanks in advance.