You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a project that generates expressions and I've looked at a few options, built in AST support from go/token, go/constant, go/types is good but getting it do this auto conversion is a pain. I started writing my own AST then I found your project and thought it would be a great fit.
Here you state
All numeric constants and variables are converted to float64 for evaluation
This would require something like float64(int64(variable) & int64(otherVariable)) when evaluating these bitwise expressions.
For 10.5 | 20.2 to just work in your expression evaluator would be super amazing
I'm not sure what to say about ^ (power) vs ^ (xor) but I'm sure there is a good solution!
Cheers!
The text was updated successfully, but these errors were encountered:
These operators sound reasonable, but a note (and tests) will need to be made somewhere about the rounding strategy. If a user does 10.5 | 20.2, some might expect 10.5 to be rounded to 11 rather than truncated. Truncation makes the most sense, and if they want to round up they can do so before evaluation. But still needs tests/documentation somewhere (readme probably).
As for XOR, I backed myself a bit into a corner with that. I'm tempted to do an API break by turning ^ into XOR (to match C-style) and use ** for exponents (borrowing from Ruby).
I think for now I'd accept a PR that added |, &, and ~ (bitwise NOT) as new OperatorToken types, and a new TokenKind ("BITWISE") which evaluates before arithmetic operators. I'm not entirely sold on an API break for XOR (as mentioned above), and I'll have to look into other options. But at least with &, |, and ~ one can accomplish the same thing (even if it's a bit roundabout).
I probably won't be able to work on it this week, so if you (or anyone) would like to put together a PR with the above stuff, then I'd be down to accept it.
It would be great if this could support bitwise operations.
https://en.wikipedia.org/wiki/Bitwise_operation
https://golang.org/ref/spec#Arithmetic_operators
I'm working on a project that generates expressions and I've looked at a few options, built in AST support from
go/token
,go/constant
,go/types
is good but getting it do this auto conversion is a pain. I started writing my own AST then I found your project and thought it would be a great fit.Here you state
All numeric constants and variables are converted to float64 for evaluation
This would require something like
float64(int64(variable) & int64(otherVariable))
when evaluating these bitwise expressions.For
10.5 | 20.2
to just work in your expression evaluator would be super amazingI'm not sure what to say about
^
(power) vs^
(xor) but I'm sure there is a good solution!Cheers!
The text was updated successfully, but these errors were encountered: