git @ Cat's Eye Technologies Maentwrog / 106b32c
Clean up README for revision release. Chris Pressey 10 years ago
2 changed file(s) with 56 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
00 The Maentwrog Programming Language
11 ==================================
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 -------------
215
316 This is a rudimentary specification for the Maentwrog programming
417 language.
821 User:Marinus and (like all esowiki articles) placed in the public
922 domain. Thanks Marinus!
1023
11 Syntax
12 ------
24 ### Syntax ###
1325
1426 A Maentwrog program consists of a series of words, separated by
1527 whitespace. Words can contain any character except whitespace. The way
3446 Additionally, words (except number words) can take one of a list of
3547 prefixes, changing how the word is executed.
3648
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.
4261
43 ### Predefined words
62 #### Predefined words ####
4463
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.
7192
7293
66 * - updated Jul 1998 Chris Pressey, fixed more minor bugs
77 * - and ANSI C-ized: now case sensitive
88 * - updated Jul 2010 Chris Pressey, buildability w/gcc & pcc
9 * - updated Sep 2014 Chris Pressey, buildability and warnings avoidance
910 * Usage : maentw maentw-expressions executes and exits
1011 * maentw goes into interactive mode
1112 * maentw <maentwrog-file runs file through maentw