{"id":13790688,"url":"https://github.com/yasn77/whitepy","last_synced_at":"2026-04-06T06:31:57.785Z","repository":{"id":62588891,"uuid":"80537901","full_name":"yasn77/whitepy","owner":"yasn77","description":"Whitespace interpreter written in Python3","archived":false,"fork":false,"pushed_at":"2023-12-15T05:37:51.000Z","size":47,"stargazers_count":15,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T10:47:03.402Z","etag":null,"topics":["interpreter","programming-language","python","python3","university-project","whitespace","whitespace-interpreter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yasn77.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-31T16:21:48.000Z","updated_at":"2024-11-14T20:26:53.000Z","dependencies_parsed_at":"2023-12-15T06:48:44.799Z","dependency_job_id":null,"html_url":"https://github.com/yasn77/whitepy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasn77%2Fwhitepy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasn77%2Fwhitepy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasn77%2Fwhitepy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasn77%2Fwhitepy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yasn77","download_url":"https://codeload.github.com/yasn77/whitepy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253709394,"owners_count":21951131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interpreter","programming-language","python","python3","university-project","whitespace","whitespace-interpreter"],"created_at":"2024-08-03T22:00:49.744Z","updated_at":"2025-12-13T20:08:38.977Z","avatar_url":"https://github.com/yasn77.png","language":"Python","funding_links":[],"categories":["Study Exams / Projects"],"sub_categories":[],"readme":"# whitepy\n\n[![Build Status](https://travis-ci.org/yasn77/whitepy.svg?branch=master)](https://travis-ci.org/yasn77/whitepy)\n\nWhitespace interpreter written in Python3 for my final Open University project (TM470)\n\n### Install and Usage\n\nOnce installed, run `whitepycli` with a whitespace source file as an argument.\n\n##### Using pip\n\n```shell\n$ pip install whitepy\n$ whitepycli --help\nUsage: whitepycli [OPTIONS] FILENAME\n\n  Whitespace Interpreter\n\nOptions:\n  --debug / --no-debug  Enable Debug\n  --help                Show this message and exit.\n  \n$ whitepycli sample_ws/helloworld.ws \nHello, World!\n```\n\n##### From Github\n\n```shell\n$ git clone https://github.com/yasn77/whitepy \u0026\u0026 cd whitepy\n$ pip install -r requirements.txt\n$ ./whitepycli --help\nUsage: whitepycli [OPTIONS] FILENAME\n\n  Whitespace Interpreter\n\nOptions:\n  --debug / --no-debug  Enable Debug\n  --help                Show this message and exit.\n  \n$ ./whitepycli sample_ws/helloworld.ws \nHello, World!\n```\n\n### What is Whitespace?\n\nWhitespace programming language was originally created by Edwin Brady and Chris Morris at the University of Durham\u003csup\u003e[1]\u003c/sup\u003e, then gained wider exposure when it was reviewed\u003csup\u003e[2]\u003c/sup\u003e April 1st 2003 on [Slashdot](https://slashdot.org) website.\n\nOriginally developed as a bit of fun, Whitespace is an attempt to have a programming language that uses characters that are usually ignored by other programming languages, namely `space` (ASCII 32), `tab`(ASCII 9) and `linefeed`(ASCII 10). The by-product being that you could implement Whitespace code in other text (making it possible to write a polygot computer program).\n\n### How to write Whitespace?\n\nWhitespace is an imperative stack based language, with 5 basic commands known as _Instruction Imperative Parameter_ (IMP):\n\n| IMP            | Meaning            |\n| -------------- | ------------------ |\n| `[Space]`      | Stack Manipulation |\n| `[Tab][Space]` | Arithmetic         |\n| `[Tab][Tab]`   | Heap access        |\n| `[LF]`         | Flow Control       |\n| `[Tab][LF]`    | I/O                |\n\nThe full list of IMP with commands can be found in the Whitespace tutorial\u003csup\u003e[3]\u003c/sup\u003e. The original tutorial is no longer available, but can be accessed using [Internet Archive:  Wayback machine](http://archive.org/web/).\n\nOne of the biggest difficulties in writing Whitespace is that the source code isn't immediately visible in most editors. To get around this, many editors have the ability to represent Whitespace characters as some other character. For example, in `vim` you can use `:set listchars=...` and `:set list`.\n\n### whitepy Implementation\n\n#### Lexer ([`lexer.py`](whitepy/lexer.py))\n\nThe whitepy lexerical analysis relies on [`lexerconstants.py`](whitepy/lexerconstants.py), which contains valid IMP that can be used and their valid arguments also other definitions, such as integer representation. These are taken from the [original whitespace tutorial](https://web.archive.org/web/20030414001723/http://compsoc.dur.ac.uk:80/whitespace/tutorial.php).\n\nThe lexer takes the whitespace code as an input (`lexer.Lexer(line=lines)`) and when the method `lexer.get_all_tokens()` is called, a list of tokens and arguments is created from the whitespace source file. These tokens are stored in the lexer object and can be retrieved by calling `lexer.tokens`.\n\nTokenisation process is handled by [`ws_token.py`](whitepy/ws_token.py).\n\n#### Tokeniser ([`ws_token.py`](whitepy/ws_token.py))\n\nThe engine that drives the Tokeniser is Pythons `re` library, specifically `re.Scanner`. This is a powerful library that can easily allow splitting of text in to the required tokens. Documentation for `re.Scanner` is not extensive and can be found under section `6.2.5.9` of [Python `re` documentation](https://docs.python.org/3.2/library/re.html#writing-a-tokenizer), however I found some really helpful documentation and examples [here](http://lucumr.pocoo.org/2015/11/18/pythons-hidden-re-gems/).\n\n#### Parser ([`parser.py`](whitepy/parser.py))\n\nOnce lexical analysis is complete, it is now possible to parse the list of tokens and execute accordingly. At the heart of the parser is a token to method map (`parser.method_map`), this is a `dict` structure that maps tokens to internal methods. I believe this approach helps me to extend the interpreter with possibly my own token implementations and reduces the size of the `parser.parse()` method. This is because it reduces the amount of logic required in `parser.parse()` and instead the method simply looks up keys in a `dict`.\n\n### Helpful links\n\nThe following is a list of sites/references I have used to help me develop `whitepy`:\n\n| Title                                    | Link                                     |\n| ---------------------------------------- | ---------------------------------------- |\n| Writing Compilers and Interpreters: A Software Engineering Approach by Ronald Mak | https://www.amazon.co.uk/Writing-Compilers-Interpreters-Software-Engineering-ebook/dp/B004S82O40) |\n| Whitspace Language Tutorial              | https://h0tsh0tt.wordpress.com/2016/07/03/whitespace-language-tutorial/ |\n| Whitespace (Wikipedia)                   | https://en.wikipedia.org/wiki/Whitespace_(programming_language) |\n| Interpreter Collection for the Whitespace Language | https://github.com/hostilefork/whitespacers/ |\n| Online Whitespace Compiler, virtual machine and IDE | https://github.com/vii5ard/whitespace    |\n| Let's build a simple interpreter         | https://ruslanspivak.com/lsbasi-part1/   |\n| Python `re` module used for tokenising   | http://lucumr.pocoo.org/2015/11/18/pythons-hidden-re-gems/ |\n| Let's build a compiler                   | http://compilers.iecc.com/crenshaw/      |\n| Notes on how Parsers and Compilers work  | http://parsingintro.sourceforge.net/     |\n\n### References\n\n[1] https://web.archive.org/web/20030412201917/http://compsoc.dur.ac.uk:80/whitespace/\n\n[2] https://developers.slashdot.org/story/03/04/01/0332202/New-Whitespace-Only-Programming-Language\n\n[3] https://web.archive.org/web/20030414001723/http://compsoc.dur.ac.uk:80/whitespace/tutorial.php\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasn77%2Fwhitepy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyasn77%2Fwhitepy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasn77%2Fwhitepy/lists"}