Commits

Anonymous committed c7a68cc

Initial import of Version 2001.1211 sources.

Comments (0)

Files changed (7)

+Copyright (c)2001, Cat's Eye Technologies.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+  Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+
+  Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+  Neither the name of Cat's Eye Technologies nor the names of its
+  contributors may be used to endorse or promote products derived
+  from this software without specific prior written permission. 
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE. 
+<html><head>
+    <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
+    <title>Cat's Eye Technologies: The Version Programming Language</title></head>
+<body>
+
+<h1>Version</h1>
+
+<p><font size=-1>&nbsp;<img src="/images/icons/copyright.gif"
+   align=absmiddle width=12 height=12 alt="(c)" border=0>2001-2004 <a href="/">Cat's Eye Technologies</a>.  All rights reserved.<br>
+    This software is OSI Certified Open Source Software.<br>
+    OSI Certified is a certification mark of the <a href="http://www.opensource.org/"><img
+    src="/images/icons/webicon.gif" alt="[WWW]" border=0 width=12 height=12>Open Source Initiative</a>.<br>
+    See the file <a href="license.txt">license.txt</a> for license information.</font></p>
+
+<h2>What is Version?</h2>
+
+<p>Version is a programming language based on the concept of
+<i>ignorance-spaces</i>.  An ignorance-space is represented by a
+pattern (irregular expression.)  All instructions in a Version
+program have a tag or label.  Instructions with
+labels which match the current
+ignorance-space are ignored.  Other instructions are
+executed sequentially.  When the last instruction is reached,
+execution wraps around to the beginning of the program.  The
+only way to halt a program is to put it in a state in which
+all instructions will be ignored.</p>
+
+<p>Other than this ignorance-space, there are no jumping or
+conditional execution mechanisms in Version.</p>
+
+<h2>Instructions</h2>
+
+<p>Each Version instruction must occur on its own line of
+source code, and looks like:</p>
+
+<ul>
+<code><i>label</i>: <i>destination</i> = <i>expression</i></code>
+</ul>
+
+<p>The label is a string.  The destination is the name of
+a variable, or a special destination name listed below.  The expression
+may be made up of prefix operators, string variables, and special
+expression terms, listed below.</p>
+
+<p>The result of executing an instruction is that a message containing the
+expression is sent to the destination.  If the destination
+is a variable, this generally results in the state of the
+variable changing.  This may not however hold true under
+all conditions - future extensions to Version may add further
+effects under prescribed conditions.</p>
+
+<h2>Special Destinations</h2>
+
+<ul>
+<li><code>OUTPUT</code>
+<p>Sending a message to OUTPUT causes the datum in question
+to appear on the standard output communications channel.</p></li>
+
+<li><code>IGNORE</code>
+<p>Sending a message to IGNORE constitutes a request to change
+from the current ignorance-space to a new one.</p></li>
+
+<li><code>CAT</code>
+<p>Sending a message to CAT concatenates a value to the last
+(non-Special) variable assigned (at runtime, not in source code).
+If there was never a variable assigned, the last variable assigned
+is considered to be DUANE for some reason.</p></li>
+
+<li><code>PUT</code>
+<p>Sending a message to PUT concatenates a value to the <i>name</i> of
+the last variable, and copies the value from the the last variable to the
+newly named variable.  Used to simulate associative arrays.</p></li>
+
+<li><code>GET</code>
+<p>Like PUT, except it copies the value of the newly named variable
+into the last variable.  Note that the name of the last variable does not
+actually change while using PUT or GET.</p></li>
+
+</ul>
+
+<h2>Special Expression Terms</h2>
+
+<ul>
+<li><code>INPUT</code>
+<p>Accessing the name INPUT causes the standard input communications
+channel to wait for a line of text and return it (complete with trailing
+newline.)</p></li>
+
+<li><code>IGNORE</code>
+<p>Accessing the name IGNORE allows the program to inquire as to the current
+ignorance-space.</p></li>
+
+<li><code>EOL</code>
+<p>The name EOL evaluates to the end-of-line character
+sequence apropriate for the system.</p></li>
+
+<li><code>EOF</code>
+<p>The variable EOF is actually a true variable, so its value can be
+reset if needed.  It takes on the value <code>TRUE</code> (a string) should
+the end of the standard input channel be reached.</p></li>
+
+</ul>
+
+<h2>Functions</h2>
+
+<ul>
+<li><code>PRED <i>n</i></code>
+<p>Returns the predecessor of n, that is the integer that comes before
+n in the domain of integers, where n is a string containing an integer in
+decimal notation.</p></li>
+
+<li><code>SUCC <i>n</i></code>
+<p>Returns the successor of n, that is the integer that comes after
+n in the domain of integers, where n is a string containing an integer in
+decimal notation.</p></li>
+
+<li><code>CHOP <i>s</i></code>
+<p>Returns the string s with the last character missing.</p></li>
+
+<li><code>POP <i>s</i></code>
+<p>Returns the string s with the first character missing.</p></li>
+
+<li><code>LEN <i>s</i></code>
+<p>Returns the length of the string s as a string containing an
+integer in decimal notation.</p></li>
+
+</ul>
+
+<h2>Ignorance-Spaces</h2>
+
+<p>The current ignorance-space is accessed through the keyword IGNORE,
+whether as a destination or as a term in an expression.</p>
+
+<p>The ignorance-space is defined by an irregular expression, which is
+encoded in a string.  An irregular expression is like a regular expression
+in that it contains special wildcard characters.
+The wildcard characters resemble those used in MS-DOS.</p>
+
+<ul>
+<li><code>?</code> - question mark - match any character</li>
+<li><code>*</code> - asterisk - match any number of characters</li>
+<li><code>|</code> - vertical bar - seperate alternatives</li>
+</ul>
+
+<p>Any characters, except ":", are allowed in labels, which are
+case sensitive.  The characters "*", "?", and "|", if used,
+cannot be matched literally (use "?" to match them, or don't use them -
+for simplicity, wildcard characters cannot be "quoted".)</p>
+
+<p>So <code>DOG|CAT</code> would match <code>DOG</code>
+or <code>CAT</code> but not <code>cat</code> or <code>antelope</code>
+or <code>seahorse</code>.  But <code>a*e</code> would match
+<code>antelope</code>.  As would <code>a?t?l?p?</code>.</p>
+
+<h2>Conventions</h2>
+
+<p>For reasons that are not well known, the common filename extension for
+Version source files is <code>_7%</code> (underscore, seven, percent sign).</p>
+
+<p>Each source line which does not even contain a colon is treated as
+a comment.</p>
+
+</body></html>
+This is a pretty sad game demo.
+START: ROOM = "VALLEY|BROOK|GLADE"
+CONT: IGNORE = ROOM
+VALLEY: OUTPUT = "You are standing in a valley."
+HILL: OUTPUT = "You are on top of a hill."
+BROOK: OUTPUT = "You are by a brook."
+GLADE: OUTPUT = "You are standing in a sun-dappled glade."
+ROOM: OUTPUT = EOL
+ROOM: DIR = CHOP INPUT
+ROOM: IGNORE = DIR
+ROOM: MASK = "VAPOURS"
+N: CAT = "|N"
+S: CAT = "|S"
+E: CAT = "|E"
+W: CAT = "|W"
+ROOM: IGNORE = MASK
+N: ROOM = "VALLEY|BROOK|GLADE"
+S: ROOM = "HILL|BROOK|GLADE"
+E: ROOM = "VALLEY|HILL|BROOK"
+W: ROOM = "VALLEY|HILL|GLADE"
+LASTLY: IGNORE = "START"
+I: BEER   = "99"
+0: IGNORE = "I"
+0: OUTPUT = BEER
+0: OUTPUT = " bottles of beer on the wall,"
+0: OUTPUT = EOL
+0: OUTPUT = BEER
+0: OUTPUT = " bottles of beer,"
+0: OUTPUT = EOL
+0: OUTPUT = "Take one down, pass it around,"
+0: OUTPUT = EOL
+0: BEER   = PRED BEER
+0: OUTPUT = BEER
+0: OUTPUT = " bottles of beer on the wall."
+0: OUTPUT = EOL
+0: OUTPUT = EOL
+0: FOO    = BEER
+0: CAT    = "|I"
+0: IGNORE = FOO
+TRUE: OUTPUT = INPUT
+TRUE: IGNORE = EOF
+HELLO: OUTPUT = "Hello, world!"
+HELLO: OUTPUT = EOL
+HELLO: IGNORE = "*"
+#!/usr/local/bin/perl -w
+
+# Version, a programming language based on ignorance-spaces
+# Dec 11 2001, Chris Pressey, Cat's Eye Technologies
+
+# Copyright (c)2001, Cat's Eye Technologies.
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#   Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# 
+#   Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# 
+#   Neither the name of Cat's Eye Technologies nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission. 
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE. 
+
+### BEGIN version[.pl] ###
+
+# usage: [perl] version[.pl] version-source-filename
+
+### INITIALIZATION ###
+
+# Open and read source file.
+
+$|=1;
+if (open(FILE, $ARGV[0]))
+{
+  @program = <FILE>;
+} else
+{
+  die "Can't open file '$ARGV[0]' for reading";
+}
+close FILE;
+
+# Set initial values of variables.
+
+$ip = 0;                          # instruction pointer
+$ig = "";                         # ignore-space
+$last_var = "DUANE";              # last variable assigned to
+$ignord = 0;                      # number of lines ignored
+
+### MAIN LOOP ###
+
+while(1)
+{
+  $d = $program[$ip];             # fetch line from program
+  if ($d =~ /^(.*?)\:(.*)$/)      # if it's an instruction
+  {
+    $lab = $1;
+    $ins = $2;
+    if ($lab !~ /$ig/)            # and it's not being ignored
+    {
+      execute($ins);              # do it
+      $ignord = 0;
+    } else
+    {
+      $ignord++;
+    }
+  } else
+  {
+    $ignord++;
+  }
+  exit(0) if $ignord > $#program; # halt if all lines are ignored
+  $ip++;                          # otherwise, keep going and
+  $ip = 0 if $ip > $#program;     # wrap around when necessary
+}
+
+### SUBROUTINES ###
+
+# execute($string) - Execute a line of source code.
+
+sub execute
+{
+  my $ins = shift;
+  if ($ins =~ /^\s*(.*?)\s*\=\s*(.*)\s*$/)
+  {
+    $lv = uc $1;
+    $rv = $2;
+    $v = calculate($rv);
+    if ($lv eq 'OUTPUT')
+    {
+      print $v;
+    }
+    elsif ($lv eq 'IGNORE')
+    {
+      $ig = convert_regexp($v);
+    }
+    elsif ($lv eq 'CAT')
+    {
+      $var{$last_var} .= $v;
+    }
+    elsif ($lv eq 'PUT')
+    {
+      $var{$last_var . $v} = $var{$last_var};
+    }
+    elsif ($lv eq 'GET')
+    {
+      $var{$last_var} = $var{$last_var . $v};
+    }
+    else
+    {
+      $var{$lv} = $v;
+      $last_var = $lv;
+    }
+  } else
+  {
+    die "Badly formed instruction '$ins'";
+  }
+}
+
+# calculate($string) - Determine the value of an expression.
+
+sub calculate
+{
+  my $expr = shift;
+  if ($expr =~ /^\s*\"(.*?)\"\s*$/)
+  {
+    return $1;                    # it's a literal string
+  } elsif ($expr =~ /^\s*(.*?)\s+(.*)\s*$/)
+  {
+    my $func = uc $1;             # it's a function
+    my $rv = $2;
+    my $v = calculate($rv);       # recurse; get rest of line first
+    
+    if ($func eq 'PRED')          # apply appropriate transform
+    {
+      $v = 0+$v-1;
+      return("$v");
+    }
+    elsif ($func eq 'SUCC')
+    {
+      $v = 0+$v+1;
+      return("$v");
+    }
+    elsif ($func eq 'CHOP')
+    {
+      chop $v;
+      return("$v");
+    }
+    elsif ($func eq 'POP')
+    {
+      $v =~ s/^.//s;
+      return("$v");
+    }
+    elsif ($func eq 'LEN')
+    {
+      $v = length($v);
+      return("$v");
+    }
+    else
+    {
+      die "Unknown function $func";
+    }
+  } else                          # it's an identifier
+  {
+    if (uc($expr) eq 'INPUT')     # check if it's a special identifier
+    {
+      my $r = <STDIN>;
+      if (not defined $r)
+      {
+        $var{'EOF'} = 'TRUE';
+        $r = "";
+      }
+      return $r;
+    }
+    elsif (uc($expr) eq 'IGNORE')
+    {
+      return $ig;
+    }
+    elsif (uc($expr) eq 'EOL')
+    {
+      return "\n";
+    }
+    else                          # not so special, just a variable
+    {
+      $var{$expr} = '' if not defined $var{$expr};
+      return $var{$expr};
+    }
+  }
+}
+
+# convert_regexp($string) - Turn a Version irregular expression into
+#                           a Perl regular expression
+
+sub convert_regexp
+{
+  my $reg = shift;
+  $reg = quotemeta($reg);         # make sure any perlisms are caught
+  $reg =~ s/\\\?/\./g;            # ?'s become .'s
+  $reg =~ s/\\\*/\.\*\?/g;        # *'s become .*?'s
+  $reg =~ s/\\\|/\|/g;            # |'s stay as |'s
+  return '^(' . $reg . ')$';      # grouped, with bos and eos symbols
+}
+
+### END of version[.pl] ###