JacquelineCasey / Nom

0 stars 0 forks source link

Unary negate and negative literals. #7

Open JacquelineCasey opened 1 year ago

JacquelineCasey commented 1 year ago

In principle, this is easy.

However, we need to be careful not to introduce ambiguity into the grammar, so likely we will only have a negate operator (and not negative literals). Then, as an AST transformation, we should fold a unary negate + literal into just a negative literal. This is a little tricky still, since ideally we do bounds-checking after we perform the fold. That would be before during type analysis though, so this is not a huge issue.

One test should be to construct the largest and smallest i64 values.

Type checking must be smart enough to know that unsigned integers cannot be negated.