[Coco] The Coco's first webserver, written in Basic09

William Astle lost at l-w.ca
Wed Dec 30 23:54:36 EST 2009


On 09-12-30 09:36 PM, Willard Goosey wrote:
> On Wed, Dec 30, 2009 at 04:49:21PM -0800, Wayne Campbell wrote:
>
>> 2*3+5/2
>>
>> is evaluated as
>>
>> 2*3/2+5, yielding a result of 8
>
> Are you sure that's not evaluted as (2*3)+(5/2)  which results in 8?
>>
>> To get the result of 5 (what we're looking for), it would have to be
>> written as
>
> I prefer languages where normal mathmatical precedence rules apply.

Which is why most languages apply them.

For anyone wanting to implement an expression evaluator, my advice is to 
think very carefully about just how important it is to do so. I am not 
just saying that to be glib, either.

Infix expression evaluation respecting operator precedence ("order of 
operations") is a miserably complex undertaking. I know this because I 
had to do it for LWTOOLS. I ended up with a pair of recursive 
co-routines - one to parse out individual terms, handle prefix operators 
(unary -), and parentheses and the other the general entry point and 
also the one that evaluates infix operators and disambiguates 
precedence. This is not a pleasant process, believe me. In fact, if you 
examine the color basic ROM, you will see that it uses the same 
mechanism to handle expression evaluation though it is substantially 
optimized.

It is true, however, that expression evaluation is a critical component 
in implementing any kind of language so if you can work it out, you're 
somewhere about 20% of the way done.

-- 
William Astle
lost at l-w.ca




More information about the Coco mailing list