Page 1 of 1

[Staff] Expression Parser

Posted: Mon 23 Feb, 2009 3:19 am
by benryves
I've been working on a little expression parser over the weekend. Given an input string in the format

Code: Select all

.db "(-8>>2)+ceil(pi())+2**sqrt(abs((~0>>>(30|1))-(10>?1)))",0
it will produce a floating-point value (10 in this case). The internal number cruncher is BBC BASIC's FPP (so you would need BBC BASIC installed) and so all the features of BBC BASIC's FPP are provided either in the form of a function or an operator. The syntax is vaguely C-like with a few functions (min, max, pow) turned into operators (<?, >?, **) and a few additional operators (\ for integer division, >>> for an unsigned right shift).

I suspect the technique is more useful than the implementation (especially given the dependency on BBC BASIC), so would anyone find it useful if I wrote this up?

Edit: Apparently not. Here's an archive of the source with some documentation.

Re: [Staff] Expression Parser

Posted: Wed 25 Feb, 2009 11:38 pm
by Galandros
I was dreaming on making something like that. :p

I will see the code to see how is that made.