Let's start with the basics. Ganges is a dynamically typed, interpreted language built using the book Writing an Interpreter in Go. The book is a hands-on guide on how to build an interpreter from scratch.
Ganges uses Sanskrit-inspired keywords that map closely to their equivalents in modern programming languages like JavaScript. This not only makes the language unique, but also reinforces semantic clarity with cultural roots.
Below is a reference table that shows common JavaScript keywords alongside their Ganges counterparts and a brief description of their use.
JavaScript | Ganges | Description |
---|---|---|
let | rama | used to declare variable |
if | yadi | if block |
else | anyatha | else block |
vadha | to write to console | |
function | kriya | to declare a function |
while | chakra | while loop initiation |
true | satya | the boolean value true |
false | asatya | the boolean value false |
return | daan | return value from a function |
Variables in Ganges are declared using the keyword rama. You don’t need to specify a type — just assign a value using =.
Strings are enclosed in double quotes. Every statement must end with a semicolon (;
). Variable names follow snake_case or camelCase — your call.
app/variables.ga
1 rama myName = "Sidharth";
2 rama gfName = "19022023";
3 rama baby = "Dhanu";
Ganges supports simple but powerful types: boolean, string, and integer. No type declarations are needed — the interpreter figures it out.
Booleans use true
or false
, strings go inside double quotes, and integers are written as-is. Terminate every declaration with a semicolon.
app/dataTypes.ga
1 rama isAlive = true;
2 rama name = "Lakshman";
3 rama age = 27;
Ganges supports all basic arithmetic operations:+,-,*, and/. Use them freely on integers.
Operations follow standard precedence rules. Variables can store results of expressions.
app/arithmetic.ga
1 rama a = 10;
2 rama b = 5;
3 rama sum = a + b;
4 rama diff = a - b;
5 rama prod = a * b;
6 rama div = a / b;
To print output in Ganges, use the keyword vadha. This function prints to the console.
Wrap what you want to print inside parentheses and double quotes. Don't forget the semicolon (;
) at the end.
app/main.ga
1 vadha("Namaste!");
2 vadha("My name is Sidharth");
3 vadha("Ganges flows strong");
Conditional logic in Ganges is handled using yadi for if and anyatha for else. The condition goes inside parentheses, and the branches inside curly braces.
Unlike many languages, the yadi-anyatha block is an expression. That means it returns a value and can be directly assigned to a variable.returns value
app/conditionals.ga
1 rama mood = yadi (5 > 3) {
2 "happy"
3 } anyatha {
4 "sad"
5 };