Challenge – QuickPiet Interpreter
Create an interpreter for a new Language based on Piet: QuickPiet
To pair off of Nate’s Rock Paper Scissors challenge, here is one I am offering up to him: create an interpreter which will execute QuickPiet commands. What is QuickPiet? QuickPiet is a very basic language based off of the commands found in the esoteric Piet programming language.
Piet programmers are written as images which can be interpreted as actions based on a stack. Recently I signed up to give a talk at the April Fool’s Day meeting of the Lambda Lounge where several people will be giving short talks on esoteric and useless programming languages. Programming in Piet poses several challenges including working only with a single stack and building up your logic into pixels and colors. I should have a few posts on writing programs in Piet in the next week or so. Until then, I have been mainly struggling with how to accomplish real work with just a single stack and a very limited menu of commands to choose from. QuickPiet is an attempt to make that process easier.
The challenge:
- Write an interpreter for the QuickPiet language I have posted in a new GitHub Gist; http://gist.github.com/332040.
[Edit: The language spec is now in the base QuickPiet repo on GitHub] - The interpreter should allow the user to enter in QuickPiet commands from a file or GUI text box
- The interpreter should allow the user to enter text to be handled by STDIN and should display to the user any characters sent to STDOUT
- Ideally the interpreter would be written in a cross-platform way (e.g. JVM, Ruby, Javascript/HTML) but anything is valid
- Extra points for GUIs and/or the ability to see how the stack changes through program execution and/or at the end
The “complete” spec can be found on the Gist page, but a very quick rundown is below:
- Program execution is top down, except for GOTO commands
- Each line can be blank (ignored), a label, a comment, or a command
- Only one command per line
- There are no explicit looping or other control structures
- The interpreter maintains a single “infinitely large” stack which different commands can act on
- Example commands include (IN, OUT, PUSH, POP, ADD, SUBTRACT, GOTO, etc)
- Commands are case-insensitive, labels are not
If you have any questions or are willing to venture a solution please leave a comment. I just had this idea this morning so I am very interested in any feedback you may have. I am planning on working on my own solution and hope to have something put together today or tomorrow.
Click the tag links for QuickPiet and Piet below to see all posts
I will be posting my version here: http://github.com/benjaminplee/QuickPiet
I’m posting my code as I go along as a fork of your gist.
I’m starting in Haskell because the pattern matching makes a lot of the stack operations trivial to implement and Parsec promises to be the easiest way to interpret and execute the actual script.
http://gist.github.com/332400
Updated QuickPiet language spec w/ new assert command, updated docs, and some slight changes to pop, push, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Piet! Language Spec
hosted with ❤ by GitHub
With the latest QuickPiet language additions I am working on some spec tests which should be able to be used to verify implementations of interpreters.
Dear Friends, Happy Fool’s Day!
A police officer pulls over this guy who had been weaving in and out of the lanes. He goes up to the guy’s window and says, “Sir, I need you to blow into this breathalyzer tube.”
The man says, “Sorry officer, I can’t do that. I am an asthmatic. If I do that I’ll have a really bad asthma attack.”
“Okay, fine. I need you to come down to the station to give a blood sample.”
“I can’t do that either. I am a hemophiliac. If I do that, I’ll bleed to death.”
“Well, then we need an urine sample.”
“I’m sorry, officer, I can’t do that either. I am also a diabetic. If I do that I’ll get really low blood sugar.”
“All right then I need you to come out here and walk this white line.”
“I can’t do that, officer.”
“Why not?”
“Because I’m too drunk to do that!”
Happy April Fool’s Day!