spec1.txt 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Muriel Language Specification (first draft) - 2001.01.19
  2. ========================================================
  3. Overview
  4. --------
  5. Muriel ("Monumentally Useless Re-Iterative Execution Language") is an imperative
  6. programming language for processing strings and integers. It is similar in
  7. principle to SMITH in that it eschews control statements; however, it does have
  8. a statement which executes a string as a Muriel program.
  9. Creating loops and other program structures is therefore a similar process to
  10. writing quines in conventional languages. An infinite loop, for example, would
  11. be created by 'quining' the program into a string, then executing that string.
  12. Instructions
  13. ------------
  14. The syntax of Muriel is intentionally terse, because you're likely to be typing
  15. everything two or three times over anyway. Besides, obfuscation is fun :-)
  16. A Muriel program consists of zero or more instructions separated by semicolons.
  17. a:0 Assign the integer variable 'a' with the value 0. Integer variables may
  18. be any single lower-case letter [a-z].
  19. A:"Foo" Assign the string variable 'A' with the value "Foo". String variables
  20. may be any single capital letter [A-Z].
  21. ."Foo" Output the string "Foo". It must be a string.
  22. @".$0" Execute the Muriel program ".$0". Variables in the current program are
  23. not passed down to the new program, and control does NOT return to the
  24. parent program upon completion.
  25. Expressions, functions and operators
  26. ------------------------------------
  27. In the statements above, 0, "Foo" and ".$0" may be replaced with arbitrary
  28. expressions of the appropriate type.
  29. 123 A numeric literal. All numbers are represented in decimal, and may be
  30. positive or negative.
  31. n Numeric variable.
  32. "Bar" A string literal. This may contain one of the following escape
  33. sequences:
  34. \" A " character
  35. \n 'New line' character
  36. \\ A \ character
  37. X String variable.
  38. ~ A string received from user input.
  39. 2+2 Addition.
  40. "X"+"Y" Concatenation.
  41. 4-2 Subtraction. (Unary minus is also valid, ie -x means 0-x)
  42. 2*2 Multiplication.
  43. 2=2 Test for equality; returns 1 if true, 0 if false.
  44. 2>1 Test for 'greater than'; returns 1 if true, 0 if false.
  45. 2<3 Test for 'less than'. [Not sure if it's worth including this - it all
  46. depends whether we want to be minimal or orthogonal.]
  47. $n Returns the string representation of the numeric value of n.
  48. #N Returns the number represented by the string N, or causes an error if N
  49. does not make sense as a number.
  50. &N Returns the length of the string N.
  51. %N,a,b Returns a section of the string N. Counting the first character of N as
  52. character number zero, the section is from character a up to (but not
  53. including) character b. Causes an error if the numbers are out of range
  54. or b<a.
  55. |N 'Quotify' string N - returns the string with ", \ and newline replaced
  56. by their escape sequences. For example, if we make the assignment
  57. A:"Arthur \"two-sheds\" Jackson"
  58. then these statements would produce these outputs:
  59. .A -> Arthur "two-sheds" Jackson
  60. .|A -> Arthur \"two-sheds\" Jackson
  61. .||A -> Arthur \\\"two-sheds\\\" Jackson
  62. (N) Brackets determine the order in which an expression is evaluated.
  63. By default, expressions are parsed from left to right, so
  64. 5-1-1 equals 3, and $1+1 is invalid (it evaluates to "1"+1,
  65. whereas $(1+1) equals "2").
  66. [Other functions that could be included, but we can probably do without:
  67. / (Integer division); < and > on strings]
  68. A sample Muriel program
  69. -----------------------
  70. Here is a Muriel version of the legendary 99 Bottles Of Beer program. It might
  71. be completely wrong, though:
  72. b:99;
  73. A:$b+" bottle"+(%"s",0,1-(b=1))+" of beer";
  74. .A+" on the wall,\n"+A+",\nTake one down, pass it around,\n";
  75. b:b-1;
  76. .$b+" bottle"+(%"s",0,1-(b=1))+" of beer on the wall.\n\n";
  77. Q:";\nA:$b+\" bottle\"+(%\"s\",0,1-(b=1))+\" of beer\";\n.A+\" on the wall,\\n\"+A+\",\\nTake one down, pass it around,\\n\";\nb:b-1;\n.$b+\" bottle\"+(%\"s\",0,1-(b=1))+\" of beer on the wall.\\n\\n\";\nQ:\"";
  78. R:"\";\nZ:\"b:\"+$b+Q+|Q+\"\\\";\\nR:\\\"\"+|R+R;\n@%Z,0,b>0*&Z";
  79. Z:"b:"+$b+Q+|Q+"\";\nR:\""+|R+R;
  80. @%Z,0,b>0*&Z
  81. Explanation: The first 5 lines print out a verse of the song. Quite
  82. straightforward, apart from the cunning use of string slicing with the '='
  83. operator to get around the lack of IF/THEN constructs. Then, variables Q and R
  84. are set to hold the body of the program - Q being from the beginning to the
  85. quoted part, R from the end of the quoted part to the end of the program.
  86. The 8th line pieces the program together so that Z contains a copy of the
  87. entire program, but with the first line altered so that b is assigned 98
  88. instead. The string slicing in the last line returns an empty string if b=0
  89. (which terminates the program when it is executed), or the entirety of Z if
  90. not (so that the next verse is printed when Z is executed).