https://github.com/omdxp/ez
ez programming language
https://github.com/omdxp/ez
hacktoberfest interpreter programming-language
Last synced: 9 months ago
JSON representation
ez programming language
- Host: GitHub
- URL: https://github.com/omdxp/ez
- Owner: omdxp
- License: mit
- Created: 2022-08-02T18:28:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-02T02:55:01.000Z (over 2 years ago)
- Last Synced: 2024-05-31T15:30:03.389Z (over 1 year ago)
- Topics: hacktoberfest, interpreter, programming-language
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
ez
interpreted programming language
> pronounced as it's spelled because it's easy 😅
a functional programming language, with first class functions and closures support.
## features
- support the usual data types like strings, booleans, integers, hashes, arrays, and nil
- support the usual operators like `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `>`, and `!`
- `!` is the logical negation operator
- `==` is the equality operator
- `!=` is the inequality operator
- `<` is the less than operator
- `>` is the greater than operator
- `+` is the addition operator
- `-` is the subtraction operator (unary minus)
- `*` is the multiplication operator
- `/` is the division operator
- support the usual flow control operators like `if`, `else`, `let` and `ret`
- `if` is the conditional operator
- `else` is the else operator
- `let` is the let operator
- `ret` is the return operator (can be omitted)
- semi-colons are optional
- for syntax highlighting, use the `ez-language-support` [extension](https://marketplace.visualstudio.com/items?itemName=OmarBelghaouti.ez-language-support)
## syntax
- print a value: `print(value)`
- print a value and a newline: `println(value)
- print a newline: `println()`
- `let` is used to declare a variable: `let variable = value`
- `if` is used to declare a conditional: `if (condition) { // do something }`
- `else` is used to declare an else block: `else { // do something }`
- `ret` is used to return a value: `ret value`
- `f` is used to declare a function: `f(name) { // do something }`
- arrays are declared with `[]`: `[1, 2, 3]`
- hashes are declared with `{}`: `{ "key": "value" }`
- `nil` is used when a value is not present: `nil`
sample code:
```
println("hello world")
let x = 1;
let y = 2
let z = x + y;
print(z);
let a = "hello";
let b = "world";
let c = a + b;
print(c);
if (x == y) {
print("x is equal to y");
} else {
print("x is not equal to y");
}
let d = if (x == y) {
"x is equal to y"
} else {
"x is not equal to y"
};
print(d);
let add = f(x, y) {
ret x + y;
};
print(add(x, y));
let mul = f(x, y) {
x * y;
};
print(mul(x, y));
let subResult = f(x, y) {
x - y;
}(x, y);
print(subResult);
let mulByFn = f(x, otherFn) {
ret x * otherFn(x)
};
let res = mulByFn(2, f(x) {
x + 2;
});
print(res);
let arr = [1, 2, 3, add(x, y), true];
print(arr[0]);
let hash = {
"key": "value",
"key2": "value2"
};
print(hash["key"]);
```
- there are some useful bultin functions for arrays:
```
let a = [1, 2, 3, 4, 5];
let b = push(a, 6); // [1, 2, 3, 4, 5, 6]
let c = tail(a); // [2, 3, 4, 5]
let d = first(a); // 1
let e = last(a); // 5
print(len(a)); // 5
```
- `len` is used to get the length of an array or a string: `len(a)`
## run the interpreter
```sh
go run main.go
```
and start typing in the console 💛
- you can run it on a file: `go run main.go -file test.ez`