I stumbled upon Pratt (or operator precedence) parsing via this (chapter 17):

http://craftinginterpreters.com/a-bytecode-virtual-machine.htmland

http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/He explains it very well, and I managed to translate the c-code (from the 1st link) to Free Pascal. I also added a view challenges, e.g. usage of interpolated strings, such as:

var drink = "tea";

var steep = 4;

var cool = 2;

print "Yes, $(drink) will be ready in $(steep + cool) minutes.";

and really cool, added anonymous (lambda) functions, so that you can do the following:

// calculates the integral of a function over the interval a..b in n steps

fun integral(f, a, b, n) {

var sum = 0;

var dt = (b-a)/n;

for (var x = 0; x<n; x=x+1) {

sum = sum + f(a+(x+0.5)*dt);

}

return sum*dt;

}

// using arrow notation

print integral(fun(x)->x*x-2*x+4, 0, 1, 10000);

print integral(fun(x)->sqrt(1-x*x), -1, 1, 10000); // 1/2 PI

Attached the pascal code + tests