Comments (7)
Just came across the same issue.
The error message I got was
"NoSuchMethodError: Class 'double' has no instance method '^'."
I first tried to define a '^' method with pow in the context, but it looks like the context is just for variables and functions, not for infix/binary operators.
In the end I got it working with a custom evaluator:
import 'dart:math';
class MyEvaluator extends ExpressionEvaluator {
const MyEvaluator();
@override
evalBinaryExpression(BinaryExpression expression, Map<String, dynamic> context) {
if (expression.operator == '^') {
final left = eval(expression.left, context);
final right = () => eval(expression.right, context);
return pow(left, right());
}
return super.evalBinaryExpression(expression, context);
}
}
from expressions.
Its already there i guess
case '^': return left ^ right();
Try a test case of 2^2 and see if it evaluates correctly
from expressions.
That's the bitwise XOR operator
https://en.wikipedia.org/wiki/Bitwise_operations_in_C#Bitwise_XOR_^
from expressions.
That will interfere with the bitwise XOR mentioned above. Also, you didn't set the precedence for the operator so the expression 5 * 3^2 gets evaluated as (5 * 3)^2
Check out my repo for a solution. I Used the ° sign as the exponent operator as i couldn't get ** to get parsed properly
https://github.com/malown/expressions
from expressions.
You can simply define a callMemberExpression like 'pow(2,2)'
from expressions.
For my usecase i need the expression to be easily readable by humans without using regex
from expressions.
Does someone have a solution for this?
Unfortunately @malown took all of their repositories down
and I have no clue on how to extend the code snippet above to make it work properly :(
from expressions.
Related Issues (20)
- ? in expression HOT 10
- What if I want to use a special match expression HOT 6
- Parsing RegEx as a variable in an Expression. HOT 5
- Power function HOT 2
- Support for the truncating division operator. (~/) HOT 1
- Use of async evaluator HOT 2
- Handle empty and contains HOT 4
- Leading and trailing spaces throw errors with Expression.parse HOT 2
- Handle assignment expressions HOT 1
- Call a method from object HOT 1
- flutter_simple_calculator >=2.0.0 depends on expressions ^0.2.3 which depends on petitparser ^4.0.2, HOT 3
- min/max function support HOT 1
- showing exponential number instead full number. please show full number. HOT 1
- Concat function HOT 1
- carriage return in expression ? HOT 2
- How to handle round function HOT 1
- type 'Null' is not a subtype of type 'Function'
- Change precedence of Operations
- The result is wrong when entering a number that is too large
- Parsing shift operations (<< and >>) fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressions.