Nikrisht is a small, dynamically typed scripting language with an AST-walking interpreter, built from scratch in JavaScript with JSDoc-based type checking, and runs in both Node and the browser without a build step.
Prime, naive
# Checks if a number is prime
func isPrime(number) {
if (number < 2) {
return false;
}
loop (2..<number with i) {
if (remainder(number, i) == 0) {
return false;
}
}
return true;
}
write(isPrime(117));Merge sort
# Sorts an array using Merge Sort algorithm
func mergeSort(array) {
# Base case, an array of 0 or 1 elements is already sorted
if (count(array) <= 1) {
return array;
}
# Split the array into two halves
const middle = floor(count(array) / 2);
# Sort both halves, recursively
const left = mergeSort(slice(array, 1, middle));
const right = mergeSort(slice(array, middle + 1, count(array)));
# Merge the two sorted halves
const result = [];
var i = 1;
var j = 1;
loop (i <= count(left) & j <= count(right)) {
if (left[i] <= right[j]) {
put(result, left[i]);
i = i + 1;
} else {
put(result, right[j]);
j = j + 1;
}
}
# Add any remaining elements from the left half.
loop (i <= count(left)) {
put(result, left[i]);
i = i + 1;
}
# Add any remaining elements from the right half.
loop (j <= count(right)) {
put(result, right[j]);
j = j + 1;
}
return result;
}
write(mergeSort([10, -1, 2, 5, 0, 9]));Fibonacci, memoized
const cache = {};
func fibonacci(number) {
if (has(cache, number)) {
return cache[number];
}
if (number <= 1) {
return number;
}
cache[number] = fibonacci(number - 1) + fibonacci(number - 2);
return cache[number];
}
write(fibonacci(8));You can try Nikrisht instantly in your browser without any installation or setup.
npm install -g nikrishtTo run a nikrisht file input.nki:
nki input.nkiFor the best development experience, install the official Nikrisht VS Code Extension to get full syntax highlighting, error checking, and code snippets:
- Open VS Code.
- Open the Extensions view (
Ctrl+Shift+XorCmd+Shift+X). - Search for Nikrisht by LadyBeGood
- Click Install.
- Microsoft's TypeScript Compiler - A very well-written codebase to study for transpiler design.
- Nathan Shively-Sanders' Mini- & Centi-TypeScript - Miniature models of the TypeScript compiler.
- Orta Therox's TypeScript compiler guide - A YouTube presentation exploring the inner workings of the TypeScript compiler.
- Simone Poggiali's The Concise TypeScript Book - An incredibly informative TypeScript guide.
- Robert Nystrom's Crafting Interpreters - The definitive blueprint for anyone building a language from scratch.
- Rockcavera's Nlox - A Nim implementation of the Lox programming language.
- James Hutcheon's Glox - A Go implementation of a superset of Lox programming language with many ergonomic additions.
- Tyler Laceby's Programming Language Guide - An excellent YouTube playlist on building a custom scripting language in TypeScript.
- Meriyah - A 100% compliant, self-hosted JavaScript parser.
- AST Explorer - A web tool to explore the ASTs generated by various parsers.
- Syntax across languages - A comparison of syntax across many programming languages.
- regex101 - Regex editor for testing and learning regular expressions. Very helpful while creating syntax-highlighting patterns for the VSCode extension and website playground.
- Matt Neuburg's guide on writing TextMate grammar - A comprehensive reference for understanding TextMate grammar internals and syntax highlighting behavior. You will have a very hard time dealing with TextMate if you don't digest this guide first.
/interpreter,/documentation,/CLI,/tests,/runner- MIT-0, see each folder'slicense.txt/website,/extension- All Rights Reserved


