zhenghaoz / SimpleScheme

A simple scheme interpreter implemented by C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SimpleScheme

SimpleScheme is a simple scheme interpreter implemented by C++ (C++11). It supports a subset of features of R5RS. The idea to develop such a project was inspired by SICP.

Compile and Run

The default compiler for this project is Clang and Boost Library, Bison, Flex is required. If you want to use GCC to compile this project, you have to modify makefile manually.

sudo apt-get install build-essential clang flex bison libboost-all-dev
git clone https://github.com/ZhangZhenghao/SimpleScheme.git
cd SimpleScheme/src
make
./build/main

We can enable log and statistic by setting variable OPTIONS:

make OPTIONS="-DLOG -DSTATS"

Test

make test

Or run driver.py in test directory. All test cases are included in test directory. A test case is considered passed if there is no error.

Features

  • Parse S expression using flex and bison
  • Implement evaluator using eval-apply model in SICP
  • Implement closure using the concept of environment
  • Implement garbage collection using mark-sweep algorithm
  • Implement tail recursion optimzation
  • Implement a few of primtive procedures
  • Compact with most codes in SICP

Types

  • Rational
  • Float
  • Symbol
  • String
  • Pair
  • Procedure

Expressions

  • define
  • set!
  • if
  • cond
  • let
  • and/or
  • lambda
  • begin
  • quote

Procedures

  • Check: number?, pair?, string?, etc.
  • Arithmetic: +,-,*,/,etc.
  • Comparation: <, >, =, <=, >=, etc.
  • Logic: not
  • Pair: cons, car, cdr, etc.
  • String: number->string, etc.
  • List: list, map, append, etc.
  • I/O: read, display, etc.
  • Debug: assert, assert=, etc.
  • Advenced: apply, eval, etc.

Note(Simplified Chinese)

About

A simple scheme interpreter implemented by C++

License:Apache License 2.0


Languages

Language:C++ 78.8%Language:Scheme 12.9%Language:Makefile 2.4%Language:Yacc 2.4%Language:Python 1.9%Language:Lex 1.6%