0 | 0 |
The Maentwrog Programming Language
|
1 | 1 |
==================================
|
|
2 |
|
|
3 |
This is the reference distribution for the Maentwrog programming language,
|
|
4 |
designed and implemented in 1993.
|
|
5 |
|
|
6 |
This distribution contains the reference interpreter, written in ANSI C, a
|
|
7 |
rudimentary specification (below) and some example Maentwrog programs. It also
|
|
8 |
contains a few other miscellaneous contemporaneous C programs by the author.
|
|
9 |
|
|
10 |
The current released version of the Maentwrog distribution is
|
|
11 |
version 1.1 revision 2014.0923.
|
|
12 |
|
|
13 |
Specification
|
|
14 |
-------------
|
2 | 15 |
|
3 | 16 |
This is a rudimentary specification for the Maentwrog programming
|
4 | 17 |
language.
|
|
8 | 21 |
User:Marinus and (like all esowiki articles) placed in the public
|
9 | 22 |
domain. Thanks Marinus!
|
10 | 23 |
|
11 | |
Syntax
|
12 | |
------
|
|
24 |
### Syntax ###
|
13 | 25 |
|
14 | 26 |
A Maentwrog program consists of a series of words, separated by
|
15 | 27 |
whitespace. Words can contain any character except whitespace. The way
|
|
34 | 46 |
Additionally, words (except number words) can take one of a list of
|
35 | 47 |
prefixes, changing how the word is executed.
|
36 | 48 |
|
37 | |
**Prefix** **Action** **Example** **Result**
|
38 | |
`=` Assign to variable `=foo` A value popped from the stack is assigned to the variable *foo*.
|
39 | |
`@` If `@bye` Pop value, stop the program (see predefined words) if it isn't 0.
|
40 | |
`[` While `[xyz` Pop value, if it's not 0 execute word *xyz*, then pop another value and do it again; continue until a 0 is popped.
|
41 | |
`$` Repeat `$.` Pop value, then output that many values from the stack.
|
|
49 |
Prefix Action Example Result
|
|
50 |
----- ------ ------- ------
|
|
51 |
= Assign to variable =foo A value popped from the stack is
|
|
52 |
assigned to the variable foo.
|
|
53 |
@ If @bye Pop value, stop the program (see
|
|
54 |
predefined words) if it isn't 0.
|
|
55 |
[ While [xyz Pop value, if it's not 0 execute
|
|
56 |
word xyz, then pop another value
|
|
57 |
and do it again; continue until a
|
|
58 |
0 is popped.
|
|
59 |
$ Repeat $. Pop value, then output that many
|
|
60 |
values from the stack.
|
42 | 61 |
|
43 | |
### Predefined words
|
|
62 |
#### Predefined words ####
|
44 | 63 |
|
45 | |
**Word** **Stack effect** **Description**
|
46 | |
`bye` Stop program immediately.
|
47 | |
`rem` ... `;` Comment. (Ignore all words between `rem` and `;`.)
|
48 | |
`:` *word* ... `;` Define a new word.
|
49 | |
`debug` Turn on debugging (outputs all words executed).
|
50 | |
`vars` Output a list of currently defined variables and their values.
|
51 | |
`words` Output a list of currently defined words.
|
52 | |
`alloc` `n` | `ptr` Allocate memory for *n* C *long*s, returns a pointer.
|
53 | |
`free` `ptr` | `-` Free memory at pointer.
|
54 | |
`size` `-` | `n` Push stack size.
|
55 | |
`dup` `a` | `a a` Duplicate top of stack.
|
56 | |
`swap` `a b` | `b a` Swap the two topmost stack values.
|
57 | |
`pop` `a` | `-` Remove top value from stack.
|
58 | |
`get` `ptr` | `value` Push value at pointer to stack (C `*ptr`).
|
59 | |
`put` `ptr val` | `-` Store value at pointer (C `*ptr = val`).
|
60 | |
`rnd` `-` | `n` Push random value.
|
61 | |
`>` `a b` | `(a>b)` Push 1 if a is greater than b, else 0.
|
62 | |
`<` `a b` | `(a<b)` Push 1 if a is less than b, else 0.
|
63 | |
`==` undefined Undefined.
|
64 | |
`.` `n` | `-` Pop a value, output as integer, adding a newline.
|
65 | |
`..` `n` | `-` Pop a value, output as an ASCII character.
|
66 | |
`mod` `a b` | `(a%b)` Modulo.
|
67 | |
`+` `a b` | `(a+b)` Addition.
|
68 | |
`-` `a b` | `(a-b)` Subtraction.
|
69 | |
`*` `a b` | `(a*b)` Multiplication.
|
70 | |
`/` `a b` | `(a/b)` Division, result is rounded towards 0.
|
|
64 |
Word Stack effect Description
|
|
65 |
---- ------------ -----------
|
|
66 |
bye Stop program immediately.
|
|
67 |
rem ... ; Comment. (Ignore all words between rem and ;.)
|
|
68 |
: word ... ; Define a new word.
|
|
69 |
debug Turn on debugging (outputs all words executed).
|
|
70 |
vars Output a list of currently defined variables
|
|
71 |
and their values.
|
|
72 |
words Output a list of currently defined words.
|
|
73 |
alloc n | ptr Allocate memory for n C longs, returns a pointer.
|
|
74 |
free ptr | - Free memory at pointer.
|
|
75 |
size - | n Push stack size.
|
|
76 |
dup a | a a Duplicate top of stack.
|
|
77 |
swap a b | b a Swap the two topmost stack values.
|
|
78 |
pop a | - Remove top value from stack.
|
|
79 |
get ptr | value Push value at pointer to stack (C `*ptr`).
|
|
80 |
put p v | - Store value at pointer (C `*ptr = val`).
|
|
81 |
rnd - | n Push random value.
|
|
82 |
> a b | (a>b) Push 1 if a is greater than b, else 0.
|
|
83 |
< a b | (a<b) Push 1 if a is less than b, else 0.
|
|
84 |
== undefined Undefined.
|
|
85 |
. n | - Pop a value, output as integer, adding a newline.
|
|
86 |
.. n | - Pop a value, output as an ASCII character.
|
|
87 |
mod a b | (a%b) Modulo.
|
|
88 |
+ a b | (a+b) Addition.
|
|
89 |
- a b | (a-b) Subtraction.
|
|
90 |
* a b | (a*b) Multiplication.
|
|
91 |
/ a b | (a/b) Division, result is rounded towards 0.
|
71 | 92 |
|
72 | 93 |
|