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 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

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.

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

Thanks
-Rama

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

发表评论

登录添加评论。还不是成员?立即加入