uranus
is a language built by following the book 'Writing a Interpreter in Go.'.
More information can be found inside book, but general introduction is provided here.
Statements end with ;
.
(5 + 10 * 2 + 15 / 3) * 2 + -10
(1 > 2) == false
!!false
if (1 < 2) { 10 } else { 20 }
let a = 5; let b = a; let c = b + a + 5; c;
let add = fn(x,y) { x + y;}; add(1,4)
Including closures.
let newAdder = fn(x) {
fn(y) { x + y };
};
let addTwo = newAdder(2);
Currently the language supports
- Variables
- Booleans
- Integers
- Functions (Including higher-order function and closures.)
- Strings
- Assignment statements
- Return Statements
It has a custom built lexer. Along with a Pratt Parser. The evaluator is a tree-walking evaluator.
The code is structured with 6 major parts.
- AST
- Lexer
- Token
- Parser
- Object
- Evaluator
This package defines what kind of symbols are used in uranus
. It also defines the type of INTEGERS and BOOLEANS.
This package separates the input into a stream of tokens according to the rules defined in the token
package.
These are the rules of the language, this package defines the structure of each expression found in uranus
.
This package parses the tokens in into a IR, according to the rules defined by the ast
package.
The language's internal object system. This does not mean the language is object-oriented. It simply means internally a structure for encapsulation each value is used.
This package contains the all-important eval
function. Which takes any Node and parses returning a value.
All the tests are written alongside the code itself. To test the code use
make test