moss is a simple programming language written in rust and c. it's a personal project for learning rust and compiler. just for curiosity.
moss version of fibonacci implementation.
fun fib(n) {
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
var before = clock();
print fib(40);
var after = clock();
print after - before;as we can see,it implement the minimal feature of a function based programming language. since now, print is not a function, it's a keyword, and clock is a function, it's a built-in function.
we can declare a function by fun keyword, and call a function by function_name(arguments).
we can declare a variable by var keyword, and assign a value to a variable by variable_name = value.
moss support if,while,for statement, and + - * / operator.
the primitive type:
- number: which is f64 in rust
- string: just a string
- boolean: true or false
cargo installif you want a repl to try moss, you can use cargo run to run moss.
cargo runif you want to run a moss file, you can use cargo run to run moss.
cargo run ./test_file/test_while.mossrun test,both unit test and integration test.
cargo testcmoss is moss lang backend,written in c. document
[ ] implement a backend of moss,based on byteCode,which is more efficient than ast. [ ] implement a standard library of moss,which is more useful than just a print and clock. [ ] build a wasm version for moss, and build a web playground for it;
- lexer ( aka scanner )
- var expression
- math compute
- assignment expression
- i++ i-- ++i --i += -= *= /=
- if expression
- while expression
- function call expression
- function define expression
- array expression
- object expression
- scoping and scop resolve
- class statement
- blank string parse
- use nom refact lexer
- number: f64
- string: String
- boolean: bool
- nil