0

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.

2
  • In principle my "reduced parser" uses such a operator table: github.com/axkr/symja-parser/blob/master/symja-parser/src/main/… but it's not a general framework at the moment. – axelclk Nov 5 '17 at 18:11
  • Thank you, but what I really need is a framework in Java. Given what you've done I can tell you know what it is that I'm looking for and am a bit surprised that it doesn't exist. I'll put it on my list of things-to-do and self answer... since it isn't a pressing concern perhaps within 6 months. – Quaternion Nov 8 '17 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.