Math parser based on Lukasz Wrobel's blog post