https://github.com/afaanbilal/koshur-lang
A simple programming language inspired by the Kashmiri language (Koshur)
https://github.com/afaanbilal/koshur-lang
evaluator koshur language lexer parser
Last synced: over 1 year ago
JSON representation
A simple programming language inspired by the Kashmiri language (Koshur)
- Host: GitHub
- URL: https://github.com/afaanbilal/koshur-lang
- Owner: AfaanBilal
- License: mit
- Created: 2023-04-06T11:50:46.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-04T17:21:57.000Z (over 2 years ago)
- Last Synced: 2025-03-28T08:18:26.525Z (over 1 year ago)
- Topics: evaluator, koshur, language, lexer, parser
- Language: JavaScript
- Homepage: https://koshur.afaan.dev
- Size: 72.3 KB
- Stars: 25
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🍁 koshur-lang
===============
A simple programming language inspired by the Kashmiri language (Koshur).
Try it out: [Koshur Online](https://koshur.afaan.dev)
---
### **Author**: [Afaan Bilal](https://afaan.dev)
---
## Hello World
````
wan("Hello, world!");
````
---
## Run
````
node koshur.js
````
The `filename` must be the last parameter and must end with `.k` or `.ast`.
```
node koshur.js [--print-ast] [--write-ast] [--from-ast]
```
- Add `--print-ast` to print the Abstract Syntax Tree.
- Add `--write-ast` to write the Abstract Syntax Tree to a file named `filename` with extension set to `.ast`.
- Add `--from-ast` to evaluate from an Abstract Syntax Tree loaded from `filename`. File must end with `.ast`.
---
## Run examples
See examples in the `examples/` directory.
````
node run-examples.js
````
---
## Syntax
Koshur-lang has a very brief syntax. Semi-colons are required except after expressions.
### Comments
```
# This is a comment
```
### Print to screen
```
wan("Hello!");
```
### Variables
```
x = 10;
y = 20;
wan(x); # Prints 10
wan(y); # Prints 20
```
### Control flow
- `poz` means `true`
- `apuz` means `false`
- `yeli` means `if`
- `nate` means `else`
- `teli` means `then` and is only required after `if` when braces (`{}`) are skipped.
```
yeli poz {
wan("Poz chu!");
} nate {
wan("Apuz hasa!");
};
yeli apuz teli
wan("apuz!")
nate
wan("poz!");
```
### Functions
Functions in **koshur-lang** are lambdas.
```
bod-kus = banav(x, y) yeli x > y teli x nate y;
wan(bod-kus(10, 20)); # Prints 20
```
This creates a function (lambda) named `bod-kus` which returns the bigger of the two parameters.
Functions may be multiline:
```
karunPrintFibonacci = banav(hadd, aediuk, patium) {
yeli (hadd > 0) {
wan(aediuk + patium);
karunPrintFibonacci(hadd - 1, patium, aediuk + patium);
} nate {
wan("Done!");
}
};
karunPrintFibonacci(10, 0, 1);
```
The above code prints:
```
1
2
3
5
8
13
21
34
55
89
Done!
```
Shortcut for `banav` is `λ`
```
lakut-kus = λ(x, y) yeli x < y teli x nate y;
wan(lakut-kus(10, 20)); # Prints 10
```
This creates a function (lambda) named `lakut-kus` which returns the smaller of the two parameters.
### Keywords
This is a list of all the keywords in **koshur-lang**.
- yeli
- teli
- nate
- poz
- apuz
- banav
- λ
### Operators
This is a list of all the operators available in **koshur-lang**.
| Operator | Description |
| -------- | ------------------ |
| \+ | Addition |
| \- | Subtraction |
| \* | Multiplication |
| \/ | Division |
| % | Modulo (Remainder) |
| && | Logical AND |
| \|\| | Logical OR |
| < | Less than |
| \> | Greater than |
| <= | Less or Equal |
| \>= | Greater or Equal |
| == | Equals |
| != | Not Equal |
---
## Contributing
All contributions are welcome. Please create an issue first for any feature request
or bug. Then fork the repository, create a branch and make any changes to fix the bug
or add the feature and create a pull request. That's it!
Thanks!
---
## License
**koshur-lang** is released under the MIT License.
Check out the full license [here](LICENSE).