https://github.com/bpetermann/ts-compiler
A typescript compiler
https://github.com/bpetermann/ts-compiler
compiler jest lexer nodejs parser typescript virtual-machine
Last synced: about 2 months ago
JSON representation
A typescript compiler
- Host: GitHub
- URL: https://github.com/bpetermann/ts-compiler
- Owner: bpetermann
- Created: 2024-01-13T22:18:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T13:37:03.000Z (about 2 years ago)
- Last Synced: 2025-03-16T23:43:10.829Z (over 1 year ago)
- Topics: compiler, jest, lexer, nodejs, parser, typescript, virtual-machine
- Language: TypeScript
- Homepage:
- Size: 203 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TypeScript Compiler
A TypeScript compiler for the monkey programming language, based on the excellent book ["Writing An Compiler In Go"](https://compilerbook.com/)
## โ๏ธ Installation
To get started, clone the repository:
```bash
git clone https://github.com/bpetermann/ts-compiler.git
cd ts-compiler
```
Then, install dependencies and build the project:
```js
npm run build:fresh // Installs dependencies and builds the project
```
## ๐ Start
Finally, start the REPL (Read-Eval-Print Loop):
```js
npm run start // Starts the REPL
```
## ๐ Usage Examples
```js
>> let a = 2; // Declare a variable
>> let baz = ["foo", "bar"]; // Declare an array
>> baz[0]; // Acesss array
>> let person = {"name": "Alice"}; // Declare a hash map
>> person["name"]; // Access map
```
Here's a basic example illustrating the declaration and invocation of a function:
```js
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
fibonacci(5);
```
Example of closures:
```js
let newClosure = fn(a) {
fn() { a; };
};
let closure = newClosure(99);
closure();
```
Close the REPL:
```js
eof;
```
## Syntax Overview
The syntax embodies a rich spectrum of functionalities, managing mathematical expressions, variable assignments, function definitions, calls, conditionals, and returns. It adeptly handles concepts like higher-order functions and closures.
Additionally, the compiler accommodates diverse data types โ integers, booleans, strings, arrays, and hashes.
It also features a set of built-in functions tailored to expedite string/array operations and console output logging.
## ๐งช Tests
The following command will run all jest test suites:
```js
npm run test
```