Koshur Lang

A simple programming language inspired by the Kashmiri language (Koshur)

JavaScript

Project Details

馃崄 koshur-lang

A simple programming language inspired by the Kashmiri language (Koshur).

Ask DeepWiki

Try it out: Koshur Online


Author: Afaan Bilal


Hello World

wan("Hello, world!");

Run

node koshur.js <filename>

The filename must be the last parameter and must end with .k or .ast.

node koshur.js [--print-ast] [--write-ast] [--from-ast] <filename>
  • 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.

OperatorDescription
+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

MIT License

Copyright (c) 2023 Afaan Bilal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.