https://github.com/buxogabriel/gabelang
A programming language written in rust
https://github.com/buxogabriel/gabelang
interpreter lexer parser programming-language rust wasm
Last synced: 6 months ago
JSON representation
A programming language written in rust
- Host: GitHub
- URL: https://github.com/buxogabriel/gabelang
- Owner: BuxoGabriel
- Created: 2024-10-29T18:04:12.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-08T14:42:44.000Z (10 months ago)
- Last Synced: 2025-04-08T15:43:38.388Z (10 months ago)
- Topics: interpreter, lexer, parser, programming-language, rust, wasm
- Language: Rust
- Homepage: https://crates.io/crates/gabelang
- Size: 179 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gabelang
## Overview
This is a language I am writing in rust for fun and to learn more about lexers, parsers, interpreters, and to dymistify programming languages in general.
The [Writing an Interpreter in Go](interpreterbook.com) book by Thorsten Ball was used as a reference and insperation for this project as well as [mkdb](github.com/antoniosarosi/mkdb) by Antonio Sarosi.
## BNF / Language Grammer
```bnf
= |
= | | | |
= let = ;
= = ;
= if
= while
= for( ; )
= fn
= {}
= (<_param_idents>)
<_param_idents> = | <_param_idents>, <_param_idents>
= |
= | _
= | | | | | |
= ()
=
= + | - | * | /
= | |
= []
= .
= ()
= {}
= : | ,
= []
= | ,
= |
= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
```
## Commenting
Comment your code using the `//comment` syntax
Any text to the right of a double slash does not make it to the parser or interpretter and will not be evaluated as code
```
// This function doubles a number
fn double_num(num) {
// Multiplies num by 2 to get the answer
return num * 2;
}
```
## Variable Behavior
- When a variable is used as an expression/rvalue it is deep cloned
## Built in Functions
**len(obj) -> number**
- returns the length of an array or string
- returns the amount of keys in an object
- throws an error if provided with something other than an array or string
___
**reverse(obj) -> number**
- returns a new reversed array or string without changing the parameter object
- throws an error if provided with something other than an array or string
___
**abs(number) -> number**
- returns the absolute value of a passed in number
- throws an error if provided with something other than a number
## Build
Build with
```sh
cargo build --release
```
## Build for wasm target
Requires wasm-pack to be installed
```sh
cargo install wasm-pack
```
Build with
```sh
wasm-pack build --features wasm
```
## Install
Requires cargo to be installed
Install gabelang with
```sh
cargo install gabelang
```
## Run
Run as repl with
```sh
gabelang
```
or run a script with
```sh
gabelang --file [script name]
```
## Test
Run tests with
```sh
cargo test
```
## Todo
- Better Documentation
- Built in Functions(print, file, fetch, input)
- Add tests to ast and eval modules
- Add fun language syntax
- Improve garbage collector to use mark and sweep
### Todo Reach
- Add tooling/language server
- Add bytecode compiler
- Create VM that can run bytecode