The Maentwrog Programming Language
This is a rudimentary specification for the Maentwrog programming language.
This information, and the example programs in this distribution, were taken from the esolangs.org wiki page for Maentwrog, written by User:Marinus and (like all esowiki articles) placed in the public domain. Thanks Marinus!
Syntax
A Maentwrog program consists of a series of words, separated by whitespace. Words can contain any character except whitespace. The way these words are executed depends on the character they begin with.
- A word that consists of digits is taken as an integer and pushed. A
minus sign may be used to make negative numbers, so
25
and-14
are words that push 25 and -14 onto the stack. Extra characters at the end of the word are allowed, so25abc
and25.14
both also push 25. - 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, 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.
- To define a word as a function, use the syntax
: new-word words to execute ;
(as in Forth). Redefining a word is not allowed, and neither are nested function definitions. - To define a word as a variable, use the syntax
*varname
. This must be done before using a variable.
Additionally, words (except number words) can take one of a list of prefixes, changing how the word is executed.
**Prefix** **Action** **Example** **Result**
`=` Assign to variable `=foo` A value popped from the stack is assigned to the variable *foo*.
`@` If `@bye` Pop value, stop the program (see predefined words) if it isn't 0.
`[` 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.
`$` Repeat `$.` Pop value, then output that many values from the stack.
Predefined words
**Word** **Stack effect** **Description**
`bye` Stop program immediately.
`rem` ... `;` Comment. (Ignore all words between `rem` and `;`.)
`:` *word* ... `;` Define a new word.
`debug` Turn on debugging (outputs all words executed).
`vars` Output a list of currently defined variables and their values.
`words` Output a list of currently defined words.
`alloc` `n` | `ptr` Allocate memory for *n* C *long*s, returns a pointer.
`free` `ptr` | `-` Free memory at pointer.
`size` `-` | `n` Push stack size.
`dup` `a` | `a a` Duplicate top of stack.
`swap` `a b` | `b a` Swap the two topmost stack values.
`pop` `a` | `-` Remove top value from stack.
`get` `ptr` | `value` Push value at pointer to stack (C `*ptr`).
`put` `ptr val` | `-` Store value at pointer (C `*ptr = val`).
`rnd` `-` | `n` Push random value.
`>` `a b` | `(a>b)` Push 1 if a is greater than b, else 0.
`<` `a b` | `(a<b)` Push 1 if a is less than b, else 0.
`==` undefined Undefined.
`.` `n` | `-` Pop a value, output as integer, adding a newline.
`..` `n` | `-` Pop a value, output as an ASCII character.
`mod` `a b` | `(a%b)` Modulo.
`+` `a b` | `(a+b)` Addition.
`-` `a b` | `(a-b)` Subtraction.
`*` `a b` | `(a*b)` Multiplication.
`/` `a b` | `(a/b)` Division, result is rounded towards 0.
Commit History
@rel_1_1_2013_0226
git clone https://git.catseye.tc/Maentwrog/
- Rectify file permissions. catseye 11 years ago
- Fix Makefile (include math lib where needed.) catseye 11 years ago
- Place this distribution in the public domain. catseye 12 years ago
- Avoid compiler warnings for -ansi -pedantic. Cat's Eye Technologies 12 years ago
- Add Makefile. Cat's Eye Technologies 12 years ago
- At least make the tables look readable. I hope. Cat's Eye Technologies 12 years ago
- Convert documentation to Markdown. Cat's Eye Technologies 12 years ago
- Added tag rel_1_1_2011_0426 for changeset 89bd258e3fdb Cat's Eye Technologies 12 years ago
- Import of Maentwrog version 1.1 revision 2011.0426 sources. Cat's Eye Technologies 12 years ago
- Added tag rel_1_0_2007_0930 for changeset dfa374858e1c Cat's Eye Technologies 12 years ago