Does anyone have a link to a good simple Rules Engine pattern that can be implemented in javascript? I am interested in doing this for the SheetWorker, since the pathfinder sheet has several places to allow players to enter their own macros (no die rolls, just calculations for abilities such as n uses per y levels etc) I have built rules engines in the distant past (at least 10 years ago), and hooked up other rules engines to other products. I am not sure if it's worth it in this case, but I'm thinking it may be a fun exercise as long as it ends up not too slow. The search/replace attributes is easy enough, which I detailed here , I am trying to determine a good method / pattern for parsing the grammar. I am thinking: first replace all [[ and ]] with ( and ) so it's more of a simple math equation, Then for each () group, treat that as a node related to each other by the operand. I guess that means the operands are the internal nodes. And the arguments would be the leaf nodes. say we have (A + B * C)/2 travelling left to right method I'm thinking of would be: for each set of () use recursion to go down a level just to make it easier instead of loops. each time we have to save the current parent operand of this iteration/recursion, plus the last leaf node read (last argument/number). Hit ( so save it (implementation: call same method with string between ( ) ?) A + B : simple 3 node: create a + node, with A and B as leaf. if A + B + C: if next operand is same then set C.parent = b.parent. if A + B - C if next operand is different but same precedence, keep order (it probably matters, simplest to just keep order), so set: +.parent = -, C.parent = -. if A + B * C if next operand is higher precedence, replace B node with that operand: *.parent = B.parent, B.parent=*, C.parent=* Hit closing ) so go back up to highest node of () which would be the +. (i.e. return + in 1st and 3rd example, - in 2nd example) () / 2 : simple 3 node again +.parent=/ 2.parent=/ other operands like floor, abs, would have only one child node. the 4 arithmetic operands could have n child nodes. kl1 kh1 also have n child nodes.