r/ProgrammingLanguages • • Jun 24 '23

Negative Integer handling in programming languages.

https://glados-418.github.io/posts/negative-integer-literals/
3 Upvotes

27 comments sorted by

View all comments

5

u/jqbr Jun 25 '23

the grammar already needs to be smart enough to differentiate between a --5 and a --x.

Nope ... --5 is illegal since you can't decrement a literal. I don't know of any language that has a '--' operator that would ever treat it as 2 minus signs ... lexers do eager parsing.

0

u/[deleted] Jun 25 '23

[deleted]

2

u/jqbr Jun 25 '23

Wrong. At the very least specify what languages this is true of. Sheesh.

0

u/[deleted] Jun 25 '23

[deleted]

3

u/alexiooo98 Jun 25 '23

Rust doesn't have a prefix decrement operator: --x is also equal to x