Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ktravis/trout-script
Compiled, strongly-typed scripting language written in javascript.
https://github.com/ktravis/trout-script
Last synced: about 2 months ago
JSON representation
Compiled, strongly-typed scripting language written in javascript.
- Host: GitHub
- URL: https://github.com/ktravis/trout-script
- Owner: ktravis
- Created: 2015-02-18T00:47:49.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-18T19:03:29.000Z (about 9 years ago)
- Last Synced: 2023-03-25T11:18:07.688Z (almost 2 years ago)
- Language: JavaScript
- Size: 211 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# trout-script
Compiled, strongly-typed scripting language written in javascript.*This was my first (real) attempt at writing a full programming language.
I learned a lot in the process, and will eventually return to make it stable and
clean everything up.*## Features
- strictly typed variables
- runtime within Javascript
- compiler emits 'runtime operations' as js
- struct types
- function closures
- explicit control of context within closures
- readable, unambiguous syntax## Examples
```c
var x = 1 // inferred type
var y:int // not initialized, but declared
var hello:string
hello = "world"
struct Node {
val:string
next:Node // struct allows recursive definition
}struct vec {
x:int = 0, // default values
y:int = 0
}// functions declared with 'fn' and '(' arguments ')'
fn factorial(x:int) int { // return type can be inferred by compiler
var out = 1 // specified following arguments
loop (x > 0) {
out *= x--
}
return out
}
print('fact(10) = '|to_string(factorial(10))) // '|' concatentates stringsvar head:Node // structs are initialized when declared
head.val = "I'm first"
var next:Node
next.val = "I'm next"
head.next = nextloop {
if (head.next == null) {
break
} else {
print(head.val)
head = head.next
}
}
```