Simple Stack Machine
written by Teresa Carrigan
- What is it?
- How it works
- How to use it
- Things to notice
- Things to try
- Extending the model
- NetLogo features
- Credits and References
- Run model in your browser
- Download the model
- Single webpage version
THINGS TO NOTICE
Every time you Push an item, the stack gets one more item on top. For every time you Pop, Add, Sub, Mul, or Div, the stack loses one item.What happens when you try to Pop and the stack is empty? What happens when you have a single item on the stack, and you try to Add? When you press Sub, how does the stack determine which item is subtracted?
THINGS TO TRY
Convert an arithmetic expression to Reverse Polish Notation (also known as postfix). Enter this RPN expression as a series of stack commands. The final result popped will be the normal infix equivalent of the expression. For example,C 4 + 3 A - *
would be entered as Push C, Push 4, Add, Push 3, Push A, Sub, Mul, Pop. What is popped should be (C + 4) * (3 – A).
HomeApplets on this website were written by Teresa Carrigan in 2004, for use in computer science courses at Blackburn College, with the exception of the Fireworks applet. The applets made with NetLogo require Java 1.4.1 or higher to run. The applets made with NetBeans require Java 1.4.2 or higher to run. Applets might not run on Windows 95 or Mac OS 8 or 9. You may obtain the latest Java plugin from Sun's Java site.