Evald – a Lightweight Expression Evaluator for Java

This open source numeric evaluator library can be found on github at https://github.com/Ben-Mann/evald.


I think I wrote my first expression scripting interpreter when I was about fifteen – albeit on a Commodore 64, using my own scripting language, and with no real target audience or application in mind. Compilers, interpreters and languages were cool – and the Commodore 64’s built-in BASIC interpreter certainly inspired attempts at improvement. Many a future hacker and developer was born of an era when a computer was better described by its initial potential than usability.

I’ve written various types of expression parsers since, professionally, in multiple industries. Motivations varied: Off the shelf offerings were expensive and difficult to maintain, or open source offerings were bloated and glacial, or the particular use case dictated expressions and data handling that were simply unique. I’ve no doubt similar requirements will come up again, too.

In a recent project I had a commercial parser & evaluator component which was unnecessarily slow for what seemed to be a trivial and elementary use case. There were reasons: It was partly bloated because it was using existing general purpose frameworks for its parsing, or because it was handling complex numbers, vectors, matrices, strings, and other data types. But none of these were necessary for my use case. Knocking together something that satisfied my requirements (a fast, extensible math parser and evaluator) looked like it wouldn’t be rocket science and was something I’d done before (and a type of project from which, frankly, I derive an irrational glee).

I also wanted the freedom to reuse it, and having benefited from plenty of other open source projects in the past, release it in a way that benefits others similarly.

So enter evald – an open-source project on Github offering an extensible and fast tree-based expression parser & evaluator in Java. The library is very lightweight and requires no additional libraries (though if you need to run the tests, you’ll need junit). Hopefully the project page provides a good guide to its use.

If you use it I’d love to know, either here or on github. I’m very much a novice at creating open source projects (just trying to work out how ant works enough to make the build script work correctly almost made my brain explode), but it’s been a lot of fun putting this together. Though as with any project, polishing the last 10% seemed to take 90% of the time.

And why call it Evald? Well, finding a unique project name on github wasn’t as trivial as I thought it’d be, and it does fit the simple evaluator/double use case. Though every time I turn the word over in my mind I’m reminded of a line by Alfre Woodard from Star Trek: First Contact, when her character Lily is reminded that the antagonists were called the Borg:

Borg? Sounds Swedish.