Scotty
A language made to be easy to tokenize. Split each line on spaces and the first word says what it is.
2016 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Scotty was made in the spring of 2016 for a course on programming languages, so that students could build an interpreter without a lexer. Every line splits on spaces, and its first word tells the kinds of line apart. The last line is a prefix expression, and its value is the program's output.
Read the story
The lines before it define variables and functions. A function takes exactly one parameter, by value, and it cannot see any variable outside itself. There is no condition anywhere, so a function that calls itself never comes back.
The machine
| Line | Means |
|---|---|
name = e | A variable |
fun name x = e | A function of one parameter |
e | The last line, whose value is printed |
| Expression | Means |
|---|---|
+ e e - e e * e e / e e | Arithmetic, in prefix |
( name e ) | Call a function |
x 3 -2 0.5 | A variable or a number |
Each token needs a space on both sides, brackets too. The specification gives no outputs, so this implementation prints each value plainly, with no decimal point on whole numbers.
Example
Functions calling functions, from the specification.
Functions calling functions, from the specification. cube uses square, and the variable is passed in from the last line, since the functions could not read it themselves.
Division is exact, as the grammar allows decimal numbers.
Further
See also
Educational
Write your own in Run Convert a program from Scotty
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: scotty.
Command line
shib run scotty -e '+ 1 1'shib manual scottySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/scotty.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org