Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Whitespace (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Syntax == Whitespace defines a command as a sequences of whitespace characters. For example, <code>[Tab][Space][Space][Space]</code> performs arithmetic addition of the top two elements on the stack. A command is written as an instruction modification parameter (IMP) followed by an operation and then any parameters. <ref name="whitespace" /> IMP sequences include: {| class="wikitable" |- ! IMP !! Meaning |- | [Space] || Stack Manipulation |- | [Tab][Space] || Arithmetic |- | [Tab][Tab] || Heap Access |- | [LineFeed] || Flow Control |- | [Tab][LineFeed] || I/O |} Operator sequences, organized by IMP, include:<ref name="whitespace"/> {| class="wikitable" |- ! IMP !! Operator !! Parameter !! Meaning !Minimum size of the stack required* |- | [Space] || [Space] || Number || Push the number onto the stack |0 |- | [Space] || [LF][Space] || - || Duplicate the top item on the stack |1 |- | [Space] || [Tab][Space] || Number ''n''|| Copy the nth item on the stack (given by the argument) onto the top of the stack** |''n''+1 |- | [Space] || [LF][Tab] || - || Swap the top two items on the stack |2 |- | [Space] || [LF][LF] || - || Discard the top item on the stack |1 |- | [Space] || [Tab][LF] || Number ''n''|| Slide n items off the stack, keeping the top item** |may be less than '''''n''+1''', but at least 1 item (top of the stack) is required |- | [Tab][Space] || [Space][Space] || - || Addition |2 |- | [Tab][Space] || [Space][Tab] || - || Subtraction |2 |- | [Tab][Space] || [Space][LF] || - || Multiplication |2 |- | [Tab][Space] || [Tab][Space] || - || Integer division |2 (top may not be 0) |- | [Tab][Space] || [Tab][Tab] || - ||[[Modulo operation|Modulo]] |2 (top may not be 0) |- | [Tab][Tab] || [Space] || - || Store in heap |2 |- | [Tab][Tab] || [Tab] || - || Retrieve from heap |1 |- | [LF] || [Space][Space] || Label || Mark a location in the program |0 |- | [LF] || [Space][Tab] || Label || Call a subroutine |0 |- | [LF] || [Space][LF] || Label || Jump to a label |0 |- | [LF] || [Tab][Space] || Label || Jump to a label if the top of the stack is zero |1 |- | [LF] || [Tab][Tab] || Label || Jump to a label if the top of the stack is negative |1 |- | [LF] || [Tab][LF] || - || End a subroutine and transfer control back to the caller |0 ''(callstack: 1)'' |- | [LF] || [LF][LF] || - || End the program |0 |- | [Tab][LF] || [Space][Space] || - || Output the character at the top of the stack |1 |- | [Tab][LF] || [Space][Tab] || - || Output the number at the top of the stack |1 |- | [Tab][LF] || [Tab][Space] || - || Read a character and place it in the location given by the top of the stack |1 |- | [Tab][LF] || [Tab][Tab] || - || Read a number and place it in the location given by the top of the stack |1 |} <nowiki>*</nowiki>Due to Haskell being lazily evaluated, the effect of the stack being too small may only show when, for example, invoking the ''outputting a number'' side-effect. <nowiki>**</nowiki>The ''copy'' and ''slide'' operations were added in Whitespace 0.3.<ref name="whitespace" /> === Comments === Characters other than <code>space</code>, <code>tab</code> and <code>linefeed</code> are ignored and thus can be used for comments. === Numbers === A numeric value is represented as a sequence of <code>space</code> and <code>tab</code> characters that represent 0 and 1 respectively and terminated by a <code>linefeed</code>. The first character represents the [[Sign (mathematics)|sign]] of the value {{endash}} <code>space</code> for positive and <code>tab</code> for negative. Subsequent characters before the terminator represent the binary digits of a value. For example: * [space][tab][space][space][tab][space][tab][tab][linefeed] (STSSTSTTL) is positive since it starts with <code>space</code> and represents 1001011 in binary, which is 75 in decimal. * [tab][tab][tab][space][space][tab][space][linefeed] (TTTSSTSL) is negative since it starts with <code>tab</code> and represents -110010 in binary which is β50 in decimal. === Labels === A label is used for [[control flow]]. It is a <code>linefeed</code>-terminated sequence of <code>space</code>and <code>tab</code> characters. As there is only one namespace, all labels must be unique. <ref name="whitespace"/>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)