Advertisement
TheFastFish

elon

Apr 11th, 2016
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. The Elon Programming Language
  2. "Slightly esoteric, slightly useful"
  3. Official Lang Spec
  4. © 2016 snail'
  5.  
  6.  
  7. Preface
  8. =======
  9. Elon is a stack-based kinda-procedural sorta-esoteric programming language taking cues from Forth, among others. I originally developed it in an attempt to make an original esolang, but since then it has taken a more serious slant.
  10.  
  11.  
  12. Program Structure
  13. =================
  14. An Elon program consists of a linear series of Tokens separated by whitespace. The Interpreter steps that through the program one Token at a time, in order. When it encounters a Token, its does one of two things:
  15. -pushes its value to the Stack
  16. -performs an operation
  17. This behavior depends on the Token type.
  18.  
  19. An example program may be:
  20. 1 2 add "The result is " print print end
  21.  
  22. Integers
  23. --------
  24. An Integer Token is a twos compliment signed integer. Ex: 12345, -500, etc.
  25. The bitwidth of this type is dependent on implementation.
  26. The following alternative bases are supported:
  27. -hexadecimal: number starts with h
  28. ex: hFE00
  29. -binary: number starts with b
  30. ex: b1111111000000000
  31. -octal: number starts with O
  32. ex: o6027
  33. When the Interpreter encounters one it will push it to the Stack.
  34.  
  35. Reals
  36. -----
  37. A Real Token is a real number, the precision of which is dependent on implementation. Ex: 1.23, -87.22222222, etc.
  38. The Interpreter will implicitly decide whether a whole number is to be treated as Integer or Real, which will be explored in a later section.
  39. When the Interpreter encounters one it will push it to the Stack
  40.  
  41. Strings
  42. -------
  43. A String Token is a set of characters delimited by double-quotes ("), as this is the traditional definition of a string. Ex: "Hello"
  44. The character encoding of text is, yet again, implementation defined.
  45. When the Interpreter encounters one it will push it to the Stack.
  46.  
  47. Booleans
  48. --------
  49. A Boolean Token is a value either true or false. In code, they are simply the word true or false.
  50. Ex: true, false
  51.  
  52. Symbols
  53. -------
  54. A Symbol Token is a "word" representing an instruction or routine. Elon contains a rich set of built in Symbols, which will be defined later. A Symbol Name may contain a. lphabetic characters and the hyphen (-). Elon is NOT case sensitive.
  55. When the Interpreter encounters one it will perform its associated function.
  56.  
  57. Lists
  58. -----
  59. A List Token is a collection of Tokens, delimited by { and }. Lists are very versatile, being able to store any type of Token, even Symbols and other Lists, as well as being unbounded in size. They can function as arrays, stacks, or defined as new Symbols. The many uses of Lists will be explored later.
  60. Ex: { 123 "hello" print 456 add }
  61.  
  62. Comments
  63. --------
  64. Comments are any text surrounded by $ symbols. The Interpreter ignores them.
  65. Ex: $ Hello World program $ "hello" print end
  66.  
  67.  
  68. Conditionals
  69. ============
  70. Because Elon does not have proper code structures beyond Lists, conditionals can be a bit hard to wrap your mind around. Two Symbols, do and do-not, are the crux of conditionals. do first pops a List to execute, then a Boolean. If the Boolean is true, the List's contents are executed as if they were an Elon program. If it's false, the List is simply thrown out. do-not is the same, but it executes if the condition is false.
  71.  
  72. A basic example is this:
  73. true { "hello" print } do
  74.  
  75. Judgement
  76. ---------
  77. A variety of Symbols exist for conditional judgement. These largely consist of Symbols which compare values. Perhaps the most used are equal and not-equal. For example, equal pops two Tokens, checks if their values are equal, and pushes a Boolean indicating this condition. not-equal is the same, but obviously returns the opposite condition. If the two Tokens are not of the same type, they are automatically not equal.
  78. In addition, there exists greater, less, greater-equal, less-equal, and many others.
  79. For example:
  80. 1 2 equal dup
  81. { "equal" print } do
  82. { "not equal" print } do-not
  83.  
  84.  
  85. Defining New Symbols
  86. ====================
  87. A new Symbol can be defined by the programmer using the Symbol define. define first pops a String off the Stack telling the name of this new Symbol. Then it pops a List that is to be the "contents" of the Symbol.
  88. When a Custom Symbol is executed its contents are treated like an Elon program, working within the current environment and program.
  89.  
  90. In this example, a Symbol listify is defined, which will turn the content cuts of the Stack into a single List.
  91. {
  92. type-of "List" not-equal { wrap } do
  93. count 1
  94. not-equal {
  95. set
  96. flip unshift
  97. count 1
  98. not-equal { repeat } do
  99. forget
  100. } do
  101. } "listify" define
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement