Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The Elon Programming Language
- "Slightly esoteric, slightly useful"
- Official Lang Spec
- © 2016 snail'
- Preface
- =======
- 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.
- Program Structure
- =================
- 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:
- -pushes its value to the Stack
- -performs an operation
- This behavior depends on the Token type.
- An example program may be:
- 1 2 add "The result is " print print end
- Integers
- --------
- An Integer Token is a twos compliment signed integer. Ex: 12345, -500, etc.
- The bitwidth of this type is dependent on implementation.
- The following alternative bases are supported:
- -hexadecimal: number starts with h
- ex: hFE00
- -binary: number starts with b
- ex: b1111111000000000
- -octal: number starts with O
- ex: o6027
- When the Interpreter encounters one it will push it to the Stack.
- Reals
- -----
- A Real Token is a real number, the precision of which is dependent on implementation. Ex: 1.23, -87.22222222, etc.
- 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.
- When the Interpreter encounters one it will push it to the Stack
- Strings
- -------
- A String Token is a set of characters delimited by double-quotes ("), as this is the traditional definition of a string. Ex: "Hello"
- The character encoding of text is, yet again, implementation defined.
- When the Interpreter encounters one it will push it to the Stack.
- Booleans
- --------
- A Boolean Token is a value either true or false. In code, they are simply the word true or false.
- Ex: true, false
- Symbols
- -------
- 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.
- When the Interpreter encounters one it will perform its associated function.
- Lists
- -----
- 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.
- Ex: { 123 "hello" print 456 add }
- Comments
- --------
- Comments are any text surrounded by $ symbols. The Interpreter ignores them.
- Ex: $ Hello World program $ "hello" print end
- Conditionals
- ============
- 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.
- A basic example is this:
- true { "hello" print } do
- Judgement
- ---------
- 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.
- In addition, there exists greater, less, greater-equal, less-equal, and many others.
- For example:
- 1 2 equal dup
- { "equal" print } do
- { "not equal" print } do-not
- Defining New Symbols
- ====================
- 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.
- When a Custom Symbol is executed its contents are treated like an Elon program, working within the current environment and program.
- In this example, a Symbol listify is defined, which will turn the content cuts of the Stack into a single List.
- {
- type-of "List" not-equal { wrap } do
- count 1
- not-equal {
- set
- flip unshift
- count 1
- not-equal { repeat } do
- forget
- } do
- } "listify" define
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement