Flasher Archive
[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]
Subject: | RE: FLASH: Complex calculator |
From: | Branden Hall |
Date: | Tue, 6 Jun 2000 17:24:25 +0100 |
Well, I hope you are decent with comp sci, cause this gets really technical
really quickly...
the best way I have been shown to do this kind of thing is to break the
objects down into a binary search tree... like as follows:
+
/ \
2 *
/ \
3 5
The actual parsing into the tree is the tough part, since once you have
the tree you just work your way up it from the bottom and you have your
answer... first of all you treat everything inside of parens as a single
entity and deal with them later...
For example...
5 * 8 + (6 + 4) * 2
First of all you look at it like this:
5 * 8 + X * 2
Then you go through and find the operator with the least precedence and make
it the root of the tree, in this case it would be the +.
Then you go to the left and right of this operator and look to see if there
is an operator there, if there is then again you look for the one with the
least precedense... then place those operators in the next nodes:
+
/ \
* *
You keep doing that last step until all you have left are numbers or place
holders for parens. Then place those into the tree where appropriate.
+
/ \
* *
/ \ / \
5 8 X 2
Then you go through the same steps with the symbols... and wa-la!
+
/ \
* *
/ \ / \
5 8+ 2
/ \
6 4
Its pretty complex I know... and its been a long time since I've done it so
its probably not very clear. Come to think of it.. .if you converted the
numbers to reverse-polish notation first it would probably be easier... by I
haven't touched RPN in a long time... sorry!
-= Branden J. Hall
-= Multimedia Developer / Instructor
-= Fig Leaf Software - "We've got you covered!"
Where you parse through the text and
-----Original Message-----
From: ownerchinwag [dot] com [ownerchinwag [dot] com]On">mailto:ownerchinwag [dot] com]On Behalf Of Anik
Rigaud
Sent: Tuesday, June 06, 2000 10:46 AM
To: flasherchinwag [dot] com
Subject: FLASH: Complex calculator
Hello,
I'm trying to put together a calculator complex enough to handle
parenthesis - i.e. in an expression going like this :
2 + (3 * 5)
It would handle the () operation before the others (and, btw, any * or /
operation before the others).
Any ideas where to start ?
Thanx in advance,
Anik =:)
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash Film Festival
July 24-26, 2000, NEW YORK CITY, Hammerstein Ballroom
Produced by United Digital Artists and lynda.com
Sponsored by Macromedia, Adobe Systems, Fusion, Inc, AtomFilms,
shockwave.com and Electric Rain.
www.flashforward2000.com + 1.877.4.FLASH.4
Register before June 15 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpchinwag [dot] com
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash� Film Festival
July 24-26, 2000, NEW YORK CITY, Hammerstein Ballroom
Produced by United Digital Artists and lynda.com
Sponsored by Macromedia, Adobe Systems, Fusion, Inc, AtomFilms,
shockwave.com and Electric Rain.
www.flashforward2000.com + 1.877.4.FLASH.4
Register before June 15 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpchinwag [dot] com
Replies
FLASH: Complex calculator, Anik Rigaud
[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]