Skip to content
/ postfix Public

An interpreter for the PostFix language created by Turbak and Gifford

Notifications You must be signed in to change notification settings

rtoal/postfix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostFix

An interpreter for the Turbak and Gifford's language PostFix. PostFix is a stack-based language described in Chapter 1 of the book Design Concepts in Programming Languages.

The interpreter is written in Python 3, with a test suite runnable with py.test. After cloning this repo, run the tests with something like:

python3 -m pytest -s -v tests

You can run the interpreter from the command line. Supply the program as the first argument, with subsequent arguments (if any) comprising the initial stack (starting with the top element):

$ ./postfix '((mul sub) (1 nget mul) 4 nget swap exec swap exec)' -10 2
42

You can also invoke the interpreter from within Python code like so:

from interpreter import run
program = "((mul sub) (1 nget mul) 4 nget swap exec swap exec)"
run(command, -10, 2)
# => 42

About

An interpreter for the PostFix language created by Turbak and Gifford

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages