Liste des Groupes | Revenir à cl c |
On 26.03.2025 23:15, Keith Thompson wrote:Having a single token like '-1234' is pointless. Most languages allow you to add parentheses like '-(1234)' which must give the exact same result.[ dyadic and monadic minus operations, and minus sign at literals ]I as well don't know. It may simplify things if the '-' is detached
>
I don't know of any language that uses "-" for both negation (prefix,
one operand) and subtraction (infix, two operands) and treats -5
as a single token rather than a unary minus operator applied to the
constant/literal "5".
from a numeric positive literal, especially for numeric expressions.
There's certainly cases where a signed numeric token is appropriate,
thinking (for example) about a CONST declaration in Pascal, like
CONST a = -5; here you don't have expressions, just the primitive
type literals.[*]
The point why I think that a signed literal as entity may be useful
is that it's a static (compile time) property; -5 is in that respect
different from -x, the negation operation. A negative constant does
not "cost" a run-time operation.
Given what we recently discussed about a division by a constant,
where compilers (may) handle expressions by pre-calculating the
reciprocal for run-time efficiency, it's not that clear to me that
it matters either way.
I suppose it's a question of whether it complicates syntax definition
or parsing.
Les messages affichés proviennent d'usenet.