a simple expression parser
1 import unit_threaded; 2 3 auto parser = new ExprParser; 4 auto p = parser.expr(); 5 auto res = p.parse("1+2*3"); 6 res.success.shouldBeTrue; 7 res.results[0].get!double.shouldEqual(7); 8 9 res = p.parse("(1+2)*3"); 10 res.success.shouldBeTrue; 11 res.results[0].get!double.shouldEqual(9);
example of an expression parser. expr -> term { + term } term -> factor { * factor } factor -> number | ( expr )