Commits

Anonymous committed d003d7c

Initial import of SMETANA 2004.0227 sources.

Comments (0)

Files changed (8)

+<html><head>
+    <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
+    <title>Cat's Eye Technologies: The SMETANA Language</title>
+</head>
+<body   bgcolor="#ffffff" text="#000000" link="#439773"
+     vlink="#ac9444" alink="#0cd490"
+     background="/img/sinewhite.gif" >
+<h1>SMETANA</h1>
+<P>Chris Pressey, 1994(ish)
+<hr>
+
+<p>A long time ago (about six years ago),
+I was writing some amusing notes to
+myself and among them was an "algorithm
+that'll never fly," which went
+something like:
+
+<p>&nbsp;&nbsp;1. Swap steps one and two.
+<br>&nbsp;&nbsp;2. Flap wings.
+<br>&nbsp;&nbsp;3. Go back to step one.
+
+<p>It then occurred to me that reducing
+this form to the absurd (removing
+the "Flap wings" instruction) just <i>might</i>
+fail to yield a totally untractable language.
+
+<p>I originally wrote the interpreter as a Visual Basic
+application and named it SMETANA - both an acronym
+for "Self-Modifying, Extremely Tiny AutomatoN
+Application", and a reference to the composer of
+the same name.
+
+<ul><p><i>Turns out that the word</i> smetana <i>is
+also Russian for</i> sour cream<i>.  What do you know?
+Finally, I join the all-too-exclusive club of people
+who have invented a language
+named after a foodstuff!</i></ul>
+
+<p>The dsitribution available here is a much better
+implementation of the SMETANA interpreter in
+a much more device-independent and scalable form.
+I have retained the English syntax exactly.  The
+program ends when it tries to peform step
+number <i>n</i>, where <i>n</i> is one plus the number
+of steps given in the source.
+
+<!--
+<p>Todo: mine information about SMETANA's Turing-Complete
+status from the e-mail archives
+-->
+
+<p>Syntax of the SMETANA Language:
+
+<pre>  Smetana ::= Step {".\n" Step} ".".
+  Step    ::= "Step" Integer "." (GoTo | Swap).
+  GoTo    ::= "Go" "to" "step" Integer.
+  Swap    ::= "Swap" "step" Integer "with" "step" Integer.
+  Integer ::= "0".."9" {"0".."9"}.</pre>
+
+</body></html>
+perl randsmet.pl 20 > cool2.sme
+perl smetana.pl cool2.sme -d cls -m 500
+Step 1. Swap step 1 with step 36.
+Step 2. Go to step 1.
+Step 3. Swap step 28 with step 33.
+Step 4. Swap step 4 with step 13.
+Step 5. Go to step 38.
+Step 6. Swap step 16 with step 8.
+Step 7. Go to step 22.
+Step 8. Go to step 26.
+Step 9. Swap step 30 with step 10.
+Step 10. Go to step 12.
+Step 11. Swap step 39 with step 8.
+Step 12. Swap step 28 with step 5.
+Step 13. Go to step 28.
+Step 14. Swap step 35 with step 15.
+Step 15. Swap step 12 with step 5.
+Step 16. Swap step 4 with step 12.
+Step 17. Swap step 33 with step 28.
+Step 18. Go to step 13.
+Step 19. Swap step 29 with step 18.
+Step 20. Go to step 39.
+Step 21. Go to step 22.
+Step 22. Swap step 35 with step 4.
+Step 23. Swap step 39 with step 38.
+Step 24. Go to step 2.
+Step 25. Swap step 25 with step 27.
+Step 26. Swap step 3 with step 36.
+Step 27. Swap step 22 with step 34.
+Step 28. Swap step 10 with step 16.
+Step 29. Go to step 3.
+Step 30. Go to step 18.
+Step 31. Swap step 2 with step 25.
+Step 32. Swap step 33 with step 26.
+Step 33. Go to step 4.
+Step 34. Swap step 11 with step 22.
+Step 35. Swap step 25 with step 27.
+Step 36. Swap step 18 with step 10.
+Step 37. Swap step 13 with step 25.
+Step 38. Swap step 16 with step 15.
+Step 39. Swap step 19 with step 8.
+Step 40. Swap step 30 with step 34.
+Step 41. Go to step 34.
+Step 42. Swap step 29 with step 16.
+Step 43. Go to step 11.
+Step 1. Go to step 4.
+Step 2. Go to step 5.
+Step 3. Go to step 17.
+Step 4. Swap step 6 with step 12.
+Step 5. Swap step 15 with step 1.
+Step 6. Go to step 12.
+Step 7. Go to step 2.
+Step 8. Go to step 2.
+Step 9. Go to step 1.
+Step 10. Swap step 18 with step 12.
+Step 11. Go to step 11.
+Step 12. Swap step 14 with step 17.
+Step 13. Swap step 9 with step 20.
+Step 14. Go to step 9.
+Step 15. Swap step 4 with step 6.
+Step 16. Swap step 1 with step 20.
+Step 17. Swap step 13 with step 8.
+Step 18. Swap step 4 with step 13.
+Step 19. Swap step 4 with step 4.
+Step 20. Go to step 17.
+Step 1. Swap step 1 with step 36.
+Step 2. Go to step 1.
+Step 3. Swap step 28 with step 33.
+Step 4. Swap step 4 with step 13.
+Step 5. Go to step 38.
+Step 6. Swap step 16 with step 8.
+Step 7. Go to step 22.
+Step 8. Go to step 26.
+Step 9. Swap step 30 with step 10.
+Step 10. Go to step 12.
+Step 11. Swap step 39 with step 8.
+Step 12. Swap step 28 with step 5.
+Step 13. Go to step 28.
+Step 14. Swap step 35 with step 15.
+Step 15. Swap step 12 with step 5.
+Step 16. Swap step 4 with step 12.
+Step 17. Swap step 33 with step 28.
+Step 18. Go to step 13.
+Step 19. Swap step 29 with step 18.
+Step 20. Go to step 39.
+Step 21. Go to step 22.
+Step 22. Swap step 35 with step 4.
+Step 23. Swap step 39 with step 38.
+Step 24. Go to step 2.
+Step 25. Swap step 25 with step 27.
+Step 26. Swap step 3 with step 36.
+Step 27. Swap step 22 with step 34.
+Step 28. Swap step 10 with step 16.
+Step 29. Go to step 3.
+Step 30. Go to step 18.
+Step 31. Swap step 2 with step 25.
+Step 32. Swap step 33 with step 26.
+Step 33. Go to step 4.
+Step 34. Swap step 11 with step 22.
+Step 35. Swap step 25 with step 27.
+Step 36. Swap step 18 with step 10.
+Step 37. Swap step 13 with step 25.
+Step 38. Swap step 16 with step 15.
+Step 39. Swap step 19 with step 8.
+Step 40. Swap step 30 with step 34.
+Step 41. Go to step 34.
+Step 42. Swap step 29 with step 16.
+Step 43. Go to step 11.
+Step 1. Swap step 1 with step 2.
+Step 2. Go to step 2.
+Step 3. Go to step 1.
+#!/usr/local/bin/perl -w
+
+# randsmet[.pl] v2000.03.01 Cat's Eye Technologies
+# Generate a random SMETANA program
+# This work is part of the Public Domain.
+
+### MAIN ###
+
+$| = 1;
+if ($#ARGV == -1)
+{
+  print "usage: randsmet <integer>\n";
+  exit(1);
+}
+$steps = shift @ARGV;
+for($i=1;$i<=$steps;$i++)
+{
+  print "Step $i. ";
+  if (rand > 0.5)
+  {
+    print "Go to step " . int(rand($steps)+1) . ".\n";
+  } else
+  {
+    print "Swap step " . int(rand($steps)+1) . " with step " .
+          int(rand($steps)+1) . ".\n";
+  }
+}
+
+### END ###
+

script/smetana.pl

+#!/usr/bin/perl -w
+
+### BEGIN smetana.pl ###
+
+# smetana[.pl] v2004.0227 Cat's Eye Technologies
+# Interpreter/Debugger for the SMETANA language
+# This work is part of the Public Domain.
+
+### GLOBALS ###
+
+$[ = 1;
+@step = ();
+$cycle = 1;
+$curstep = 1;
+$maxcycle = 0;
+
+### SUBROUTINES ###
+
+sub load_source_file # into global list variable @step
+{
+  my $fn = shift @_;
+  my $rs = 1; my $x = '';
+
+  @step = ();
+  open FILE, "<$fn";
+  while(defined($x = <FILE>))
+  {
+    if ($x =~ /^\s*Step\s*(\d+)\s*\.\s*(.*?)$/io)
+    {
+      my $x = $2;
+      if ($1 == $rs)
+      {
+        if ($x =~ /^Go\s*to\s*step\s*(\d+)\s*\.\s*$/io)
+        {
+          push @step, [1, $1];
+        } elsif ($x =~ /^Swap\s*step\s*(\d+)\s*with\s*step\s*(\d+)\s*\.\s*$/io)
+        {
+          push @step, [0, $1, $2];
+        } else
+        {
+          print STDERR "SMETANA: Triple Boo!  " .
+	               "Insulting instruction in step $rs.\n";
+          return;
+        }
+        $rs++;
+      } else
+      {
+        print STDERR "SMETANA: Double Boo!  " .
+	             "Line $rs contains wrong step, step $1.\n";
+        return;
+      }
+    } else
+    {
+      print STDERR "SMETANA: Boo!  Line $rs does not contain a step.\n";
+      return;
+    }
+  }
+}
+
+sub display_program
+{
+  my $i = 1;
+  while (defined($step[$i]))
+  {
+    print "Step $i. ";
+    if ($step[$i][1])
+    {
+      print "Go to step " . $step[$i][2] . ".\n";
+    } else
+    {
+      print "Swap step " . $step[$i][2] . " with step " . $step[$i][3] . ".\n";
+    }
+    $i++;
+  }
+  print "\n";
+}
+
+### MAIN ###
+
+$| = 1;
+if ($#ARGV == 0)
+{
+  print <<'EOT';
+smetana[.pl] v2004.0227 - Interpreter/Debugger for the SMETANA language
+Chris Pressey, Cat's Eye Technologies.
+This work is part of the Public Domain.
+
+Usage:
+  [perl] smetana[.pl] inputfile {-d binfile | -m integer}
+  inputfile: text file to use as SMETANA source file.
+  -d binfile: optional program to shell between program states (e.g. cls)
+  -m integer: optional limit to number of states (to avoid infinite loops)
+EOT
+  exit(1);
+}
+
+load_source_file shift @ARGV;
+
+while (defined $ARGV[1])
+{
+  $a = shift @ARGV;
+  if ($a eq '-d')
+  {
+    $xbefore = shift @ARGV;
+  } elsif ($a eq '-m')
+  {
+    $maxcycle += shift @ARGV;
+  } else
+  {
+    print STDERR "SMETANA: What the..?  " .
+                 "Unsupported command line option '$a'.\n";
+  }
+}
+
+while ($maxcycle == 0 or $cycle <= $maxcycle)
+{
+  system $xbefore if $xbefore;
+  print "Current cycle: $cycle.  Current step: $curstep.\n";
+  display_program();
+  if ($step[$curstep][1])
+  {
+    $curstep = $step[$curstep][2]; 
+  } else
+  {
+    my $a = $step[$curstep][2];
+    my $b = $step[$curstep][3];
+    my $temp = $step[$a];
+    $step[$a] = $step[$b];
+    $step[$b] = $temp;
+    $curstep++;
+  }
+  $cycle++;
+  last if $curstep > $#step;
+}
+
+system $xbefore if $xbefore;
+print "Final cycle: $cycle.  Final step: $curstep.\n";
+display_program();
+
+### END of smetana.pl ###