473,396 Members | 2,020 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,396 software developers and data experts.

Implementing a fixed size stack for an RPN Calculator


I have implemented an RPN calculator in python but now I would like to
make the stack size fixed. how can I transform the user's RPN
expression from a stack overflow to a computable expression.

For instance, if my stack size is 2 then the some expression can't be
computed but could be transformed as following:

Non computable expression: 1 2 3 + + --stack size of 3 is needed
Computable expression: 1 2 + 3 + --stack size of 2 is needed

How can I define a formal way of transforming the non computable
expression to computable one.

My RPN only implements: + - x %

Sep 12 '07 #1
3 1979
On Wed, 12 Sep 2007 20:55:22 +0000, ra********@gmail.com wrote:
I have implemented an RPN calculator in python but now I would like to
make the stack size fixed. how can I transform the user's RPN
expression from a stack overflow to a computable expression.

For instance, if my stack size is 2 then the some expression can't be
computed but could be transformed as following:

Non computable expression: 1 2 3 + + --stack size of 3 is needed
Computable expression: 1 2 + 3 + --stack size of 2 is needed

How can I define a formal way of transforming the non computable
expression to computable one.

My RPN only implements: + - x %
Why does this homework assignment limit the stack so severely!? ;-)

Ciao,
Marc 'BlackJack' Rintsch
Sep 12 '07 #2
On Sep 12, 2:55 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Wed, 12 Sep 2007 20:55:22 +0000, rami.ma...@gmail.com wrote:
I have implemented an RPN calculator in python but now I would like to
make the stack size fixed. how can I transform the user's RPN
expression from a stack overflow to a computable expression.
For instance, if my stack size is 2 then the some expression can't be
computed but could be transformed as following:
Non computable expression: 1 2 3 + + --stack size of 3 is needed
Computable expression: 1 2 + 3 + --stack size of 2 is needed
How can I define a formal way of transforming the non computable
expression to computable one.
My RPN only implements: + - x %

Why does this homework assignment limit the stack so severely!? ;-)

Ciao,
Marc 'BlackJack' Rintsch

The problem is not with the stack being severely small or not, it
could be 1000 but it should be fixed and that's the limitation.

Sep 13 '07 #3
ra********@gmail.com schrieb:
On Sep 12, 2:55 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>On Wed, 12 Sep 2007 20:55:22 +0000, rami.ma...@gmail.com wrote:
>>I have implemented an RPN calculator in python but now I would like to
make the stack size fixed. how can I transform the user's RPN
expression from a stack overflow to a computable expression.
For instance, if my stack size is 2 then the some expression can't be
computed but could be transformed as following:
Non computable expression: 1 2 3 + + --stack size of 3 is needed
Computable expression: 1 2 + 3 + --stack size of 2 is needed
How can I define a formal way of transforming the non computable
expression to computable one.
My RPN only implements: + - x %
Why does this homework assignment limit the stack so severely!? ;-)

Ciao,
Marc 'BlackJack' Rintsch


The problem is not with the stack being severely small or not, it
could be 1000 but it should be fixed and that's the limitation.
It can't be fixed. You can algebraic rewrite expressions of the form

(a + (b + (c + d))

because of the commutativity of the +-operation to

(a+b) + (c + d)

and this can be done automatically.

But for arbitrary expressions, you will _always_ need arbitrary stack-sizes.

Diez
Sep 13 '07 #4

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

Similar topics

8
by: Ben | last post by:
Hi all, I implemented a stack in C++ in 2 different ways and I'd like to know which approach is better than the other.. and if there is any difference between the two? I'd also like to know if...
19
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
13
by: Ben R. Bolton | last post by:
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed. Is it possible to change the StackSize in .NET? If so how? Is it...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
9
by: Jensen Somers | last post by:
Hi, Is it possible to change the stack size of a DLL from within the source code? When using threads you can specify the size of the stack you want the thread to use, but since my application...
13
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one...
8
by: nickooooola | last post by:
Hello to all I'm about to write a simulator for a microcontroller in python (why python? because I love it!!!) but I have a problem. The registry of this processor are all 8 bit long (and 10...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.