Negative numbers disallowed?

Negative numbers disallowed?

Аватар пользователя john_e_lilley
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 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя DweeberlyLoom

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

Аватар пользователя Minh-Nhut Hong

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.

Аватар пользователя Rama Kishan Malladi (Intel)

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

Thanks
-Rama

Аватар пользователя john_e_lilley

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

Зарегистрируйтесь, чтобы оставить комментарий.