smurf.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ------------------------------
  2. Smurf - Language Specification
  3. ------------------------------
  4. Smurf = String-based MURiel Forthoid
  5. Smurf is a tarpit based on the self-propagation paradigm featured in Muriel.
  6. The only native data type is the string, and operations are carried out on
  7. strings in a forty manner.
  8. (At first I was reluctant to call the language Smurf after I found that there
  9. was already a humourous email in circulation regarding a fictional (I hope
  10. so, anyway...) language called Smurf. However, a Google search for "smurf
  11. programming language" revealed this link:
  12. http://www.google.com/search?q=cache:everything2.com/index.pl%3Fnode%3DForth+smurf+programming+language
  13. I can only assume that this is a sign from a divine entity that there is
  14. indeed a connection between Smurfs and the Forth programming language, so I'm
  15. certainly not going to argue.)
  16. The Smurf environment consists of a program (a string of characters), a stack
  17. on which strings are stored, and a variable store which behaves as in a
  18. standard imperative language - string values are labelled with a name, which
  19. is also a string. Any string can be used as a variable name, including the
  20. empty string. All variable values are initially set to the empty string.
  21. The program consists of a sequence of instructions, which may be separated
  22. with whitespace. Whenever an instruction takes a parameter from the stack,
  23. that parameter is removed from the stack.
  24. "insert some profound text here"
  25. - Places the string on top of the stack (without the quotes). The string
  26. may include the following escape sequences:
  27. \n = newline
  28. \" = the " character
  29. \\ = the \ character
  30. + - concatenates the top two strings on the stack. The string pushed earlier
  31. appears earlier in the resulting string, eg
  32. "Zork" "mid" +
  33. would result in the string "Zorkmid" being placed on the stack.
  34. i - takes a string from user input, and places it on the stack.
  35. o - outputs the topmost string on the stack.
  36. p - Pops a variable name from the stack, pops a value from the stack, and
  37. assigns that value to the variable name.
  38. g - Pops a variable name from the stack, and pushes the value of the
  39. variable.
  40. h - Pops a string from the stack, and pushes its head, ie the first
  41. character. This causes an error if used on the empty string.
  42. t - Pops a string from the stack, and pushes its tail, ie all but the first
  43. character. This causes an error if used on the empty string.
  44. q - "Quotifies" the string on top of the stack, so that it can be placed
  45. into a Smurf program as a literal string, eg
  46. Arthur "two-sheds" Jackson
  47. becomes
  48. "Arthur \"two-sheds\" Jackson"
  49. NOTE: This differs from the quotify operator in Muriel, because it adds
  50. the surrounding quotes as well.
  51. x - Executes the string on top of the stack as a Smurf program. The stack
  52. and variable store are cleared before it is executed.
  53. --------------------------------
  54. smurf.pl - the Smurf interpreter
  55. --------------------------------
  56. Usage:
  57. smurf.pl <smurf program file>
  58. Error messages are in the form of They Might Be Giants quotes. (I apologise
  59. for my lack of knowledge of the works of Bjork, but if anyone would care to
  60. provide me with appropriate quotes, I'll happily incorporate a command line
  61. option to enable Icelandic Pop Diva Mode in the next version.)
  62. "It's hard to understand me from the language I use
  63. There's no word in English for my style":
  64. The interpreter encountered an unrecognised program instruction.
  65. "When the indicator says you're out of gas
  66. Should you continue driving anyway?":
  67. The program attempted to pop a value from the stack when it was empty.
  68. "Roll out that special head
  69. This is our favourite one":
  70. The h instruction was used on the empty string.
  71. "I'm not done
  72. And I won't be till my head falls off":
  73. The t instruction was used on the empty string.
  74. "I was just talking and someone interrupted
  75. Or was it a loud explosion?":
  76. The terminating " of a string expression was missing.
  77. ----------------------
  78. Example Smurf programs
  79. ----------------------
  80. 1. HelloWorld.smu
  81. "Hello World!"o
  82. 2. Quine.smu
  83. "\"\"p\"\"gqo\"\"go"""p""gqo""go
  84. 3. Echo.smu
  85. io "\"a\"p \"io\" \"a\"gq+ \"a\"g+ x" "a"p "io" "a"gq+ "a"g+ x