• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

mattgreen/hython: Haskell-powered Python 3 interpreter

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mattgreen/hython

开源软件地址(OpenSource Url):

https://github.com/mattgreen/hython

开源编程语言(OpenSource Language):

Haskell 60.8%

开源软件介绍(OpenSource Introduction):

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

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
vincenthz/hs-memory: haskell memory发布时间:2022-06-22
下一篇:
ekmett/quine: haskell, opengl, toy project发布时间:2022-06-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap