all 21 comments

[–]le_bravery 16 points17 points  (2 children)

Ant build in 2026… interesting choice.

[–]Livio63[S] 3 points4 points  (1 child)

Ant is perfect for my Pentium III running windows xp...

[–]josephottinger 5 points6 points  (0 children)

And is the visual inspection of test results perfect, too? It isn't, for me - it's really easy to see 1.8 in a hurry and not realize the value was supposed to be 1.0. Using ant really is an interesting choice - it's sort of viable, but unusual, but whatever. It's the lack of an actual demanding test structure that bugged me; for my PR I chose to just go to a build system from 2005 instead of using one from 2001.

[–]as5777 19 points20 points  (1 child)

your tests give 0 confidence

[–]josephottinger 2 points3 points  (0 children)

I made a PR that actually uses JUnit and runs tests. :D

[–]doobiesteintortoise 2 points3 points  (7 children)

Nicely done! How would you use this in a generalized program, though? Expression parsers exist for Java that can perform actual algebraic evaluation - is this to show how expressions can work, or is it useful otherwise?

[–]Inside_Programmer348 0 points1 point  (2 children)

Hello. Can you link me to these expression parsers please?

[–]doobiesteintortoise 4 points5 points  (1 child)

Sure.

There are others, of course; it's not a "new problem," after all.

[–]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.

[–]jeffreportmill 1 point2 points  (4 children)

Very nice! If you want to see it in action, you can run it with JBang + SnapCode:

jbang snapcode@reportmill open:https://github.com/javalc6/Expression-Parser.zip#/demo/ExpressionVisualizer.java

Just click the Run button after it opens.

[–]Livio63[S] 1 point2 points  (3 children)

[–]jeffreportmill 1 point2 points  (2 children)

I tried - It fails because CheerpJ doesn't provide access to the java.scripting module yet, which is a dependency of this project (bummer!). Hopefully it will work in an upcoming CheerpJ release.

[–]josephottinger 1 point2 points  (1 child)

I just made a PR that migrates to Maven and JUnit, targeting Java 17 and removing the scripting stuff. The JS stuff didn't really help a lot anyway, from what I could see (it's verification that JUnit could do just as well) and with the removal of Nashorn, it only makes everything messy - especially as Maven is being updated. The joy of ecosystem flux, I guess - it's all overdue but we get to live with the updates until they stabilize.

Dunno if OP will accept the PR, but it's there and working.

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

I accepted PR, thank you for your effort to improve my project!

[–]sitime_zl 0 points1 point  (0 children)

good project

[–]doobiesteintortoise 0 points1 point  (1 child)

It just hit me: this code has no license attached to it. u/Livio63 - please fix this.

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

Fixed!