Language Specification

Formal specification of the Rampyaaryan language — Version 3.5.2

1. Lexical Structure

1.1 Tokens

Token TypePatternExamples
Identifiers[a-zA-Z_][a-zA-Z0-9_]*naam, my_var, _x
NumbersInteger or float42, 3.14, -7
StringsDouble-quoted with escapes"hello", "line\n"
Comments# or // (single-line)# yeh comment hai

1.2 Keywords

KeywordEnglish EquivalentUsage
maanolet / varVariable declaration
likhoprintPrint output
puchoinputRead user input
agarifConditional
warnaelseElse branch
warna agarelse ifElse-if branch
jab takwhileWhile loop
harforFor loop
kaamfunctionFunction definition
wapas doreturnReturn from function
rukobreakBreak from loop
aglacontinueSkip to next iteration
sachtrueBoolean true
jhoothfalseBoolean false
khalinullNull value
aurandLogical AND
yaorLogical OR
nahinotLogical NOT

1.3 Operators

CategoryOperators
Arithmetic+ - * / % **
Comparison== != > < >= <=
Bitwise& | ^ ~ << >>
Logicalaur ya nahi
Assignment= += -= *= /=

1.4 Escape Sequences

SequenceCharacter
\nNewline
\tTab
\\Backslash
\"Double quote

2. Data Types

TypeHinglish NameExamplesDescription
Numbersankhya42, 3.14, -764-bit IEEE 754 double
Stringshabd"hello", "namaste"Immutable, interned, UTF-8
Booleanhaan_nasach, jhoothTrue or false
NullkhalikhaliAbsence of value
Listsuchi[1, 2, 3]Dynamic array, mixed types
Functionkaamkaam f(x) {...}First-class, closures
Map/Dictshabdkosh{"key": "val"}String-keyed hash map

3. Statements

3.1 Variable Declaration

maano <name> = <expression>

Declares and initializes a variable. Variables are dynamically typed.

3.2 Print Statement

likho <expression> [, <expression>]*

Multiple expressions are printed space-separated with a trailing newline. A ; separator prints without newline.

3.3 If Statement

agar <condition> {
    <statements>
} warna agar <condition> {
    <statements>
} warna {
    <statements>
}

3.4 While Loop

jab tak <condition> {
    <statements>
}

3.5 For Loop

har <init>; <condition>; <update> {
    <statements>
}

3.6 Function Declaration

kaam <name>(<params>) {
    <statements>
    wapas do <expression>
}

3.7 Break & Continue

ruko      # break out of loop
agla      # skip to next iteration

4. Expressions

4.1 Operator Precedence (low to high)

LevelOperatorsDescription
1yaLogical OR
2aurLogical AND
3|Bitwise OR
4^Bitwise XOR
5&Bitwise AND
6== !=Equality
7> < >= <=Comparison
8<< >>Bit shifts
9+ -Addition / subtraction
10* / %Multiplication / division
11**Exponentiation
12~ nahi -Unary: bitwise NOT, logical NOT, negate
13() [] .Call, index, member access

4.2 Function Calls

<function>(<args>)

4.3 List Indexing

<list>[<index>]          # read
<list>[<index>] = <value> # write

4.4 Input Expression

pucho(<prompt>)

5. Closures

Functions capture variables from enclosing scopes. This enables powerful patterns like counters, iterators, and factory functions.

kaam counter() {
    maano n = 0
    kaam badhao() {
        n = n + 1
        wapas do n
    }
    wapas do badhao
}

maano c = counter()
likho c()    # 1
likho c()    # 2
likho c()    # 3
How it works: The inner function badhao captures the variable n from the outer function via an "upvalue". The VM uses a dedicated upvalue mechanism (similar to Lua/clox) to track captured variables even after the enclosing function returns.

6. Truthiness

ValueTruthy?
jhoothFalsy
khaliFalsy
0Falsy
"" (empty string)Falsy
[] (empty list)Falsy
Everything elseTruthy

7. String Operations

OperationSyntaxResult
Concatenation"a" + "b""ab"
Repetition"ha" * 3"hahaha"
Indexing"hello"[0]"h"
Lengthlambai("hello")5

8. Map Literals

Maps can be created with literal syntax. Keys must be strings. Values can be any type.

maano m = {"key1": value1, "key2": value2}

m["key"]              # read
m["new_key"] = value  # write

9. Bitwise Operations

Bitwise operators work on integer values:

a & b       # AND
a | b       # OR
a ^ b       # XOR
~a          # NOT (complement)
a << n      # Left shift
a >> n      # Right shift

10. Runtime Architecture

Rampyaaryan Virtual Machine — Execution Model: Dispatch Loop, Value Stack, Call Frames, Globals Table, Constant Pool, Garbage Collector
Rampyaaryan Object Type Hierarchy — Obj base with ObjString, ObjFunction, ObjClosure, ObjUpvalue, ObjClass, ObjInstance, ObjList, ObjMap

Compilation

Single-pass Pratt parser compiles source code into bytecode. No AST is generated — the parser emits bytecode directly.

Execution

Stack-based virtual machine interprets bytecode using a dispatch loop with computed gotos (where available).

Memory

Mark-sweep garbage collector with automatic memory management. Objects are tracked in a linked list.

Strings

All strings are interned using FNV-1a hashing. String equality is O(1) pointer comparison.

Variables

Global variables use a hash table. Local variables use dedicated stack slots for maximum performance.

Functions

First-class closures with upvalue tracking. Supports recursion, higher-order functions, and currying.

Implementation note: Rampyaaryan is implemented in ~4000 lines of portable C99 with zero external dependencies. It compiles with any C99-compliant compiler (GCC, Clang, MSVC).