You can actually do it in the same way with event as you can with code. I've done it a few times. The last one was here:
r0j0-s-experiments_p955579?#p955579
Most of it was syntax error checking though.
Basically it grabs a token at a time from the string while skipping over spaces. regex could have been used to assist with that but I opted not to use it. After that it gives me a list of tokens which i then feed into this:
https://en.wikipedia.org/wiki/Shunting-yard_algorithm
Which converts it to reverse polish notation, while preserving the order of operations. Then it becomes simple to eval from left to right. I didn't get around to implementing variables here, but it was on paper.
The main drawback is it can be a lot of events.
Magistross' suggestion would be by far the simplest. Although you wouldn't have control over what js code was run.