Initial import of SMETANA 2004.0227 sources.
Cat's Eye Technologies
10 years ago
0 | <html><head> | |
1 | <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1"> | |
2 | <title>Cat's Eye Technologies: The SMETANA Language</title> | |
3 | </head> | |
4 | <body bgcolor="#ffffff" text="#000000" link="#439773" | |
5 | vlink="#ac9444" alink="#0cd490" | |
6 | background="/img/sinewhite.gif" > | |
7 | <h1>SMETANA</h1> | |
8 | <P>Chris Pressey, 1994(ish) | |
9 | <hr> | |
10 | ||
11 | <p>A long time ago (about six years ago), | |
12 | I was writing some amusing notes to | |
13 | myself and among them was an "algorithm | |
14 | that'll never fly," which went | |
15 | something like: | |
16 | ||
17 | <p> 1. Swap steps one and two. | |
18 | <br> 2. Flap wings. | |
19 | <br> 3. Go back to step one. | |
20 | ||
21 | <p>It then occurred to me that reducing | |
22 | this form to the absurd (removing | |
23 | the "Flap wings" instruction) just <i>might</i> | |
24 | fail to yield a totally untractable language. | |
25 | ||
26 | <p>I originally wrote the interpreter as a Visual Basic | |
27 | application and named it SMETANA - both an acronym | |
28 | for "Self-Modifying, Extremely Tiny AutomatoN | |
29 | Application", and a reference to the composer of | |
30 | the same name. | |
31 | ||
32 | <ul><p><i>Turns out that the word</i> smetana <i>is | |
33 | also Russian for</i> sour cream<i>. What do you know? | |
34 | Finally, I join the all-too-exclusive club of people | |
35 | who have invented a language | |
36 | named after a foodstuff!</i></ul> | |
37 | ||
38 | <p>The dsitribution available here is a much better | |
39 | implementation of the SMETANA interpreter in | |
40 | a much more device-independent and scalable form. | |
41 | I have retained the English syntax exactly. The | |
42 | program ends when it tries to peform step | |
43 | number <i>n</i>, where <i>n</i> is one plus the number | |
44 | of steps given in the source. | |
45 | ||
46 | <!-- | |
47 | <p>Todo: mine information about SMETANA's Turing-Complete | |
48 | status from the e-mail archives | |
49 | --> | |
50 | ||
51 | <p>Syntax of the SMETANA Language: | |
52 | ||
53 | <pre> Smetana ::= Step {".\n" Step} ".". | |
54 | Step ::= "Step" Integer "." (GoTo | Swap). | |
55 | GoTo ::= "Go" "to" "step" Integer. | |
56 | Swap ::= "Swap" "step" Integer "with" "step" Integer. | |
57 | Integer ::= "0".."9" {"0".."9"}.</pre> | |
58 | ||
59 | </body></html> |
0 | Step 1. Swap step 1 with step 36. | |
1 | Step 2. Go to step 1. | |
2 | Step 3. Swap step 28 with step 33. | |
3 | Step 4. Swap step 4 with step 13. | |
4 | Step 5. Go to step 38. | |
5 | Step 6. Swap step 16 with step 8. | |
6 | Step 7. Go to step 22. | |
7 | Step 8. Go to step 26. | |
8 | Step 9. Swap step 30 with step 10. | |
9 | Step 10. Go to step 12. | |
10 | Step 11. Swap step 39 with step 8. | |
11 | Step 12. Swap step 28 with step 5. | |
12 | Step 13. Go to step 28. | |
13 | Step 14. Swap step 35 with step 15. | |
14 | Step 15. Swap step 12 with step 5. | |
15 | Step 16. Swap step 4 with step 12. | |
16 | Step 17. Swap step 33 with step 28. | |
17 | Step 18. Go to step 13. | |
18 | Step 19. Swap step 29 with step 18. | |
19 | Step 20. Go to step 39. | |
20 | Step 21. Go to step 22. | |
21 | Step 22. Swap step 35 with step 4. | |
22 | Step 23. Swap step 39 with step 38. | |
23 | Step 24. Go to step 2. | |
24 | Step 25. Swap step 25 with step 27. | |
25 | Step 26. Swap step 3 with step 36. | |
26 | Step 27. Swap step 22 with step 34. | |
27 | Step 28. Swap step 10 with step 16. | |
28 | Step 29. Go to step 3. | |
29 | Step 30. Go to step 18. | |
30 | Step 31. Swap step 2 with step 25. | |
31 | Step 32. Swap step 33 with step 26. | |
32 | Step 33. Go to step 4. | |
33 | Step 34. Swap step 11 with step 22. | |
34 | Step 35. Swap step 25 with step 27. | |
35 | Step 36. Swap step 18 with step 10. | |
36 | Step 37. Swap step 13 with step 25. | |
37 | Step 38. Swap step 16 with step 15. | |
38 | Step 39. Swap step 19 with step 8. | |
39 | Step 40. Swap step 30 with step 34. | |
40 | Step 41. Go to step 34. | |
41 | Step 42. Swap step 29 with step 16. | |
42 | Step 43. Go to step 11. |
0 | Step 1. Go to step 4. | |
1 | Step 2. Go to step 5. | |
2 | Step 3. Go to step 17. | |
3 | Step 4. Swap step 6 with step 12. | |
4 | Step 5. Swap step 15 with step 1. | |
5 | Step 6. Go to step 12. | |
6 | Step 7. Go to step 2. | |
7 | Step 8. Go to step 2. | |
8 | Step 9. Go to step 1. | |
9 | Step 10. Swap step 18 with step 12. | |
10 | Step 11. Go to step 11. | |
11 | Step 12. Swap step 14 with step 17. | |
12 | Step 13. Swap step 9 with step 20. | |
13 | Step 14. Go to step 9. | |
14 | Step 15. Swap step 4 with step 6. | |
15 | Step 16. Swap step 1 with step 20. | |
16 | Step 17. Swap step 13 with step 8. | |
17 | Step 18. Swap step 4 with step 13. | |
18 | Step 19. Swap step 4 with step 4. | |
19 | Step 20. Go to step 17. |
0 | Step 1. Swap step 1 with step 36. | |
1 | Step 2. Go to step 1. | |
2 | Step 3. Swap step 28 with step 33. | |
3 | Step 4. Swap step 4 with step 13. | |
4 | Step 5. Go to step 38. | |
5 | Step 6. Swap step 16 with step 8. | |
6 | Step 7. Go to step 22. | |
7 | Step 8. Go to step 26. | |
8 | Step 9. Swap step 30 with step 10. | |
9 | Step 10. Go to step 12. | |
10 | Step 11. Swap step 39 with step 8. | |
11 | Step 12. Swap step 28 with step 5. | |
12 | Step 13. Go to step 28. | |
13 | Step 14. Swap step 35 with step 15. | |
14 | Step 15. Swap step 12 with step 5. | |
15 | Step 16. Swap step 4 with step 12. | |
16 | Step 17. Swap step 33 with step 28. | |
17 | Step 18. Go to step 13. | |
18 | Step 19. Swap step 29 with step 18. | |
19 | Step 20. Go to step 39. | |
20 | Step 21. Go to step 22. | |
21 | Step 22. Swap step 35 with step 4. | |
22 | Step 23. Swap step 39 with step 38. | |
23 | Step 24. Go to step 2. | |
24 | Step 25. Swap step 25 with step 27. | |
25 | Step 26. Swap step 3 with step 36. | |
26 | Step 27. Swap step 22 with step 34. | |
27 | Step 28. Swap step 10 with step 16. | |
28 | Step 29. Go to step 3. | |
29 | Step 30. Go to step 18. | |
30 | Step 31. Swap step 2 with step 25. | |
31 | Step 32. Swap step 33 with step 26. | |
32 | Step 33. Go to step 4. | |
33 | Step 34. Swap step 11 with step 22. | |
34 | Step 35. Swap step 25 with step 27. | |
35 | Step 36. Swap step 18 with step 10. | |
36 | Step 37. Swap step 13 with step 25. | |
37 | Step 38. Swap step 16 with step 15. | |
38 | Step 39. Swap step 19 with step 8. | |
39 | Step 40. Swap step 30 with step 34. | |
40 | Step 41. Go to step 34. | |
41 | Step 42. Swap step 29 with step 16. | |
42 | Step 43. Go to step 11. |
0 | #!/usr/local/bin/perl -w | |
1 | ||
2 | # randsmet[.pl] v2000.03.01 Cat's Eye Technologies | |
3 | # Generate a random SMETANA program | |
4 | # This work is part of the Public Domain. | |
5 | ||
6 | ### MAIN ### | |
7 | ||
8 | $| = 1; | |
9 | if ($#ARGV == -1) | |
10 | { | |
11 | print "usage: randsmet <integer>\n"; | |
12 | exit(1); | |
13 | } | |
14 | $steps = shift @ARGV; | |
15 | for($i=1;$i<=$steps;$i++) | |
16 | { | |
17 | print "Step $i. "; | |
18 | if (rand > 0.5) | |
19 | { | |
20 | print "Go to step " . int(rand($steps)+1) . ".\n"; | |
21 | } else | |
22 | { | |
23 | print "Swap step " . int(rand($steps)+1) . " with step " . | |
24 | int(rand($steps)+1) . ".\n"; | |
25 | } | |
26 | } | |
27 | ||
28 | ### END ### | |
29 |
0 | #!/usr/bin/perl -w | |
1 | ||
2 | ### BEGIN smetana.pl ### | |
3 | ||
4 | # smetana[.pl] v2004.0227 Cat's Eye Technologies | |
5 | # Interpreter/Debugger for the SMETANA language | |
6 | # This work is part of the Public Domain. | |
7 | ||
8 | ### GLOBALS ### | |
9 | ||
10 | $[ = 1; | |
11 | @step = (); | |
12 | $cycle = 1; | |
13 | $curstep = 1; | |
14 | $maxcycle = 0; | |
15 | ||
16 | ### SUBROUTINES ### | |
17 | ||
18 | sub load_source_file # into global list variable @step | |
19 | { | |
20 | my $fn = shift @_; | |
21 | my $rs = 1; my $x = ''; | |
22 | ||
23 | @step = (); | |
24 | open FILE, "<$fn"; | |
25 | while(defined($x = <FILE>)) | |
26 | { | |
27 | if ($x =~ /^\s*Step\s*(\d+)\s*\.\s*(.*?)$/io) | |
28 | { | |
29 | my $x = $2; | |
30 | if ($1 == $rs) | |
31 | { | |
32 | if ($x =~ /^Go\s*to\s*step\s*(\d+)\s*\.\s*$/io) | |
33 | { | |
34 | push @step, [1, $1]; | |
35 | } elsif ($x =~ /^Swap\s*step\s*(\d+)\s*with\s*step\s*(\d+)\s*\.\s*$/io) | |
36 | { | |
37 | push @step, [0, $1, $2]; | |
38 | } else | |
39 | { | |
40 | print STDERR "SMETANA: Triple Boo! " . | |
41 | "Insulting instruction in step $rs.\n"; | |
42 | return; | |
43 | } | |
44 | $rs++; | |
45 | } else | |
46 | { | |
47 | print STDERR "SMETANA: Double Boo! " . | |
48 | "Line $rs contains wrong step, step $1.\n"; | |
49 | return; | |
50 | } | |
51 | } else | |
52 | { | |
53 | print STDERR "SMETANA: Boo! Line $rs does not contain a step.\n"; | |
54 | return; | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | sub display_program | |
60 | { | |
61 | my $i = 1; | |
62 | while (defined($step[$i])) | |
63 | { | |
64 | print "Step $i. "; | |
65 | if ($step[$i][1]) | |
66 | { | |
67 | print "Go to step " . $step[$i][2] . ".\n"; | |
68 | } else | |
69 | { | |
70 | print "Swap step " . $step[$i][2] . " with step " . $step[$i][3] . ".\n"; | |
71 | } | |
72 | $i++; | |
73 | } | |
74 | print "\n"; | |
75 | } | |
76 | ||
77 | ### MAIN ### | |
78 | ||
79 | $| = 1; | |
80 | if ($#ARGV == 0) | |
81 | { | |
82 | print <<'EOT'; | |
83 | smetana[.pl] v2004.0227 - Interpreter/Debugger for the SMETANA language | |
84 | Chris Pressey, Cat's Eye Technologies. | |
85 | This work is part of the Public Domain. | |
86 | ||
87 | Usage: | |
88 | [perl] smetana[.pl] inputfile {-d binfile | -m integer} | |
89 | inputfile: text file to use as SMETANA source file. | |
90 | -d binfile: optional program to shell between program states (e.g. cls) | |
91 | -m integer: optional limit to number of states (to avoid infinite loops) | |
92 | EOT | |
93 | exit(1); | |
94 | } | |
95 | ||
96 | load_source_file shift @ARGV; | |
97 | ||
98 | while (defined $ARGV[1]) | |
99 | { | |
100 | $a = shift @ARGV; | |
101 | if ($a eq '-d') | |
102 | { | |
103 | $xbefore = shift @ARGV; | |
104 | } elsif ($a eq '-m') | |
105 | { | |
106 | $maxcycle += shift @ARGV; | |
107 | } else | |
108 | { | |
109 | print STDERR "SMETANA: What the..? " . | |
110 | "Unsupported command line option '$a'.\n"; | |
111 | } | |
112 | } | |
113 | ||
114 | while ($maxcycle == 0 or $cycle <= $maxcycle) | |
115 | { | |
116 | system $xbefore if $xbefore; | |
117 | print "Current cycle: $cycle. Current step: $curstep.\n"; | |
118 | display_program(); | |
119 | if ($step[$curstep][1]) | |
120 | { | |
121 | $curstep = $step[$curstep][2]; | |
122 | } else | |
123 | { | |
124 | my $a = $step[$curstep][2]; | |
125 | my $b = $step[$curstep][3]; | |
126 | my $temp = $step[$a]; | |
127 | $step[$a] = $step[$b]; | |
128 | $step[$b] = $temp; | |
129 | $curstep++; | |
130 | } | |
131 | $cycle++; | |
132 | last if $curstep > $#step; | |
133 | } | |
134 | ||
135 | system $xbefore if $xbefore; | |
136 | print "Final cycle: $cycle. Final step: $curstep.\n"; | |
137 | display_program(); | |
138 | ||
139 | ### END of smetana.pl ### |