Implementing a "calcuator" feature

S

Sonny Chee

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.
 
J

Jeremy Tregunna

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top