Tree @rel_1_1_2014_0923 (Download .tar.gz)
The Maentwrog Programming Language
This is the reference distribution for the Maentwrog programming language, designed and implemented in 1993.
This distribution contains the reference interpreter, written in ANSI C, a rudimentary specification (below) and some example Maentwrog programs. It also contains a few other miscellaneous contemporaneous C programs by the author.
The current released version of the Maentwrog distribution is version 1.1 revision 2014.0923.
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!
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
-14are words that push 25 and -14 onto the stack. Extra characters at the end of the word are allowed, so
25.14both 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.
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 longs, 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 p v | - 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.
git clone https://git.catseye.tc/Maentwrog/
- Clean up README for revision release. Chris Pressey 6 years ago
- Expand tabs to spaces! Chris Pressey 6 years ago
- I'm a bit sick of the strdup() nonsense, so let's do this. Chris Pressey 6 years ago
- Force bin directory to exist; easier than creating it. Chris Pressey 6 years ago
- Missed 'em by _that_ much. Chris Pressey 6 years ago
- NetBSD: fix "warning: array subscript has type char" warnings. Chris Pressey 6 years ago
- Tweak Makefile and clean up all warnings (on recent Linux anyway.) Chris Pressey 6 years ago
- Improve Makefile. Clean up warnings in rdp.c. Chris Pressey 6 years ago
- Reduce compilation warnings. Chris Pressey 6 years ago
- Move Makefile to root dir, executables to bin. Chris Pressey 6 years ago