SUTRA

A tiny Sanskrit-style joke language that compiles to JavaScript.

Made for fun. Built for learning. Not for production. Built for NASA (just kidding).

Playground

Output:

 

Install

npm install -g @tarunjawla/sutrasutra run hello.skt

Examples

Explore more Sutra programs in the GitHub examples folder.

GitHub examples →

Documentation

Sutra is a tiny Sanskrit-style joke language that compiles to JavaScript.

General

आरम्भ and समाप्त are optional program boundaries. If both exist, only code inside them is compiled. If neither exists, the whole file is compiled. Anything outside will be ignored.

This will be ignored

आरम्भ // Write code here समाप्त This too

Variables

Variables can be declared using मान.

आरम्भ मान a = 10; मान b = "two"; मान c = 15; a = a + 1; b = 21; c *= 2; समाप्त

Types

Numbers and strings are like other languages. शून्य denotes null values. सत्य and असत्य are the boolean values.

आरम्भ मान a = 10; मान b = 10 + (15*20); मान c = "two"; मान d = 'ok'; मान e = शून्य; मान f = सत्य; मान g = असत्य; समाप्त

Built-ins

Use मुद्रय to print anything to console.

आरम्भ मुद्रय("Hello World"); मान a = 10; { मान b = 20; मुद्रय(a + b); } मुद्रय(5, 'ok', शून्य, सत्य, असत्य); समाप्त

Conditionals

Sutra supports if-else construct. यदि block executes if condition is true, otherwise अन्यथा block executes.

आरम्भ मान a = 10; यदि (a < 20) { मुद्रय("a is less than 20"); } अन्यथा { मुद्रय("a is greater than or equal to 20"); } समाप्त

Loops

Statements inside यावत् blocks are executed as long as a specified condition evaluates to true. Use विराम to break the loop and अग्रिम to continue within loop.

आरम्भ मान a = 0; यावत् (a < 10) { a += 1; यदि (a === 5) { मुद्रय("inside loop", a); अग्रिम; } यदि (a === 6) { विराम; } मुद्रय(a); } मुद्रय("done"); समाप्त

Why Sutra Exists

  • For fun
  • To learn how compilers work
  • Because not everything needs a reason

Created by Tarun Jawla

GitHub

Website