Drift
Jump to navigation
Jump to search
| Paradigm(s) | Procedural |
|---|---|
| Designed by | Harald Sorenson |
| Appeared in | 2017 |
| Dimensions | One-Dimensional |
| Computational class | Unknown |
| Major implementations | Interpreter |
| Influenced by | C, Lua |
| File extension(s) | .df |
Drift is a procedural, "stack-based" programming language created by Harald Sorenson in 2017. The main premise of the language is where every variable is a stack (filo) or queue (fifo) of positive integers.
Language Syntax
Declaration Keywords
filowill declare a first-in-last-out stack.fifowill declare a first-in-first-out stack, also known as a queue.
Destruction Keywords
delwill destroy a variable, and will allow it to be redeclared.
Variable Operators
- Pushing:
.will push onto the stack. - Popping:
~will return and remove the top/bottom of the stack. - Peeking:
^will return the top/bottom of the stack. - Get Size:
?will return the size of the stack.
Logic Keywords
ifandelsestatements, along withelse ifstatements.loopwithbreakfor looping.lblandgotooperators withrettoken to return togotocall.
I/O Keywords
printwill print to stdout.printlnwill print to stdout with an appended newline.charandintkeywords to define how to print.cinwill get the first character of user input.sinwill get a line of user input.ninwill get a number from user input.
Arithmetic
- All arithmetic must be placed within arithmetic blocks
() - Operators currently functional include:
+,-,/,*, and%.
Strings
"..."to create a string literal, only supported when pushing to a variable.'...to create a character literal, only supports one character.
Misc
- One-line comments are declared with a
\token.
Examples
Hello, World!
fifo str."Hello World!\n"
loop {
if ?str > 0 {
print char ~str
}else {
break
}
}
Reverse Cat
Note: filo could be replaced with fifo to make this a normal cat program.
filo input.sin
loop {
if ?input = 0 {
print char '\n
input.sin
}
print char ~input
}
Fibonacci Sequence
filo fib.0
fib.1
loop {
println int ^fib
filo tmp.(~fib)
filo sum.(^tmp + ~fib)
fib.(~tmp)
fib.(~sum)
del tmp
del sum
if ^fib > 100000 {break}
}
Label/Gotos
filo arg
lbl pstr
loop {
if ?arg = 0 {break}
print char ~arg
}
print char '\n
ret
arg.sin
goto pstr
Conditional Loop
filo num.nin
if ^num = 0 {
exit
}else loop if ^num > 0 {
if ^num = 0 {
break
}
println int ^num
num.(~num-1)
}else {
println int ^num
}