{ "info": { "author": "Yasser Nabi", "author_email": "yassersaleemi@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "whitepy\n=======\n\n|Build Status|\n\nWhitespace interpreter written in Python3 for my final Open University\nproject (TM470)\n\nInstall and Usage\n~~~~~~~~~~~~~~~~~\n\nOnce installed, run ``whitepycli`` with a whitespace source file as an\nargument.\n\nUsing pip\n'''''''''\n\n.. code:: shell\n\n $ pip install whitepy\n $ whitepycli --help\n Usage: whitepycli [OPTIONS] FILENAME\n\n Whitespace Interpreter\n\n Options:\n --debug / --no-debug Enable Debug\n --help Show this message and exit.\n \n $ whitepycli sample_ws/helloworld.ws \n Hello, World!\n\nFrom Github\n'''''''''''\n\n.. code:: shell\n\n $ git clone https://github.com/yasn77/whitepy && cd whitepy\n $ pip install -r requirements.txt\n $ ./whitepycli --help\n Usage: whitepycli [OPTIONS] FILENAME\n\n Whitespace Interpreter\n\n Options:\n --debug / --no-debug Enable Debug\n --help Show this message and exit.\n \n $ ./whitepycli sample_ws/helloworld.ws \n Hello, World!\n\nWhat is Whitespace?\n~~~~~~~~~~~~~~~~~~~\n\nWhitespace programming language was originally created by Edwin Brady\nand Chris Morris at the University of Durham[1], then gained wider\nexposure when it was reviewed[2] April 1st 2003 on\n`Slashdot `__ website.\n\nOriginally developed as a bit of fun, Whitespace is an attempt to have a\nprogramming language that uses characters that are usually ignored by\nother programming languages, namely ``space`` (ASCII 32),\n``tab``\\ (ASCII 9) and ``linefeed``\\ (ASCII 10). The by-product being\nthat you could implement Whitespace code in other text (making it\npossible to write a polygot computer program).\n\nHow to write Whitespace?\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nWhitespace is an imperative stack based language, with 5 basic commands\nknown as *Instruction Imperative Parameter* (IMP):\n\n+--------------------+----------------------+\n| IMP | Meaning |\n+====================+======================+\n| ``[Space]`` | Stack Manipulation |\n+--------------------+----------------------+\n| ``[Tab][Space]`` | Arithmetic |\n+--------------------+----------------------+\n| ``[Tab][Tab]`` | Heap access |\n+--------------------+----------------------+\n| ``[LF]`` | Flow Control |\n+--------------------+----------------------+\n| ``[Tab][LF]`` | I/O |\n+--------------------+----------------------+\n\nThe full list of IMP with commands can be found in the Whitespace\ntutorial[3]. The original tutorial is no longer available, but can be\naccessed using `Internet Archive: Wayback\nmachine `__.\n\nOne of the biggest difficulties in writing Whitespace is that the source\ncode isn't immediately visible in most editors. To get around this, many\neditors have the ability to represent Whitespace characters as some\nother character. For example, in ``vim`` you can use\n``:set listchars=...`` and ``:set list``.\n\nwhitepy Implementation\n~~~~~~~~~~~~~~~~~~~~~~\n\nLexer (```lexer.py`` `__)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe whitepy lexerical analysis relies on\n```lexerconstants.py`` `__, which contains\nvalid IMP that can be used and their valid arguments also other\ndefinitions, such as integer representation. These are taken from the\n`original whitespace\ntutorial `__.\n\nThe lexer takes the whitespace code as an input\n(``lexer.Lexer(line=lines)``) and when the method\n``lexer.get_all_tokens()`` is called, a list of tokens and arguments is\ncreated from the whitespace source file. These tokens are stored in the\nlexer object and can be retrieved by calling ``lexer.tokens``.\n\nTokenisation process is handled by\n```ws_token.py`` `__.\n\nTokeniser (```ws_token.py`` `__)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe engine that drives the Tokeniser is Pythons ``re`` library,\nspecifically ``re.Scanner``. This is a powerful library that can easily\nallow splitting of text in to the required tokens. Documentation for\n``re.Scanner`` is not extensive and can be found under section\n``6.2.5.9`` of `Python ``re``\ndocumentation `__,\nhowever I found some really helpful documentation and examples\n`here `__.\n\nParser (```parser.py`` `__)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nOnce lexical analysis is complete, it is now possible to parse the list\nof tokens and execute accordingly. At the heart of the parser is a token\nto method map (``parser.method_map``), this is a ``dict`` structure that\nmaps tokens to internal methods. I believe this approach helps me to\nextend the interpreter with possibly my own token implementations and\nreduces the size of the ``parser.parse()`` method. This is because it\nreduces the amount of logic required in ``parser.parse()`` and instead\nthe method simply looks up keys in a ``dict``.\n\nHelpful links\n~~~~~~~~~~~~~\n\nThe following is a list of sites/references I have used to help me\ndevelop ``whitepy``:\n\n+--------------------------------------+--------------------------------------+\n| Title | Link |\n+======================================+======================================+\n| Writing Compilers and Interpreters: | https://www.amazon.co.uk/Writing-Com |\n| A Software Engineering Approach by | pilers-Interpreters-Software-Enginee |\n| Ronald Mak | ring-ebook/dp/B004S82O40) |\n+--------------------------------------+--------------------------------------+\n| Whitspace Language Tutorial | https://h0tsh0tt.wordpress.com/2016/ |\n| | 07/03/whitespace-language-tutorial/ |\n+--------------------------------------+--------------------------------------+\n| Whitespace (Wikipedia) | https://en.wikipedia.org/wiki/Whites |\n| | pace\\_(programming\\_language) |\n+--------------------------------------+--------------------------------------+\n| Interpreter Collection for the | https://github.com/hostilefork/white |\n| Whitespace Language | spacers/ |\n+--------------------------------------+--------------------------------------+\n| Online Whitespace Compiler, virtual | https://github.com/vii5ard/whitespac |\n| machine and IDE | e |\n+--------------------------------------+--------------------------------------+\n| Let's build a simple interpreter | https://ruslanspivak.com/lsbasi-part |\n| | 1/ |\n+--------------------------------------+--------------------------------------+\n| Python ``re`` module used for | http://lucumr.pocoo.org/2015/11/18/p |\n| tokenising | ythons-hidden-re-gems/ |\n+--------------------------------------+--------------------------------------+\n| Let's build a compiler | http://compilers.iecc.com/crenshaw/ |\n+--------------------------------------+--------------------------------------+\n| Notes on how Parsers and Compilers | http://parsingintro.sourceforge.net/ |\n| work | |\n+--------------------------------------+--------------------------------------+\n\nReferences\n~~~~~~~~~~\n\n[1]\nhttps://web.archive.org/web/20030412201917/http://compsoc.dur.ac.uk:80/whitespace/\n\n[2]\nhttps://developers.slashdot.org/story/03/04/01/0332202/New-Whitespace-Only-Programming-Language\n\n[3]\nhttps://web.archive.org/web/20030414001723/http://compsoc.dur.ac.uk:80/whitespace/tutorial.php\n\n.. |Build Status| image:: https://travis-ci.org/yasn77/whitepy.svg?branch=master\n :target: https://travis-ci.org/yasn77/whitepy\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/yasn77/whitepy/archive/0.4.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yasn77/whitepy", "keywords": "", "license": "LICENSE.txt", "maintainer": "", "maintainer_email": "", "name": "whitepy", "package_url": "https://pypi.org/project/whitepy/", "platform": "", "project_url": "https://pypi.org/project/whitepy/", "project_urls": { "Download": "https://github.com/yasn77/whitepy/archive/0.4.tar.gz", "Homepage": "https://github.com/yasn77/whitepy" }, "release_url": "https://pypi.org/project/whitepy/0.4/", "requires_dist": null, "requires_python": "", "summary": "Whitespace interpreter written in Python 3", "version": "0.4" }, "last_serial": 2957414, "releases": { "0.3": [], "0.4": [ { "comment_text": "", "digests": { "md5": "d502d5c96943ad9ff3da467a9982fcd2", "sha256": "3c4cae3d494229433645108c7dceb2e5a4384178463555d5054b8ab31580f2e7" }, "downloads": -1, "filename": "whitepy-0.4.tar.gz", "has_sig": false, "md5_digest": "d502d5c96943ad9ff3da467a9982fcd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9126, "upload_time": "2017-06-18T10:38:54", "url": "https://files.pythonhosted.org/packages/c2/10/27ede9f50a7ff989489bed561b0bb430c1eb1d4c7f0810b9168b920d7cfe/whitepy-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d502d5c96943ad9ff3da467a9982fcd2", "sha256": "3c4cae3d494229433645108c7dceb2e5a4384178463555d5054b8ab31580f2e7" }, "downloads": -1, "filename": "whitepy-0.4.tar.gz", "has_sig": false, "md5_digest": "d502d5c96943ad9ff3da467a9982fcd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9126, "upload_time": "2017-06-18T10:38:54", "url": "https://files.pythonhosted.org/packages/c2/10/27ede9f50a7ff989489bed561b0bb430c1eb1d4c7f0810b9168b920d7cfe/whitepy-0.4.tar.gz" } ] }