|
0 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
1 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
|
2 |
<head>
|
|
3 |
<title>The Maentwrog Programming Language</title>
|
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
5 |
<!-- begin html doc dynamic markup -->
|
|
6 |
<script type="text/javascript" src="/contrib/jquery-1.6.4.min.js"></script>
|
|
7 |
<script type="text/javascript" src="/scripts/documentation.js"></script>
|
|
8 |
<!-- end html doc dynamic markup -->
|
|
9 |
</head>
|
|
10 |
<body>
|
|
11 |
|
|
12 |
<h1>The Maentwrog Programming Language</h1>
|
|
13 |
|
|
14 |
<p>This is a rudimentary specification for the Maentwrog programming language.</p>
|
|
15 |
|
|
16 |
<p>This information, and the example programs in this distribution, were taken
|
|
17 |
from the esolangs.org wiki page for Maentwrog, written by User:Marinus and
|
|
18 |
(like all esowiki articles) placed in the public domain. Thanks Marinus!</p>
|
|
19 |
|
|
20 |
<h2>Syntax</h2>
|
|
21 |
|
|
22 |
<p>A Maentwrog program consists of a series of words, separated by whitespace. Words can contain any character except whitespace.
|
|
23 |
The way these words are executed depends on the character they begin with.</p>
|
|
24 |
|
|
25 |
<ul>
|
|
26 |
<li>A word that consists of digits is taken as an integer and pushed. A minus sign
|
|
27 |
may be used to make negative numbers, so <code>25</code> and <code>-14</code> are
|
|
28 |
words that push 25 and -14 onto the stack. Extra characters at the end of the word are allowed,
|
|
29 |
so <code>25abc</code> and <code>25.14</code> both also push 25. </li>
|
|
30 |
<li>A word that isn't a number is treated as either a function or a variable. If the word is defined as a function, it is executed; if it's a variable,
|
|
31 |
its current value is pushed to the stack. Using an undefined word results in an error, though this doesn't stop further execution of the program. </li>
|
|
32 |
<li>To define a word as a function, use the syntax <code>: new-word words to execute ;</code> (as in Forth). Redefining a word is not allowed,
|
|
33 |
and neither are nested function definitions. </li>
|
|
34 |
<li>To define a word as a variable, use the syntax <code>*varname</code>. This must be done before using a variable. </li>
|
|
35 |
</ul>
|
|
36 |
|
|
37 |
<p>Additionally, words (except number words) can take one of a list of prefixes, changing how the word is executed.</p>
|
|
38 |
|
|
39 |
<table>
|
|
40 |
<tr>
|
|
41 |
<td> <b>Prefix</b> </td><td> <b>Action</b> </td><td> <b>Example</b> </td><td> <b>Result</b>
|
|
42 |
</td></tr>
|
|
43 |
<tr>
|
|
44 |
<td> <code>=</code> </td><td> Assign to variable </td><td> <code>=foo</code> </td><td> A value popped from the stack is assigned to the variable <i>foo</i>.
|
|
45 |
</td></tr>
|
|
46 |
<tr>
|
|
47 |
<td> <code>@</code> </td><td> If </td><td> <code>@bye</code> </td><td> Pop value, stop the program (see predefined words) if it isn't 0.
|
|
48 |
</td></tr>
|
|
49 |
<tr>
|
|
50 |
<td> <code>[</code> </td><td> While </td><td> <code>[xyz</code> </td><td> Pop value, if it's not 0 execute word <i>xyz</i>, then pop another value and do it again; continue until a 0 is popped.
|
|
51 |
</td></tr>
|
|
52 |
<tr>
|
|
53 |
<td> <code>$</code> </td><td> Repeat </td><td> <code>$.</code> </td><td> Pop value, then output that many values from the stack.
|
|
54 |
</td></tr></table>
|
|
55 |
|
|
56 |
<h3>Predefined words</h3>
|
|
57 |
|
|
58 |
<table>
|
|
59 |
<tr>
|
|
60 |
<td> <b>Word</b> </td><td> <b>Stack effect</b> </td><td> <b>Description</b>
|
|
61 |
</td></tr>
|
|
62 |
<tr>
|
|
63 |
<td> <code>bye</code> </td><td> </td><td> Stop program immediately.
|
|
64 |
</td></tr>
|
|
65 |
<tr>
|
|
66 |
<td> <code>rem</code> ... <code>;</code> </td><td> </td><td> Comment. (Ignore all words between <code>rem</code> and <code>;</code>.)
|
|
67 |
</td></tr>
|
|
68 |
<tr>
|
|
69 |
<td> <code>:</code> <i>word</i> ... <code>;</code> </td><td> </td><td> Define a new word.
|
|
70 |
</td></tr>
|
|
71 |
<tr>
|
|
72 |
<td> <code>debug</code> </td><td> </td><td> Turn on debugging (outputs all words executed).
|
|
73 |
</td></tr>
|
|
74 |
<tr>
|
|
75 |
<td> <code>vars</code> </td><td> </td><td> Output a list of currently defined variables and their values.
|
|
76 |
</td></tr>
|
|
77 |
<tr>
|
|
78 |
<td> <code>words</code> </td><td> </td><td> Output a list of currently defined words.
|
|
79 |
</td></tr>
|
|
80 |
<tr>
|
|
81 |
<td> <code>alloc</code> </td><td> <code>n</code> | <code>ptr</code> </td><td> Allocate memory for <i>n</i> C <i>long</i>s, returns a pointer.
|
|
82 |
</td></tr>
|
|
83 |
<tr>
|
|
84 |
<td> <code>free</code> </td><td> <code>ptr</code> | <code>-</code> </td><td> Free memory at pointer.
|
|
85 |
</td></tr>
|
|
86 |
<tr>
|
|
87 |
<td> <code>size</code> </td><td> <code>-</code> | <code>n</code> </td><td> Push stack size.
|
|
88 |
</td></tr>
|
|
89 |
<tr>
|
|
90 |
<td> <code>dup</code> </td><td> <code>a</code> | <code>a a</code> </td><td> Duplicate top of stack.
|
|
91 |
</td></tr>
|
|
92 |
<tr>
|
|
93 |
<td> <code>swap</code> </td><td> <code>a b</code> | <code>b a</code> </td><td> Swap the two topmost stack values.
|
|
94 |
</td></tr>
|
|
95 |
<tr>
|
|
96 |
<td> <code>pop</code> </td><td> <code>a</code> | <code>-</code> </td><td> Remove top value from stack.
|
|
97 |
</td></tr>
|
|
98 |
<tr>
|
|
99 |
<td> <code>get</code> </td><td> <code>ptr</code> | <code>value</code> </td><td> Push value at pointer to stack (C <code>*ptr</code>).
|
|
100 |
</td></tr>
|
|
101 |
<tr>
|
|
102 |
<td> <code>put</code> </td><td> <code>ptr val</code> | <code>-</code> </td><td> Store value at pointer (C <code>*ptr = val</code>).
|
|
103 |
</td></tr>
|
|
104 |
<tr>
|
|
105 |
<td> <code>rnd</code> </td><td> <code>-</code> | <code>n</code> </td><td> Push random value.
|
|
106 |
</td></tr>
|
|
107 |
<tr>
|
|
108 |
<td> <code>></code> </td><td> <code>a b</code> | <code>(a>b)</code> </td><td> Push 1 if a is greater than b, else 0.
|
|
109 |
</td></tr>
|
|
110 |
<tr>
|
|
111 |
<td> <code><</code> </td><td> <code>a b</code> | <code>(a<b)</code> </td><td> Push 1 if a is less than b, else 0.
|
|
112 |
</td></tr>
|
|
113 |
<tr>
|
|
114 |
<td> <code>==</code> </td><td> undefined </td><td> Undefined.
|
|
115 |
</td></tr>
|
|
116 |
<tr>
|
|
117 |
<td> <code>.</code> </td><td> <code>n</code> | <code>-</code> </td><td> Pop a value, output as integer, adding a newline.
|
|
118 |
</td></tr>
|
|
119 |
<tr>
|
|
120 |
<td> <code>..</code> </td><td> <code>n</code> | <code>-</code> </td><td> Pop a value, output as an ASCII character.
|
|
121 |
</td></tr>
|
|
122 |
<tr>
|
|
123 |
<td> <code>mod</code> </td><td> <code>a b</code> | <code>(a%b)</code> </td><td> Modulo.
|
|
124 |
</td></tr>
|
|
125 |
<tr>
|
|
126 |
<td> <code>+</code> </td><td> <code>a b</code> | <code>(a+b)</code> </td><td> Addition.
|
|
127 |
</td></tr>
|
|
128 |
<tr>
|
|
129 |
<td> <code>-</code> </td><td> <code>a b</code> | <code>(a-b)</code> </td><td> Subtraction.
|
|
130 |
</td></tr>
|
|
131 |
<tr>
|
|
132 |
<td> <code>*</code> </td><td> <code>a b</code> | <code>(a*b)</code> </td><td> Multiplication.
|
|
133 |
</td></tr>
|
|
134 |
<tr>
|
|
135 |
<td> <code>/</code> </td><td> <code>a b</code> | <code>(a/b)</code> </td><td> Division, result is rounded towards 0.
|
|
136 |
</td></tr></table>
|
|
137 |
|
|
138 |
</body>
|
|
139 |
</html>
|