Negative numbers disallowed?

Negative numbers disallowed?

Without the unary operator one cannot enter negative numbers without introducing additional complexity in the lexer/parser. For example: var m1 = -1;The "-1" can be thought of as a negative constant, but if the lexer assumes that, so you get problems with: var m2 = 2-1;Which would be lexed as number(2) number(-1) and a syntax error, as opposed to the correct number(2) operator(-) number(1).Can we conclude that there are therefore no negative numeric constants?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

That would be my read. "Negative constants" can always be expressed as a operation with 0.Example:var m1 = 0 - 1;

In general, '-' is treated as operator not a part of any number. In later example, it would be lexed as NUMBER OPERATOR NUMBER. Token in lexer and syntax in parser have to be defined in a way so that it happens that way.

As we don't have unary operator support in the parser, please consider that negative numbers aren't allowed/ supported.


If we see one is it OK to process it instead of issuing an error?

Leave a Comment

Please sign in to add a comment. Not a member? Join today