https://github.com/codebox/scheme-interpreter
An interpreter for a basic subset of the Scheme programming language
https://github.com/codebox/scheme-interpreter
interpreter scheme scheme-programming-language
Last synced: 7 months ago
JSON representation
An interpreter for a basic subset of the Scheme programming language
- Host: GitHub
- URL: https://github.com/codebox/scheme-interpreter
- Owner: codebox
- License: mit
- Created: 2012-08-18T07:00:50.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-01-14T20:57:02.000Z (almost 10 years ago)
- Last Synced: 2023-03-11T21:48:13.391Z (almost 3 years ago)
- Topics: interpreter, scheme, scheme-programming-language
- Language: Python
- Homepage: http://codebox.org.uk/pages/scheme-interpreter-in-python
- Size: 4.88 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an interpreter for a sub-set of the Scheme programming language. It was written as a learning exercise, and should not be used for anything important.
To use the interpreter, write your Scheme code into a text file and run scheme.py, passing the file name and location as a
command-line argument, for example:
python scheme.py mycode.txt
The interpreter supports basic arithmetic and equality operators, conditional statements, the cons/car/cdr
list operations, define and lambda.
Each statement in the source file will be evaluated in turn, and any printable results will be displayed to standard output. A few
working Scheme programs and their resulting output are shown below:
(define factorial (
lambda (n) (
if (= n 1)
1
(* n (factorial (- n 1)))
)
)
)
(factorial 6)
720.0
(define fib (
lambda (n) (
if (< n 3)
1
(+ (fib (- n 1)) (fib (- n 2)))
)
)
)
(fib 10)
55.0
(define ackermann (
lambda (m n) (
if (= m 0)
(+ n 1)
(if (= n 0)
(ackermann (- m 1) 1)
(ackermann (- m 1) (ackermann m (- n 1))))
)
)
)
(ackermann 3 3)
61.0