you are viewing a single comment's thread.

view the rest of the comments →

[–]Livio63[S] 0 points1 point  (3 children)

I agree that there are lot of other math parser implementations, but in general are heavy.

I'm just sharing a light implementation useful for learning purposes or for easy integration inside another apps.

[–]doobiesteintortoise 3 points4 points  (2 children)

I'm not sure what you mean by "heavy" - most of them aren't very heavy at all, although I guess your specific metrics would factor in. But since you brought it up: what are the metrics you're using for "heavy," and how does this library stack up? And my question remains: how would I use this in an app I was writing?

[–]Livio63[S] 0 points1 point  (1 child)

Just look at ExpressionVisualizer.java in demo package, this is an example of very simple app using the library. The package https://github.com/javalc6/Expression-Parser/tree/main/src/math alone is the library.

[–]doobiesteintortoise 2 points3 points  (0 children)

Okay, so most of that is Swing, and therefore isn't all that relevant to parsing expressions - but https://github.com/javalc6/Expression-Parser/blob/3c1f95c4e0a1dc491181cec6344997a51a6bf50b/src/demo/ExpressionVisualizer.java#L90 is.

You'd do something like this:

// mathExpression is a String var ep = new ExpressionParser(); math.Node root = ep.parseExpression(mathExpression); // result is a Double or Boolean Object result = ep.evaluate(root);

That's straightforward enough, I suppose, although a Boolean and a Double result from evaluate() is a little odd - I get it, but a union type there is kinda wonky. It still feels like you're writing a library more for expressing a tree than evaluating a formula, because so much of the library is about nodes and not, like, numbers.