Simple Stack Machine

written by Teresa Carrigan


Run model in your browser


Top

EXTENDING THE MODEL

Add another operator to the stack, such as exponentiation, or sin.

Add a memory bank, where variables may be pushed from, or popped to.

Change the stack machine so that instead of simply changing the label of an item, items always have numeric values and the expressions are evaluated.

Modify push to limit the number of items that can be pushed on the stack (to prevent wrapping).

Top

NETLOGO FEATURES

Several interesting NetLogo features were used in this model. The oper-random procedure uses random-one-of to select the name of a procedure to run, and then uses the run command to call the procedure. This is much cleaner than a series of nested ifelse statements to call the procedure chosen.

Each procedure that removes an item from the stack uses "ifelse any? node-at x y" to check that there is a node (the name of the breed used for items) at position x y.


Home

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