All Projects → ridwanmsharif → lispy

ridwanmsharif / lispy

Licence: MIT license
LISP interpreter in Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to lispy

Cpython Internals
Dive into CPython internals, trying to illustrate every detail of CPython implementation
Stars: ✭ 3,084 (+9848.39%)
Mutual labels:  interpreter
Hackide
hackIDE is an online code editor, compiler and interpreter based on Django, powered by HackerEarth API! Go, hack it!
Stars: ✭ 242 (+680.65%)
Mutual labels:  interpreter
StepULC
Efficient and single-steppable ULC evaluation algorithm
Stars: ✭ 15 (-51.61%)
Mutual labels:  interpreter
Arturo
Simple, expressive & portable programming language for efficient scripting
Stars: ✭ 225 (+625.81%)
Mutual labels:  interpreter
Mond
A scripting language for .NET Core
Stars: ✭ 237 (+664.52%)
Mutual labels:  interpreter
Gobasic
A BASIC interpreter written in golang.
Stars: ✭ 253 (+716.13%)
Mutual labels:  interpreter
Awklisp
A Lisp interpreter written in Awk.
Stars: ✭ 214 (+590.32%)
Mutual labels:  interpreter
LLVM-JVM
[W.I.P] A Just-In-Time Java Virtual Machine written in Haskell
Stars: ✭ 22 (-29.03%)
Mutual labels:  interpreter
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+8938.71%)
Mutual labels:  interpreter
pythonvm-rust
An incomplete stackless interpreter of Python bytecode, written in Rust.
Stars: ✭ 65 (+109.68%)
Mutual labels:  interpreter
Hexagony
A two-dimensional, hexagonal programming language.
Stars: ✭ 228 (+635.48%)
Mutual labels:  interpreter
Tabloid
A minimal programming language inspired by clickbait headlines
Stars: ✭ 235 (+658.06%)
Mutual labels:  interpreter
Xstate
State machines and statecharts for the modern web.
Stars: ✭ 18,300 (+58932.26%)
Mutual labels:  interpreter
Swift Lispkit
Interpreter framework for Lisp-based extension and scripting languages on macOS and iOS. LispKit is based on the R7RS standard for Scheme. Its compiler generates bytecode for a virtual machine. LispKit is fully implemented in Swift 5.
Stars: ✭ 228 (+635.48%)
Mutual labels:  interpreter
wasm
A fast Pascal (Delphi) WebAssembly interpreter
Stars: ✭ 40 (+29.03%)
Mutual labels:  interpreter
Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: ✭ 2,623 (+8361.29%)
Mutual labels:  interpreter
Go Pry
An interactive REPL for Go that allows you to drop into your code at any point.
Stars: ✭ 2,747 (+8761.29%)
Mutual labels:  interpreter
sturdy
Sturdy is a library for developing sound static analyses in Haskell.
Stars: ✭ 49 (+58.06%)
Mutual labels:  interpreter
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀
Stars: ✭ 38 (+22.58%)
Mutual labels:  interpreter
NatsuLang
No description or website provided.
Stars: ✭ 96 (+209.68%)
Mutual labels:  interpreter

lispy

Interpreter for Scheme (A dialect of LISP) in Python. Contains two modules that cover tokenizing, parsing, loading environments and evaluating valid Scheme code input. Closely following Peter Norvig's implementation to get started. Covers primitive keywords and syntactic and procedure calls. A more complete LISP interpreter is what I hope to build on top of this and I intend to closely follow Norvig's thorough interpreter. I have worked independantly to include and cover features inpired by Racket (A dialect of Scheme) we'd been taught this past semester in CS135 at University of Waterloo.

Coverage

Lispy is currently a lightweight interpreter that can deal with primitive and other non-primitive essentials of Scheme. These are but not confined to the following:

  • Mathematical operators (Infix)
  • Primitive data structures (Number (Integers) , Strings, lists)
  • String literals and comments ("", ;;)
  • Procedure calls/Functions using lambda calculus
  • Abstract list functions (foldl, foldr, map, filter)
  • User defined data structures
  • Racket predicates (member?, equal?)
  • Functional paradigm supported
  • Built-in testing functions (check-expect, check-within)
  • Dynamic scoping and environment building
  • Supports algorithms designed with these restrictions
  • Command line utility so available to all users alike
  • Interactive interface with minimalistic error handling

