Content deleted Content added
Correct name of language from MOUSE to Mouse (as given in Mouse book) |
No edit summary |
||
Line 1:
The '''Mouse programming language''' is a small computer programming language developed by Dr. Peter Grogono in the late 1970s and early 1980s.<ref name="grogono1">Grogono, Peter. "Mouse: A Language for Microcomputers", ''Byte'', July 1979, pp. 198ff.</ref><ref name="grogono2">Grogono, Peter. ''Mouse: A Language for Microcomputers''. 151 pages. Petrocelli Books, Inc.: 1983. ISBN 0-89433-201-5.</ref> It was developed as an extension of an earlier language called MUSYS, which was used to control digital and analog devices in an electronic music studio.
Mouse was originally intended as a small, efficient language for [[microcomputer|microcomputers]] with limited memory. It is an interpreted, [[Stack (data structure)|stack]]-based language and uses [[Reverse Polish notation]]. In order to make an interpreter as easy as possible to implement, Mouse is designed so that a program is processed as a stream of characters, interpreted one character at a time.
The elements of the Mouse language consist of a set of one-character symbols, each of which performs a specific function (see table below). Since variable names are limited to one character, there are only 26 possible variables in Mouse (named A-Z). Integers and characters are the only available data types.
Despite these limitations, Mouse includes a number of relatively advanced features, including:
* Conditional branching
* Loops
* Pointers
* Macros (subroutines)
* Arrays
* Code tracing
The design of the Mouse language makes it ideal for teaching the design of an simple interpreter. Much of the book describing Mouse<ref name="grogono2" /> is devoted to describing the implementation of the interpreter.
==Detailed Description==
The language described here is the later version of Mouse, as described in the Mouse book<ref name="grogono2" />. This version is an extension of the language described in the original magazine article<ref name="grogono1" />.
===Mouse Symbols===
The following table describes each of the symbols used by Mouse<ref name="grogono2" />. Here X refers to the number on the top of the stack, and Y is the next number on the stack.
{| class="wikitable"
|-
! title="Symbol" | Symbol
! title="Action" | Action
|-
| <space>
| No action.
|-
|align="center"| $
| End of program.
|-
| <number>
| Push <number> on the stack.
|-
|align="center"| +
| Add
|-
|align="center"| -
| Subtract
|-
|align="center"| *
| Multiply
|-
|align="center"| /
| Integer divide
|-
|align="center"| \
| Remainder
|-
|align="center"| ?
| Input integer
|-
|align="center"| ?'
| Input character
|-
|align="center"| !
| Print integer
|-
|align="center"| !'
| Print character
|-
|align="center"| '
| Push character onto stack
|-
|align="center"| "
| Print string
|-
|align="center"| <letter>
| Get variable address
|-
|align="center"| :
| Store variable
|-
|align="center"| .
| Recall variable
|-
|align="center"| <
| Return 1 if Y<X; else return 0
|-
|align="center"| =
| Return 1 if Y=X; else return 0
|-
|align="center"| >
| Return 1 if Y>X; else return 0
|-
|align="center"| [
| Start of conditional statement
|-
|align="center"| ]
| End of conditional statement
|-
|align="center"| (
| Start of loop
|-
|align="center"| )
| End of loop
|-
|align="center"| ^
| Exit loop (if false)
|-
|align="center"| #
| Macro call
|-
|align="center"| @
| Exit from macro
|-
|align="center"| %
| Macro parameter
|-
|align="center"| ,
| End of actual macro parameter
|-
|align="center"| ;
| End of list of macro parameters
|-
|align="center"| {
| Start trace
|-
|align="center"| }
| End trace
|-
|align="center"| ~
| Comment
|}
===Language Expressions===
====Common Idioms====
These expressions appear frequently in Mouse programs.
<pre>
X: ~ store into variable X
X. ~ recall variable X
X. Y: ~ assign X to Y
N. 1 + N: ~ increment X by 1
P. Q. P: Q: ~ swap values of P and Q
? A: ~ input a number and store in A
P. ! ~ print variable P
</pre>
====Input====
Mouse may input integers or characters. When a character is input, it is automatically converted to its ASCII code.
<pre>
? X: ~ input a number and store into X
?' X: ~ input a character and store its ASCII code into X
</pre>
====Output====
Mouse may print integers, characters, or string constants, as shown in these examples. If an exclamation point appears in a string constant, a carriage return is printed.
<pre>
X. ! ~ recall number X and print it
X. !' ~ recall ASCII code X and print character
"Hello" ~ print string "Hello"
"Line 1!Line 2" ~ print strings "Line 1" and "Line 2" on two lines
</pre>
====Conditionals====
A conditional statement has the general form:
<pre>
B [ S ] ~ equivalent to: if B then S
</pre>
Here ''B'' is an expression that evaluates to 1 (true) or 0 (false), and ''S'' is a sequence of statements.
====Loops====
Loops may have one of several forms. Most common are the forms:
<pre>
(B ^ S) ~ equivalent to: while B do S
(S B ^) ~ equivalent to: repeat S until (not B)
</pre>
Here again ''B'' is a boolean value (0 or 1), and ''S'' is a sequence of statements.
====Macro Calls====
The format of a macro (subroutine) call may be illustrated by the following example. Macro A in this example adds the two parameters passed to it from the main program, and returns the sum on the top of the stack.
<pre>
#A,p1,p2; ~ call in main program to macro A
...
$A 1% 2% + @ ~ macro A (add parameters p1 and p2)
</pre>
Here ''p1'' and ''p2'' are parameters passed to the macro.
===Example Programs===
This short program prints 'Hello world.'
<pre>
"Hello world."
$</pre>
This program displays the squares of the numbers from 1 to 10.
<pre>
1 N: ~ initialize N to 1
( N. N. * ! " " ~ begin loop; print squares of numbers
N. 10 - 0 < ^ ~ exit loop if N > 10
N. 1 + N: ) $ ~ increment N and repeat loop</pre>
==Notes==
<div class="references-small" style="-moz-column-count:2; column-count:2;">
<references/>
</div>
==External links==
* [http://mouse.sourceforge.net/ Information on sourceforge.net]
* [http://www.geocities.com/fullerhaparnoldafmil/mouse.html The Great MOUSE Programming Language Revival]
* [http://cth.dtdns.net/mouse/ Friends of the Mouse]
* [http://www.primepuzzle.com/mouse/mouse.html Mouse, the Language]
* [http://www.davidgsimpson.com/mouse/ Mouse: Computer Programming Language] (includes source code for Mouse interpreters)
|