git @ Cat's Eye Technologies Maentwrog / 7c28c27
Merge pull request #1 from catseye/develop-2018-1 Release version 1.1 revision 2018.0608 Chris Pressey authored 4 years ago GitHub committed 4 years ago
3 changed file(s) with 101 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
+0
-94
README.markdown less more
0 The Maentwrog Programming Language
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 -------------
15
16 This is a rudimentary specification for the Maentwrog programming
17 language.
18
19 This information, and the example programs in this distribution, were
20 taken from the esolangs.org wiki page for Maentwrog, written by
21 User:Marinus and (like all esowiki articles) placed in the public
22 domain. Thanks Marinus!
23
24 ### Syntax ###
25
26 A Maentwrog program consists of a series of words, separated by
27 whitespace. Words can contain any character except whitespace. The way
28 these words are executed depends on the character they begin with.
29
30 - A word that consists of digits is taken as an integer and pushed. A
31 minus sign may be used to make negative numbers, so `25` and `-14`
32 are words that push 25 and -14 onto the stack. Extra characters at
33 the end of the word are allowed, so `25abc` and `25.14` both also
34 push 25.
35 - A word that isn't a number is treated as either a function or a
36 variable. If the word is defined as a function, it is executed; if
37 it's a variable, its current value is pushed to the stack. Using an
38 undefined word results in an error, though this doesn't stop further
39 execution of the program.
40 - To define a word as a function, use the syntax
41 `: new-word words to execute ;` (as in Forth). Redefining a word is
42 not allowed, and neither are nested function definitions.
43 - To define a word as a variable, use the syntax `*varname`. This must
44 be done before using a variable.
45
46 Additionally, words (except number words) can take one of a list of
47 prefixes, changing how the word is executed.
48
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.
61
62 #### Predefined words ####
63
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.
92
93
0 The Maentwrog Programming Language
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 document, and some example Maentwrog programs.
8
9 It also contains a few other miscellaneous contemporaneous C programs by
10 the author, for historical interest.
11
12 The specification and example programs in this distribution were
13 taken from the esolangs.org wiki page for Maentwrog that was written by
14 User:Marinus. Thanks Marinus!
15
16 All of these materials are in the public domain.
17
18 The current released version of the Maentwrog distribution is
19 version 1.1 revision 2018.0608.
0 The Maentwrog Programming Language
1 ==================================
2
3 This is a rudimentary specification for the Maentwrog programming
4 language.
5
6 This information, and the example programs in this distribution, were
7 taken from the esolangs.org wiki page for Maentwrog, written by
8 User:Marinus and (like all esowiki articles) placed in the public
9 domain. Thanks Marinus!
10
11 ### Syntax ###
12
13 A Maentwrog program consists of a series of words, separated by
14 whitespace. Words can contain any character except whitespace. The way
15 these words are executed depends on the character they begin with.
16
17 - A word that consists of digits is taken as an integer and pushed. A
18 minus sign may be used to make negative numbers, so `25` and `-14`
19 are words that push 25 and -14 onto the stack. Extra characters at
20 the end of the word are allowed, so `25abc` and `25.14` both also
21 push 25.
22 - A word that isn't a number is treated as either a function or a
23 variable. If the word is defined as a function, it is executed; if
24 it's a variable, its current value is pushed to the stack. Using an
25 undefined word results in an error, though this doesn't stop further
26 execution of the program.
27 - To define a word as a function, use the syntax
28 `: new-word words to execute ;` (as in Forth). Redefining a word is
29 not allowed, and neither are nested function definitions.
30 - To define a word as a variable, use the syntax `*varname`. This must
31 be done before using a variable.
32
33 Additionally, words (except number words) can take one of a list of
34 prefixes, changing how the word is executed.
35
36 Prefix Action Example Result
37 ----- ------ ------- ------
38 = Assign to variable =foo A value popped from the stack is
39 assigned to the variable foo.
40 @ If @bye Pop value, stop the program (see
41 predefined words) if it isn't 0.
42 [ While [xyz Pop value, if it's not 0 execute
43 word xyz, then pop another value
44 and do it again; continue until a
45 0 is popped.
46 $ Repeat $. Pop value, then output that many
47 values from the stack.
48
49 #### Predefined words ####
50
51 Word Stack effect Description
52 ---- ------------ -----------
53 bye Stop program immediately.
54 rem ... ; Comment. (Ignore all words between rem and ;.)
55 : word ... ; Define a new word.
56 debug Turn on debugging (outputs all words executed).
57 vars Output a list of currently defined variables
58 and their values.
59 words Output a list of currently defined words.
60 alloc n | ptr Allocate memory for n C longs, returns a pointer.
61 free ptr | - Free memory at pointer.
62 size - | n Push stack size.
63 dup a | a a Duplicate top of stack.
64 swap a b | b a Swap the two topmost stack values.
65 pop a | - Remove top value from stack.
66 get ptr | value Push value at pointer to stack (C `*ptr`).
67 put p v | - Store value at pointer (C `*ptr = val`).
68 rnd - | n Push random value.
69 > a b | (a>b) Push 1 if a is greater than b, else 0.
70 < a b | (a<b) Push 1 if a is less than b, else 0.
71 == undefined Undefined.
72 . n | - Pop a value, output as integer, adding a newline.
73 .. n | - Pop a value, output as an ASCII character.
74 mod a b | (a%b) Modulo.
75 + a b | (a+b) Addition.
76 - a b | (a-b) Subtraction.
77 * a b | (a*b) Multiplication.
78 / a b | (a/b) Division, result is rounded towards 0.
79
80