All Projects → mattgreen → Hython

mattgreen / Hython

Licence: gpl-3.0
Haskell-powered Python 3 interpreter

Programming Languages

python
139335 projects - #7 most used programming language
haskell
3896 projects
language
365 projects

Projects that are alternatives of or similar to Hython

Vm.js
Javascript 解释器. Javascript Interpreter
Stars: ✭ 343 (-37.64%)
Mutual labels:  interpreter
Ok
An open-source interpreter for the K5 programming language.
Stars: ✭ 408 (-25.82%)
Mutual labels:  interpreter
Gpython
gpython is a python interpreter written in go "batteries not included"
Stars: ✭ 472 (-14.18%)
Mutual labels:  interpreter
Monkey
Interpreter with support for class, linq, sql, net, http, fmt, json and A realtime syntax highlighting REPL.
Stars: ✭ 347 (-36.91%)
Mutual labels:  interpreter
Mirth
Compiler for the Mirth programming language.
Stars: ✭ 390 (-29.09%)
Mutual labels:  interpreter
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (-23.27%)
Mutual labels:  interpreter
Passerine
A small extensible programming language designed for concise expression with little code.
Stars: ✭ 341 (-38%)
Mutual labels:  interpreter
Wren
The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
Stars: ✭ 5,345 (+871.82%)
Mutual labels:  interpreter
Gravity
Gravity Programming Language
Stars: ✭ 3,968 (+621.45%)
Mutual labels:  interpreter
Renjin
JVM-based interpreter for the R language for the statistical analysis.
Stars: ✭ 466 (-15.27%)
Mutual labels:  interpreter
Sh
A shell parser, formatter, and interpreter with bash support; includes shfmt
Stars: ✭ 4,343 (+689.64%)
Mutual labels:  interpreter
Picrin
lightweight scheme interpreter
Stars: ✭ 387 (-29.64%)
Mutual labels:  interpreter
Engine262
An implementation of ECMA-262 in JavaScript
Stars: ✭ 445 (-19.09%)
Mutual labels:  interpreter
Tcl
The Tcl Core. (Mirror of core.tcl-lang.org)
Stars: ✭ 342 (-37.82%)
Mutual labels:  interpreter
Bartosz Basics Of Haskell
Code and exercises from Bartosz Milewski's Basics of Haskell Tutorial
Stars: ✭ 483 (-12.18%)
Mutual labels:  interpreter
Hyper Haskell
The strongly hyped Haskell interpreter.
Stars: ✭ 342 (-37.82%)
Mutual labels:  interpreter
Enso
Hybrid visual and textual functional programming.
Stars: ✭ 5,238 (+852.36%)
Mutual labels:  interpreter
Hashlink
A virtual machine for Haxe
Stars: ✭ 523 (-4.91%)
Mutual labels:  interpreter
Red
Red is a next-generation programming language strongly inspired by Rebol, but with a broader field of usage thanks to its native-code compiler, from system programming to high-level scripting and cross-platform reactive GUI, while providing modern support for concurrency, all in a zero-install, zero-config, single 1MB file!
Stars: ✭ 4,725 (+759.09%)
Mutual labels:  interpreter
Neko
The Neko Virtual Machine
Stars: ✭ 447 (-18.73%)
Mutual labels:  interpreter

hython

A toy Python 3 interpreter implemented in Haskell.

Introduction

I wanted to learn Haskell, and I wanted a big project, so I decided to write a Python 3 interpreter. The result was extremely educational and easily the coolest project I've ever worked on. Because it's implemented in a naive fashion, it won't ever be a replacement for real Python implementations.

Note: Hython only implements most of the Python3 language. It doesn't contain much of a standard library, which is a big part of what makes Python pleasant to use. Adding all of the necessary machinery needed for the existing Python 3 standard library to function is an enormous undertaking that I'm not interested in.

Status

It's finally done! Or at least, I'm declaring it that way.

Features

  • [x] Lexer
  • [x] Parser
  • [x] Most built-in data types, including int, bool, string, list, dict and range
  • [x] Common unary and binary operators on common data types
  • [x] A few built-in functions, including print
  • [x] Variable assignment and lookup, with support for nonlocal and global keywords
  • [x] Conditional expressions with if and else
  • [x] All loop constructs: for and while with support for break and continue within them
  • [x] Support for the with statement
  • [x] Destructuring ((a,b) = [1,2])
  • [x] Functions, including nested functions, default parameters, and keyword parameters
  • [x] Splat (* and **) operators in caller argument lists
  • [x] Lambda expressions, with proper environment capture
  • [x] Classes, including inheritance and proper method resolution order
  • [x] Objects
  • [x] Exception handling via try, with support for handlers, frame unwinding, finally handlers, and else, along with some built-in exception classes
  • [x] Basic support for loading modules with the import statement
  • [x] Simple REPL
  • [x] Support for the is operator
  • [ ] Support for generators and yield
  • [ ] List/generator/dict/set comprehensions
  • [ ] Index slicing
  • [ ] Support for decorators / metaclasses
  • [ ] Multi-line input for the REPL

Code Metrics

sloccount output as of 10/1/16:

Totals grouped by language (dominant language first):
haskell:       2159 (70.83%)
yacc:           580 (19.03%) # parser
python:         309 (10.14%) # lib

Examples

See the test directory for example code that works

Building and running

  1. Install Stack

  2. Clone the repository:

     $ git clone https://github.com/mattgreen/hython.git
     $ cd hython
    
  3. Build:

     $ make
    
  4. Run a file:

     $ ./hython test/fib.py
    

REPL

Hython includes a simple REPL, which you can play around with:

$ ./hython

Test Suite

Hython's test suite is rather simple: it ensures the output of Hython matches that of the system's python3 for each test file.

To run the automated test suite:

$ make test

Reference Information

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].