[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Implementing a "calcuator" feature

Sonny Chee

1/21/2007 12:43:00 AM

Hey Guys,

Can someone recommend a fast but robust way to implement a calculator
feature? I want to allow my users the ability to enter simple agebraic
expressions and then press 'calc'.

My initial thought was to:

1) Check the expression for "bad words" and escapes by checking against
a black list.

2) Any expressions that pass step 1 are then evaluated with 'eval'.

Anyone have better ideas? In terms of the black list, does anyone know
how I can load the list of ruby reserved words without having to
actually type them all in by hand?

Soroe.

--
Posted via http://www.ruby-....

1 Answer

Jeremy Tregunna

1/21/2007 12:58:00 AM

0

On 20-Jan-07, at 7:42 PM, Sonny Chee wrote:

> Hey Guys,
>
> Can someone recommend a fast but robust way to implement a calculator
> feature? I want to allow my users the ability to enter simple agebraic
> expressions and then press 'calc'.
>
> My initial thought was to:
>
> 1) Check the expression for "bad words" and escapes by checking
> against
> a black list.
>
> 2) Any expressions that pass step 1 are then evaluated with 'eval'.
>
> Anyone have better ideas? In terms of the black list, does anyone
> know
> how I can load the list of ruby reserved words without having to
> actually type them all in by hand?

Why not just write a parser for algebraic expressions?

--
jer