DONE: Currently working to build procedure and evaluation definitions to support structures, struct functions and predicates. The general strategy I've opted to go forward with so to avoid tampering with existing tokenization is to identify struct commands during evaluation of parsed tokens. Following this, I intend to use either named tuples from the collections library or fixed length arrays with elements as fields. The idea is that any struct call to fields can correspond to index locations in the array. Therefore each index location will correspond to a specefic field which will corresspond to a 'struct-field' auto-created function. This function will act as a placeholder and a key in the environment and will be pushed along with its value - the index. When this procedure is called, its lambda function will call for an array to be passed and the index of the given array is then returned. Thus emulating a struct in Scheme.

Lispy 3.0 has dealt with the issue vaguely described above. However to access a field of a structure its position needs to be known. This position is returned by the '[struct name]-[field name]-pos' command that is autonomously generated for every field when declaring a struct. This is because of the structs underlying architecture I've chosen. Examples to clarify and dispel further queries are addressed in the Examples sextion.

Memory allocation and garbage collection are handled by python's architecture. Lispy supports an interactive environment over client's terminal as discussed below

Setup

pip install rlispy

Or

git clone https://github.com/ridwanmsharif/lispy

Usage

To begin using the environment, enter Lispy directory and run:

$ python rlispy/lis.py

Note: Enter one valid Scheme command at a time

Lispy is now ready for use:

Code: ENTER ANY SCHEME CODE HERE (NOTE THE RESTRICTIONS)

To quit the environment enter the quit command:

Code: quit

Examples

Defining constants

Code: (define const "Constant")
Code: const
"Constant"

Defining and changing variables

Code: (define var "Variable")
Code: var
"Variable"
Code: (set! var "Variable")
Code: var
"Variable"

Basic Operations

Code: (* (+ 1 1) (/ (- 5 3) 2))
2

Defining functions and using lambda calculus

Code: (define factorial 
          (lambda (x)
              (if (<= 1)
                  1
                  (* x (factorial (- x 1))))))
Code: (factorial 5)
120
Code: (factorial 2)
2
Code: (factorial -10)
1
Code: (check-expect (factorial 3) 6)
True
Code: (check-within (factorial 3) (factorial 2) (factorial 4))
True

Using abstract list functions

Code: (define lst (list 1 2 3))
Code: lst
(1 2 3)
Code: (member? 2 lst)
True
Code: (member? 4 lst)
False
Code: (map (lambda (elem) (+ 1 elem)) lst)
(2 3 4)
Code: (foldr + 0 lst)
6
Code: (foldr (lambda (x rest) (cons x rest)) (list) lst)
(1 2 3)
Code: (foldl (lambda (x acc) (cons acc x)) (list) lst)
(3 2 1)
Code: (filter (lambda (x) (>= x 2)) lst)
(2 3)

Making use of structs

Code: (struct posn (x y z))
Code: (make-posn coordinate_a "x" "y" "z")
Code: coordinate_a
("x" "y" "z")
Code: (make-posn coornidate_fail 2 2)
TypeError: make-posn requires 3 values, given 2
Code: (posn? coordinate_a)
True
Code: (define x posn-x-pos)
Code: (define y posn-y-pos)
Code: (define z posn-z-pos)
Code: (posn-pos coordinate_a x)
"x"
Code: (posn-pos coordinate_a y)
"y"
Code: (posn-pos coordinate_a z)
"z"

Quit command to exit Lispy 3.0

Code: quit

$

Disclaimer

Purely experimental project. Designed for learning purposes not production use. Closely following Peter Norvig's implementation to get started.

Contributing

Bug reports and pull requests are welcome on GitHub at @ridwanmsharif

Author

Ridwan M. Sharif: E-mail, @ridwanmsharif

License

The command line utility is available as open source under the terms of the MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].