I've created several infix to postfix implementations (shunting-yard algorithm) but find myself starting from scratch each time. I find it reasonable that someone has created a library or framework for this purpose. Sure you could go with full blown compiler techniques but there are a lot of expressions that I find myself wanting to evaluate without such and I find the shunting-yard sufficient.
//following is made up code just to illustrate what I'm looking for: OpperatorGroup opperators = new OpperatorGroup(); opperators.add( new Opperator("*",//opperator in string 3,//precedence LEFT,///associativity for which the direction in multiplication is arbitrary new CustomLeftAndRightOpperandEvaluator()));//evaluate right and left, or operate on just one side... //add a bunch more Evaluator eval = new Evaluator(opperators); String result = eval.evaluate(someString);//for which we can assume anything that isn't an opperator is an opperand, and if the string can't be parsed we give up, perhaps with a useful error.
Anyways does anyone know of such a shunting-yard framework for Java? I think it would be nice to essentially do a "fill in the blanks" and get a reasonable string evaluator.
Examples of infix to postfix in past projects: One was for a dice roller where 3+7d4*2 would be interpreted as: roll 7 four-sided dice, take their score, multiply by 2 and then add 3. Another implementation was a custom search language, well not so much custom but constrained to allow only the types of operators to act on the Database which I allowed terms such as "Near", "or", "and", etc.