Skip to content

Latest commit

 

History

History
119 lines (91 loc) · 2.23 KB

File metadata and controls

119 lines (91 loc) · 2.23 KB

Scheme Interpreter

A Scheme programming language interpreter implemented in C++17.

Description

This project is an implementation of an interpreter for the Scheme dialect of Lisp.
It supports basic operations, functions, lambda expressions, and control structures.

Features

  • Basic operations: addition (+), subtraction (-), multiplication (*), division (/)
  • Data types: numbers, symbols, lists, booleans
  • Functions: lambda expressions and user-defined functions
  • Control structures: if, and, or
  • Scopes: local and global variable support
  • Interactive mode: REPL (Read-Eval-Print Loop)
  • Script execution: run Scheme programs from files

Build

Requirements

  • CMake 3.10 or higher
  • C++17-compatible compiler (GCC, Clang, MSVC)

Build Instructions

# Clone the repository
git clone https://github.com/Lawrence1947/Scheme.git
cd Scheme

# Create build directory
mkdir build
cd build

# Configure and build
cmake ..
make

# Run
./Scheme

Usage

Interactive mode

./Scheme

After launching, you’ll see the >>> prompt where you can enter Scheme expressions:

>>> (+ 2 3)
5
>>> (define x 10)
>>> (* x 5)
50
>>> (lambda (x) (+ x x))
(lambda-function)

Running from a file

./Scheme script.scm

The file should contain valid Scheme expressions, one per line.

Example Programs

Simple arithmetic

(+ 1 2 3 4 5)
(* 2 3 4)
(- 10 3)
(/ 15 3)

Variable definitions

(define x 42)
(define y (+ x 8))

Lambda functions

(define double (lambda (x) (+ x x)))
(double 5)

Conditional expressions

(if (> 5 3) #t #f)
(and (> 5 3) (< 2 4))

Error Handling

The interpreter supports multiple types of errors:

  • SyntaxError – syntax-related issues
  • RuntimeError – runtime execution errors
  • NameError – undefined variable or function references

Limitations

  • Only integer numbers are supported
  • Limited data type coverage
  • Basic standard library implementation

Future Plans

  • Floating-point number support
  • Strings and symbols
  • Vectors and arrays
  • Macros
  • Extended standard library
  • Performance optimization
  • Implement loops (for/while)