Initial import of Version 2001.1211 sources.
Cat's Eye Technologies
13 years ago
0 | Copyright (c)2001, Cat's Eye Technologies. | |
1 | All rights reserved. | |
2 | ||
3 | Redistribution and use in source and binary forms, with or without | |
4 | modification, are permitted provided that the following conditions | |
5 | are met: | |
6 | ||
7 | Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | ||
10 | Redistributions in binary form must reproduce the above copyright | |
11 | notice, this list of conditions and the following disclaimer in | |
12 | the documentation and/or other materials provided with the | |
13 | distribution. | |
14 | ||
15 | Neither the name of Cat's Eye Technologies nor the names of its | |
16 | contributors may be used to endorse or promote products derived | |
17 | from this software without specific prior written permission. | |
18 | ||
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
20 | CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
21 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
22 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE | |
24 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
25 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
27 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | POSSIBILITY OF SUCH DAMAGE. |
0 | <html><head> | |
1 | <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1"> | |
2 | <title>Cat's Eye Technologies: The Version Programming Language</title></head> | |
3 | <body> | |
4 | ||
5 | <h1>Version</h1> | |
6 | ||
7 | <p><font size=-1> <img src="/images/icons/copyright.gif" | |
8 | align=absmiddle width=12 height=12 alt="(c)" border=0>2001-2004 <a href="/">Cat's Eye Technologies</a>. All rights reserved.<br> | |
9 | This software is OSI Certified Open Source Software.<br> | |
10 | OSI Certified is a certification mark of the <a href="http://www.opensource.org/"><img | |
11 | src="/images/icons/webicon.gif" alt="[WWW]" border=0 width=12 height=12>Open Source Initiative</a>.<br> | |
12 | See the file <a href="license.txt">license.txt</a> for license information.</font></p> | |
13 | ||
14 | <h2>What is Version?</h2> | |
15 | ||
16 | <p>Version is a programming language based on the concept of | |
17 | <i>ignorance-spaces</i>. An ignorance-space is represented by a | |
18 | pattern (irregular expression.) All instructions in a Version | |
19 | program have a tag or label. Instructions with | |
20 | labels which match the current | |
21 | ignorance-space are ignored. Other instructions are | |
22 | executed sequentially. When the last instruction is reached, | |
23 | execution wraps around to the beginning of the program. The | |
24 | only way to halt a program is to put it in a state in which | |
25 | all instructions will be ignored.</p> | |
26 | ||
27 | <p>Other than this ignorance-space, there are no jumping or | |
28 | conditional execution mechanisms in Version.</p> | |
29 | ||
30 | <h2>Instructions</h2> | |
31 | ||
32 | <p>Each Version instruction must occur on its own line of | |
33 | source code, and looks like:</p> | |
34 | ||
35 | <ul> | |
36 | <code><i>label</i>: <i>destination</i> = <i>expression</i></code> | |
37 | </ul> | |
38 | ||
39 | <p>The label is a string. The destination is the name of | |
40 | a variable, or a special destination name listed below. The expression | |
41 | may be made up of prefix operators, string variables, and special | |
42 | expression terms, listed below.</p> | |
43 | ||
44 | <p>The result of executing an instruction is that a message containing the | |
45 | expression is sent to the destination. If the destination | |
46 | is a variable, this generally results in the state of the | |
47 | variable changing. This may not however hold true under | |
48 | all conditions - future extensions to Version may add further | |
49 | effects under prescribed conditions.</p> | |
50 | ||
51 | <h2>Special Destinations</h2> | |
52 | ||
53 | <ul> | |
54 | <li><code>OUTPUT</code> | |
55 | <p>Sending a message to OUTPUT causes the datum in question | |
56 | to appear on the standard output communications channel.</p></li> | |
57 | ||
58 | <li><code>IGNORE</code> | |
59 | <p>Sending a message to IGNORE constitutes a request to change | |
60 | from the current ignorance-space to a new one.</p></li> | |
61 | ||
62 | <li><code>CAT</code> | |
63 | <p>Sending a message to CAT concatenates a value to the last | |
64 | (non-Special) variable assigned (at runtime, not in source code). | |
65 | If there was never a variable assigned, the last variable assigned | |
66 | is considered to be DUANE for some reason.</p></li> | |
67 | ||
68 | <li><code>PUT</code> | |
69 | <p>Sending a message to PUT concatenates a value to the <i>name</i> of | |
70 | the last variable, and copies the value from the the last variable to the | |
71 | newly named variable. Used to simulate associative arrays.</p></li> | |
72 | ||
73 | <li><code>GET</code> | |
74 | <p>Like PUT, except it copies the value of the newly named variable | |
75 | into the last variable. Note that the name of the last variable does not | |
76 | actually change while using PUT or GET.</p></li> | |
77 | ||
78 | </ul> | |
79 | ||
80 | <h2>Special Expression Terms</h2> | |
81 | ||
82 | <ul> | |
83 | <li><code>INPUT</code> | |
84 | <p>Accessing the name INPUT causes the standard input communications | |
85 | channel to wait for a line of text and return it (complete with trailing | |
86 | newline.)</p></li> | |
87 | ||
88 | <li><code>IGNORE</code> | |
89 | <p>Accessing the name IGNORE allows the program to inquire as to the current | |
90 | ignorance-space.</p></li> | |
91 | ||
92 | <li><code>EOL</code> | |
93 | <p>The name EOL evaluates to the end-of-line character | |
94 | sequence apropriate for the system.</p></li> | |
95 | ||
96 | <li><code>EOF</code> | |
97 | <p>The variable EOF is actually a true variable, so its value can be | |
98 | reset if needed. It takes on the value <code>TRUE</code> (a string) should | |
99 | the end of the standard input channel be reached.</p></li> | |
100 | ||
101 | </ul> | |
102 | ||
103 | <h2>Functions</h2> | |
104 | ||
105 | <ul> | |
106 | <li><code>PRED <i>n</i></code> | |
107 | <p>Returns the predecessor of n, that is the integer that comes before | |
108 | n in the domain of integers, where n is a string containing an integer in | |
109 | decimal notation.</p></li> | |
110 | ||
111 | <li><code>SUCC <i>n</i></code> | |
112 | <p>Returns the successor of n, that is the integer that comes after | |
113 | n in the domain of integers, where n is a string containing an integer in | |
114 | decimal notation.</p></li> | |
115 | ||
116 | <li><code>CHOP <i>s</i></code> | |
117 | <p>Returns the string s with the last character missing.</p></li> | |
118 | ||
119 | <li><code>POP <i>s</i></code> | |
120 | <p>Returns the string s with the first character missing.</p></li> | |
121 | ||
122 | <li><code>LEN <i>s</i></code> | |
123 | <p>Returns the length of the string s as a string containing an | |
124 | integer in decimal notation.</p></li> | |
125 | ||
126 | </ul> | |
127 | ||
128 | <h2>Ignorance-Spaces</h2> | |
129 | ||
130 | <p>The current ignorance-space is accessed through the keyword IGNORE, | |
131 | whether as a destination or as a term in an expression.</p> | |
132 | ||
133 | <p>The ignorance-space is defined by an irregular expression, which is | |
134 | encoded in a string. An irregular expression is like a regular expression | |
135 | in that it contains special wildcard characters. | |
136 | The wildcard characters resemble those used in MS-DOS.</p> | |
137 | ||
138 | <ul> | |
139 | <li><code>?</code> - question mark - match any character</li> | |
140 | <li><code>*</code> - asterisk - match any number of characters</li> | |
141 | <li><code>|</code> - vertical bar - seperate alternatives</li> | |
142 | </ul> | |
143 | ||
144 | <p>Any characters, except ":", are allowed in labels, which are | |
145 | case sensitive. The characters "*", "?", and "|", if used, | |
146 | cannot be matched literally (use "?" to match them, or don't use them - | |
147 | for simplicity, wildcard characters cannot be "quoted".)</p> | |
148 | ||
149 | <p>So <code>DOG|CAT</code> would match <code>DOG</code> | |
150 | or <code>CAT</code> but not <code>cat</code> or <code>antelope</code> | |
151 | or <code>seahorse</code>. But <code>a*e</code> would match | |
152 | <code>antelope</code>. As would <code>a?t?l?p?</code>.</p> | |
153 | ||
154 | <h2>Conventions</h2> | |
155 | ||
156 | <p>For reasons that are not well known, the common filename extension for | |
157 | Version source files is <code>_7%</code> (underscore, seven, percent sign).</p> | |
158 | ||
159 | <p>Each source line which does not even contain a colon is treated as | |
160 | a comment.</p> | |
161 | ||
162 | </body></html> |
0 | This is a pretty sad game demo. | |
1 | START: ROOM = "VALLEY|BROOK|GLADE" | |
2 | CONT: IGNORE = ROOM | |
3 | VALLEY: OUTPUT = "You are standing in a valley." | |
4 | HILL: OUTPUT = "You are on top of a hill." | |
5 | BROOK: OUTPUT = "You are by a brook." | |
6 | GLADE: OUTPUT = "You are standing in a sun-dappled glade." | |
7 | ROOM: OUTPUT = EOL | |
8 | ROOM: DIR = CHOP INPUT | |
9 | ROOM: IGNORE = DIR | |
10 | ROOM: MASK = "VAPOURS" | |
11 | N: CAT = "|N" | |
12 | S: CAT = "|S" | |
13 | E: CAT = "|E" | |
14 | W: CAT = "|W" | |
15 | ROOM: IGNORE = MASK | |
16 | N: ROOM = "VALLEY|BROOK|GLADE" | |
17 | S: ROOM = "HILL|BROOK|GLADE" | |
18 | E: ROOM = "VALLEY|HILL|BROOK" | |
19 | W: ROOM = "VALLEY|HILL|GLADE" | |
20 | LASTLY: IGNORE = "START" |
0 | I: BEER = "99" | |
1 | 0: IGNORE = "I" | |
2 | 0: OUTPUT = BEER | |
3 | 0: OUTPUT = " bottles of beer on the wall," | |
4 | 0: OUTPUT = EOL | |
5 | 0: OUTPUT = BEER | |
6 | 0: OUTPUT = " bottles of beer," | |
7 | 0: OUTPUT = EOL | |
8 | 0: OUTPUT = "Take one down, pass it around," | |
9 | 0: OUTPUT = EOL | |
10 | 0: BEER = PRED BEER | |
11 | 0: OUTPUT = BEER | |
12 | 0: OUTPUT = " bottles of beer on the wall." | |
13 | 0: OUTPUT = EOL | |
14 | 0: OUTPUT = EOL | |
15 | 0: FOO = BEER | |
16 | 0: CAT = "|I" | |
17 | 0: IGNORE = FOO |
0 | #!/usr/local/bin/perl -w | |
1 | ||
2 | # Version, a programming language based on ignorance-spaces | |
3 | # Dec 11 2001, Chris Pressey, Cat's Eye Technologies | |
4 | ||
5 | # Copyright (c)2001, Cat's Eye Technologies. | |
6 | # All rights reserved. | |
7 | # | |
8 | # Redistribution and use in source and binary forms, with or without | |
9 | # modification, are permitted provided that the following conditions | |
10 | # are met: | |
11 | # | |
12 | # Redistributions of source code must retain the above copyright | |
13 | # notice, this list of conditions and the following disclaimer. | |
14 | # | |
15 | # Redistributions in binary form must reproduce the above copyright | |
16 | # notice, this list of conditions and the following disclaimer in | |
17 | # the documentation and/or other materials provided with the | |
18 | # distribution. | |
19 | # | |
20 | # Neither the name of Cat's Eye Technologies nor the names of its | |
21 | # contributors may be used to endorse or promote products derived | |
22 | # from this software without specific prior written permission. | |
23 | # | |
24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
25 | # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
26 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
27 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
28 | # DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE | |
29 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
30 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
31 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
32 | # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
33 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
34 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
35 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
36 | # POSSIBILITY OF SUCH DAMAGE. | |
37 | ||
38 | ### BEGIN version[.pl] ### | |
39 | ||
40 | # usage: [perl] version[.pl] version-source-filename | |
41 | ||
42 | ### INITIALIZATION ### | |
43 | ||
44 | # Open and read source file. | |
45 | ||
46 | $|=1; | |
47 | if (open(FILE, $ARGV[0])) | |
48 | { | |
49 | @program = <FILE>; | |
50 | } else | |
51 | { | |
52 | die "Can't open file '$ARGV[0]' for reading"; | |
53 | } | |
54 | close FILE; | |
55 | ||
56 | # Set initial values of variables. | |
57 | ||
58 | $ip = 0; # instruction pointer | |
59 | $ig = ""; # ignore-space | |
60 | $last_var = "DUANE"; # last variable assigned to | |
61 | $ignord = 0; # number of lines ignored | |
62 | ||
63 | ### MAIN LOOP ### | |
64 | ||
65 | while(1) | |
66 | { | |
67 | $d = $program[$ip]; # fetch line from program | |
68 | if ($d =~ /^(.*?)\:(.*)$/) # if it's an instruction | |
69 | { | |
70 | $lab = $1; | |
71 | $ins = $2; | |
72 | if ($lab !~ /$ig/) # and it's not being ignored | |
73 | { | |
74 | execute($ins); # do it | |
75 | $ignord = 0; | |
76 | } else | |
77 | { | |
78 | $ignord++; | |
79 | } | |
80 | } else | |
81 | { | |
82 | $ignord++; | |
83 | } | |
84 | exit(0) if $ignord > $#program; # halt if all lines are ignored | |
85 | $ip++; # otherwise, keep going and | |
86 | $ip = 0 if $ip > $#program; # wrap around when necessary | |
87 | } | |
88 | ||
89 | ### SUBROUTINES ### | |
90 | ||
91 | # execute($string) - Execute a line of source code. | |
92 | ||
93 | sub execute | |
94 | { | |
95 | my $ins = shift; | |
96 | if ($ins =~ /^\s*(.*?)\s*\=\s*(.*)\s*$/) | |
97 | { | |
98 | $lv = uc $1; | |
99 | $rv = $2; | |
100 | $v = calculate($rv); | |
101 | if ($lv eq 'OUTPUT') | |
102 | { | |
103 | print $v; | |
104 | } | |
105 | elsif ($lv eq 'IGNORE') | |
106 | { | |
107 | $ig = convert_regexp($v); | |
108 | } | |
109 | elsif ($lv eq 'CAT') | |
110 | { | |
111 | $var{$last_var} .= $v; | |
112 | } | |
113 | elsif ($lv eq 'PUT') | |
114 | { | |
115 | $var{$last_var . $v} = $var{$last_var}; | |
116 | } | |
117 | elsif ($lv eq 'GET') | |
118 | { | |
119 | $var{$last_var} = $var{$last_var . $v}; | |
120 | } | |
121 | else | |
122 | { | |
123 | $var{$lv} = $v; | |
124 | $last_var = $lv; | |
125 | } | |
126 | } else | |
127 | { | |
128 | die "Badly formed instruction '$ins'"; | |
129 | } | |
130 | } | |
131 | ||
132 | # calculate($string) - Determine the value of an expression. | |
133 | ||
134 | sub calculate | |
135 | { | |
136 | my $expr = shift; | |
137 | if ($expr =~ /^\s*\"(.*?)\"\s*$/) | |
138 | { | |
139 | return $1; # it's a literal string | |
140 | } elsif ($expr =~ /^\s*(.*?)\s+(.*)\s*$/) | |
141 | { | |
142 | my $func = uc $1; # it's a function | |
143 | my $rv = $2; | |
144 | my $v = calculate($rv); # recurse; get rest of line first | |
145 | ||
146 | if ($func eq 'PRED') # apply appropriate transform | |
147 | { | |
148 | $v = 0+$v-1; | |
149 | return("$v"); | |
150 | } | |
151 | elsif ($func eq 'SUCC') | |
152 | { | |
153 | $v = 0+$v+1; | |
154 | return("$v"); | |
155 | } | |
156 | elsif ($func eq 'CHOP') | |
157 | { | |
158 | chop $v; | |
159 | return("$v"); | |
160 | } | |
161 | elsif ($func eq 'POP') | |
162 | { | |
163 | $v =~ s/^.//s; | |
164 | return("$v"); | |
165 | } | |
166 | elsif ($func eq 'LEN') | |
167 | { | |
168 | $v = length($v); | |
169 | return("$v"); | |
170 | } | |
171 | else | |
172 | { | |
173 | die "Unknown function $func"; | |
174 | } | |
175 | } else # it's an identifier | |
176 | { | |
177 | if (uc($expr) eq 'INPUT') # check if it's a special identifier | |
178 | { | |
179 | my $r = <STDIN>; | |
180 | if (not defined $r) | |
181 | { | |
182 | $var{'EOF'} = 'TRUE'; | |
183 | $r = ""; | |
184 | } | |
185 | return $r; | |
186 | } | |
187 | elsif (uc($expr) eq 'IGNORE') | |
188 | { | |
189 | return $ig; | |
190 | } | |
191 | elsif (uc($expr) eq 'EOL') | |
192 | { | |
193 | return "\n"; | |
194 | } | |
195 | else # not so special, just a variable | |
196 | { | |
197 | $var{$expr} = '' if not defined $var{$expr}; | |
198 | return $var{$expr}; | |
199 | } | |
200 | } | |
201 | } | |
202 | ||
203 | # convert_regexp($string) - Turn a Version irregular expression into | |
204 | # a Perl regular expression | |
205 | ||
206 | sub convert_regexp | |
207 | { | |
208 | my $reg = shift; | |
209 | $reg = quotemeta($reg); # make sure any perlisms are caught | |
210 | $reg =~ s/\\\?/\./g; # ?'s become .'s | |
211 | $reg =~ s/\\\*/\.\*\?/g; # *'s become .*?'s | |
212 | $reg =~ s/\\\|/\|/g; # |'s stay as |'s | |
213 | return '^(' . $reg . ')$'; # grouped, with bos and eos symbols | |
214 | } | |
215 | ||
216 | ### END of version[.pl] ### |