473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ummm...... how to evaluate the formulae??

if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?
Nov 14 '05 #1
10 1336

Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??


You can convert the algebraic expression to reverse polish notation.
Try searching for reverse polish notation. It is very effective with
computational expressions and parenthesis.
Try http://en.wikipedia.org/wiki/Reverse_Polish_notation

Nov 14 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8
Google for "recursive descent parser"
how to deal with the brackets??
That's part of what the parser does.
need to use stacks??
Perhaps. Or not, as your implementation requires.
Thx.......


?_?

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCE1wnagVFX4UWr64RAmueAKC7pvDB+wDo3KYuoTRUE3 Vnb5y4vwCgv3iE
lWW1zW5Dy21NDd/V9dE7DTw=
=yl+Y
-----END PGP SIGNATURE-----
Nov 14 '05 #3
Steven mentioned:
Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

You can convert the algebraic expression to reverse polish notation.
Try searching for reverse polish notation. It is very effective with
computational expressions and parenthesis.
Try http://en.wikipedia.org/wiki/Reverse_Polish_notation

icic,
so if I enters
1+3*4+2

it is
1 3 4 * + 2 +

right??
Nov 14 '05 #4
Lew Pitcher mentioned:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

Google for "recursive descent parser"

how to deal with the brackets??

That's part of what the parser does.

need to use stacks??

Perhaps. Or not, as your implementation requires.

Thx.......


?_?


THX~~
Nov 14 '05 #5
Mars wrote:
<RPN>
icic,
so if I enters
1+3*4+2

it is
1 3 4 * + 2 +

right??


Looks right to me.
Nov 14 '05 #6

Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?

RPN calculator (reverse polish notation)
I' ve got one implementaion with stach so fi you need it I can send you
by mail..

Nov 14 '05 #7


RPN calculator (reverse polish notation)
I' ve got one implementaion with stach so fi you need it I can send you by mail..


I mean stack! sorry

Nov 14 '05 #8
Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?


Try flex/bison, or write you own lexical analyser & parser.
http://www.gnu.org/software/bison/bison.html

If you dont know the basics of BNF/recursive descent you wont get far.

gtoomey
Nov 14 '05 #9


Gregory Toomey wrote:
Mars wrote:

if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?

Try flex/bison, or write you own lexical analyser & parser.
http://www.gnu.org/software/bison/bison.html

If you dont know the basics of BNF/recursive descent you wont get far.


These tools are surely overkill for so small a problem.
A stack and a precedence table will do the job just fine
and with less fuss. Two stacks if you want to evaluate at
the same time you're parsing.

--
Er*********@sun.com

Nov 14 '05 #10
si*****@inet.hr mentioned:
Mars wrote:
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?


RPN calculator (reverse polish notation)
I' ve got one implementaion with stack so fi you need it I can send you
by mail..

Great~
my email is : fa*******@gmail.com

Thx~
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Spiegel | last post by:
Hi all, Is it possible to have an uncompiled C# expression evaluated at runtime? I'd like to store an expression within an XML file then evaluate it when the time comes, something like: ...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
2
by: dam_fool_2003 | last post by:
Friends, I come across a resent thread describes the differences between getc() vs fgetc(). There some body stated the sentence "evaluate its parameter more than once". I cannot understand the...
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
5
by: Csaba Gabor | last post by:
In Firefox 1.5 (this question is Mozilla specific as I am using greasemonkey) I would like to be able to use document.evaluate to return the first TD entry that shows ^\s*MySearchText\s*$. As I...
2
by: Björn Langhof | last post by:
Hello. I want to evaluate a XPath-Expression only on a subtree of the whole xml-document. 1. I select a node of the XML-document 2. Then a want to select specific nodes below the node chosen...
1
by: shellon | last post by:
Hi all: when I use XPather(a firefox extension) to evaluate the expression: "/html/body/table/tbody/tr/td/table/tbody/tr/td/div/ul/li" it tells me there are 7 matching Nodes. but when I use...
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
6
by: qianz99 | last post by:
unsigned char buffer; I'd like to put the following hex value into this array 01 1D 28 05 08 00 13 F0 33 19 19 00 35 05 08 00 64 F0 64 46 46 00 09 Is it any easy way to do it? Thanks a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.