Skip to main content

Getting Started

Begin your journey with Sanskriti programming language

Installation

Download and install the Sanskriti compiler on your system.

$ curl -sSL https://sanskriti.dev/install.sh | bash
# Or download from GitHub releases
$ sanskriti --version

Hello World

Write your first Sanskriti program with cultural syntax.

प्रारंभ
लिखें("नमस्ते संसार!")
समाप्ति

Prerequisites

Basic Programming

Understanding of programming concepts

Sanskrit Basics

Familiarity with Devanagari script

Terminal Usage

Command line interface knowledge

Quick Setup

1

Download Compiler

Get the latest Sanskriti compiler from our official repository.

$ wget https://github.com/sanskriti-lang/releases/latest
2

Configure Environment

Add Sanskriti to your system PATH for global access.

$ export PATH=$PATH:/usr/local/bin/sanskriti
3

Verify Installation

Test your installation with a simple version check.

$ sanskriti --version
Sanskriti v1.0.0 (build 2024.1)

Next Steps

Ready to dive deeper? Explore these essential topics to master Sanskriti.

व्या

Language Syntax

Master the fundamental syntax and structure of Sanskriti

Program Structure

Basic Program Template

प्रारंभ
// मुख्य कार्यक्रम यहाँ लिखें
लिखें("नमस्ते संसार!")
समाप्ति

Key Components

  • प्रारंभ - Program start declaration
  • लिखें() - Output function
  • समाप्ति - Program end declaration

Variables & Data Types

Variable Declaration

संख्या आयु = २५
पाठ नाम = "राम"
बूलियन सत्य = सही
दशमलव मूल्य = ३.१४

Data Types

संख्या Integer numbers
पाठ Text strings
बूलियन Boolean values
दशमलव Decimal numbers

Control Structures

Conditional Statements

यदि (आयु >= १८) {
लिखें("वयस्क")
} अन्यथा {
लिखें("बालक")
}

Loop Structures

के लिए (i = १; i <= १०; i++) {
लिखें(i)
}
// जब तक लूप
जब तक (शर्त) {
// कोड
}

Function Definition

कार्य जोड़(a, b) {
वापसी a + b
}
// कॉल करना
परिणाम = जोड़(५, ३)

Operators

Arithmetic

+ Addition
- Subtraction
* Multiplication
/ Division

Comparison

== Equal
!= Not equal
> Greater than
< Less than

Logical

और AND
या OR
नहीं NOT

Assignment

= Assign
+= Add assign
-= Subtract assign

Comments & Documentation

Comment Types

// एकल पंक्ति टिप्पणी
/*
* बहु-पंक्ति टिप्पणी
* विस्तृत विवरण के लिए
*/
/** दस्तावेज़ीकरण टिप्पणी */

Best Practices

  • Use meaningful variable names in Sanskrit
  • Comment complex logic in Sanskrit
  • Follow consistent indentation
  • Document function parameters

Complete Example

/** गणित कार्यक्रम - बुनियादी गणना */
प्रारंभ
संख्या a = १०
संख्या b = ५
पाठ संदेश = "परिणाम: "
// गणना करें
संख्या योग = a + b
संख्या गुणा = a * b
// परिणाम दिखाएं
लिखें(संदेश + "योग = " + योग)
लिखें(संदेश + "गुणा = " + गुणा)
यदि (योग > गुणा) {
लिखें("योग बड़ा है")
} अन्यथा {
लिखें("गुणा बड़ा है")
}
समाप्ति
टो

Tokens and Keywords

Explore the building blocks of Sanskriti language

Reserved Keywords

Control Flow

यदि if
अन्यथा else
जब तक while
के लिए for

Data Types

संख्या number
पाठ text
बूलियन boolean
दशमलव decimal

Program Structure

प्रारंभ begin
समाप्ति end
कार्य function
वापसी return

Operators & Symbols

Arithmetic

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo

Comparison

== Equal to
!= Not equal
> Greater than
< Less than
>= Greater equal

Logical

और AND
या OR
नहीं NOT
सही true
गलत false

Punctuation

{} Code blocks
() Parameters
; Statement end
, Separator
" String quotes

Identifiers & Literals

Identifier Rules

Valid Identifiers

नाम
आयु१
मेरा_चर
गणना_परिणाम

Invalid Identifiers

१नाम (starts with number)
मेरा-चर (hyphen not allowed)
यदि (reserved keyword)

Literal Types

Number Literals

१२३ (integer)
३.१४ (decimal)
-४५ (negative)

String Literals

"नमस्ते" (simple string)
"मेरा नाम राम है" (with spaces)
"संख्या: १२३" (mixed content)

Token Categories

K

Keywords

Reserved words with special meaning

प्रारंभ, यदि, कार्य
I

Identifiers

User-defined names for variables

नाम, आयु, गणना
L

Literals

Constant values in source code

१२३, "नमस्ते", सही
O

Operators

Symbols for operations

+, -, ==, और
P

Punctuation

Structural symbols

{}, (), ;, ,
C

Comments

Documentation and notes

//, /* */, /**

Lexical Analysis Example

Source Code

प्रारंभ
संख्या आयु = २५
यदि (आयु >= १८) {
लिखें("वयस्क")
}
समाप्ति

Token Breakdown

KEYWORD प्रारंभ
TYPE संख्या
ID आयु
ASSIGN =
NUMBER २५
फं

Built-in Functions

Explore powerful built-in functions for Sanskriti programming

Input/Output Functions

Output Functions

लिखें() print

Display text or values to console

लिखें("नमस्ते संसार!")
// Output: नमस्ते संसार!
प्रदर्शन() display

Format and display structured output

प्रदर्शन("नाम: %s, आयु: %d", नाम, आयु)

Input Functions

पढ़ें() read

Read user input from console

पाठ नाम = पढ़ें("आपका नाम: ")
संख्या_पढ़ें() read_number

Read numeric input with validation

संख्या आयु = संख्या_पढ़ें("आयु दर्ज करें: ")

Mathematical Functions

Basic Math

वर्गमूल() sqrt
घात() power
निरपेक्ष() abs

Trigonometry

साइन() sin
कोसाइन() cos
टैंजेंट() tan

Rounding

पूर्णांक() round
छत() ceil
फर्श() floor

Mathematical Examples

दशमलव परिणाम = वर्गमूल(१६.०)
// परिणाम: ४.०
संख्या शक्ति = घात(२, ३)
// परिणाम: ८
दशमलव कोण = साइन(३.१४१५९/२)
// परिणाम: १.०
संख्या पूर्ण = पूर्णांक(३.७)
// परिणाम: ४

String Functions

String Manipulation

लंबाई() length

Get string length

संख्या लेन = लंबाई("नमस्ते")
// परिणाम: ६
जोड़ें() concat

Concatenate strings

पाठ पूरा = जोड़ें("नमस्ते ", "दुनिया")

String Operations

उप_पाठ() substring

Extract substring

पाठ भाग = उप_पाठ("नमस्ते", १, ३)
खोजें() find

Find substring position

संख्या स्थिति = खोजें("नमस्ते", "स्ते")

Array Functions

Array Creation

सरणी() array
नई_सरणी() new_array

Array Operations

धक्का() push
पॉप() pop
आकार() size

Array Search

खोजें_सरणी() find_array
क्रमबद्ध() sort

Array Examples

सरणी संख्याएं = नई_सरणी()
धक्का(संख्याएं, १०)
धक्का(संख्याएं, २०)
// सरणी: [१०, २०]
संख्या आकार = आकार(संख्याएं)
// आकार: २

Utility Functions

Type Checking

प्रकार() Get variable type
संख्या_है() Check if number
पाठ_है() Check if string

Conversion

संख्या_में() Convert to number
पाठ_में() Convert to string
बूलियन_में() Convert to boolean

Complete Example

/** गणितीय कैलकुलेटर - बिल्ट-इन फंक्शन का उपयोग */
प्रारंभ
// उपयोगकर्ता से इनपुट लें
दशमलव संख्या१ = संख्या_पढ़ें("पहली संख्या: ")
दशमलव संख्या२ = संख्या_पढ़ें("दूसरी संख्या: ")
// गणना करें
दशमलव योग = संख्या१ + संख्या२
दशमलव गुणा = संख्या१ * संख्या२
दशमलव वर्गमूल१ = वर्गमूल(संख्या१)
// परिणाम दिखाएं
प्रदर्शन("योग: %.२f", योग)
प्रदर्शन("गुणा: %.२f", गुणा)
प्रदर्शन("पहली संख्या का वर्गमूल: %.२f", वर्गमूल१)
// प्रकार जांच
यदि (संख्या_है(योग)) {
लिखें("योग एक वैध संख्या है")
}
समाप्ति
कं

Compiler Design

Deep dive into Sanskriti compiler architecture and implementation

Compilation Pipeline

1

Lexical Analysis

Tokenization of Sanskrit source code

2

Syntax Analysis

Parse tree generation

3

Semantic Analysis

Type checking and validation

4

Code Generation

Intermediate code creation

5

Optimization

Performance enhancement

Compilation Flow

Source Code (.sk) → Lexer → Tokens
Tokens → Parser → AST
AST → Semantic Analyzer → Validated AST
Validated AST → Code Generator → Bytecode
Bytecode → Optimizer → Optimized Bytecode
Optimized Bytecode → Runtime → Execution

Lexical Analyzer

Token Recognition

Sanskrit Keywords

Recognizes Devanagari script tokens
प्रारंभ → BEGIN_TOKEN
यदि → IF_TOKEN
समाप्ति → END_TOKEN

Identifier Pattern

Unicode-aware identifier matching
Pattern: [अ-ह][अ-ह०-९_]*
Example: नाम, आयु१, मेरा_चर

Lexer Implementation

// Lexer state machine
class SanskritiLexer {
private position: number
private current_char: string
tokenize(): Token[] {
while (!this.isEOF()) {
this.skipWhitespace()
if (this.isDevanagari()) {
return this.readKeyword()
}
}
}
}

Parser Design

Grammar Rules

program → प्रारंभ statement_list समाप्ति
statement → assignment | if_stmt | while_stmt
assignment → IDENTIFIER = expression
if_stmt → यदि ( condition ) { statements }
expression → term ((+|-) term)*
term → factor ((*|/) factor)*
factor → NUMBER | IDENTIFIER | ( expression )

AST Structure

Program Node
Root node containing all statements
Statement Nodes
Assignment, If, While, Function calls
Expression Nodes
Binary operations, literals, identifiers

Semantic Analysis

Type Checking

  • • Variable type validation
  • • Function parameter matching
  • • Return type verification
  • • Implicit type conversion

Scope Analysis

  • • Variable declaration tracking
  • • Scope boundary management
  • • Name resolution
  • • Shadowing detection

Error Detection

  • • Undefined variable usage
  • • Type mismatch errors
  • • Unreachable code detection
  • • Dead code elimination

Symbol Table Example

Source Code:
संख्या आयु = २५
पाठ नाम = "राम"
बूलियन सक्रिय = सही
Symbol Table:
आयु: {type: संख्या, scope: global}
नाम: {type: पाठ, scope: global}
सक्रिय: {type: बूलियन, scope: global}

Code Generation

Bytecode Instructions

LOAD_CONST Load constant value
STORE_VAR Store in variable
BINARY_ADD Addition operation
CALL_FUNC Function call

Code Generation Example

Source:
संख्या a = १०
संख्या b = २०
संख्या sum = a + b
Generated Bytecode:
LOAD_CONST 10
STORE_VAR a
LOAD_CONST 20
STORE_VAR b
LOAD_VAR a
LOAD_VAR b
BINARY_ADD
STORE_VAR sum

Runtime System

Virtual Machine

Stack-based VM

Operand stack for expression evaluation

Memory Management

Automatic garbage collection for objects

Exception Handling

Runtime error detection and reporting

Execution Model

VM Execution Loop:
while (pc < bytecode.length) {
instruction = bytecode[pc]
switch (instruction.opcode) {
case LOAD_CONST:
stack.push(instruction.value)
case BINARY_ADD:
b = stack.pop()
a = stack.pop()
stack.push(a + b)
}
pc++
}

Complete Architecture

Sanskriti Compiler Architecture:
┌─ Frontend ─────────────────────────────────┐
│ Lexer → Parser → Semantic Analyzer │
└────────────────────────────────────────────┘
┌─ Middle-end ───────────────────────────────┐
│ AST → IR Generator → Optimizer │
└────────────────────────────────────────────┘
┌─ Backend ──────────────────────────────────┐
│ Code Generator → Bytecode → VM │
└────────────────────────────────────────────┘
┌─ Runtime ──────────────────────────────────┐
│ Stack Machine → GC → Built-in Functions │
└────────────────────────────────────────────┘
उदा

Sample Programs

Practical examples to master Sanskriti programming

Basic Programs

Hello World

/** पहला कार्यक्रम - नमस्ते संसार */
प्रारंभ
लिखें("नमस्ते संसार!")
लिखें("स्वागत है संस्कृति में")
समाप्ति
Output:
नमस्ते संसार!
स्वागत है संस्कृति में

Variables & Types

/** चर और प्रकार */
प्रारंभ
संख्या आयु = २५
पाठ नाम = "राम"
बूलियन सक्रिय = सही
दशमलव वेतन = ५०००.५०
लिखें("नाम: " + नाम)
लिखें("आयु: " + आयु)
समाप्ति
Output:
नाम: राम
आयु: २५

Control Structures

Conditional Logic

/** आयु जांच कार्यक्रम */
प्रारंभ
संख्या आयु = २०
यदि (आयु >= १८) {
लिखें("आप वयस्क हैं")
यदि (आयु >= ६०) {
लिखें("आप वरिष्ठ नागरिक हैं")
}
} अन्यथा {
लिखें("आप नाबालिग हैं")
}
समाप्ति

Loop Examples

/** संख्या गिनती */
प्रारंभ
// १ से १० तक गिनती
के लिए (i = १; i <= १०; i++) {
लिखें("संख्या: " + i)
}
// जब तक लूप
संख्या गिनती = १
जब तक (गिनती <= ५) {
लिखें("गिनती: " + गिनती)
गिनती = गिनती + १
}
समाप्ति

Mathematical Programs

Simple Calculator

/** सरल कैलकुलेटर */
प्रारंभ
दशमलव संख्या१ = १५.५
दशमलव संख्या२ = ४.५
दशमलव योग = संख्या१ + संख्या२
दशमलव अंतर = संख्या१ - संख्या२
दशमलव गुणा = संख्या१ * संख्या२
दशमलव भाग = संख्या१ / संख्या२
लिखें("योग: " + योग)
लिखें("अंतर: " + अंतर)
लिखें("गुणा: " + गुणा)
लिखें("भाग: " + भाग)
समाप्ति

Factorial Program

/** फैक्टोरियल गणना */
प्रारंभ
संख्या n = ५
संख्या फैक्टोरियल = १
संख्या i = १
जब तक (i <= n) {
फैक्टोरियल = फैक्टोरियल * i
i = i + १
}
लिखें(n + " का फैक्टोरियल: " + फैक्टोरियल)
समाप्ति
Output:
५ का फैक्टोरियल: १२०

Function Examples

Function Definition

/** फंक्शन परिभाषा और उपयोग */
कार्य वर्ग(संख्या x) {
वापसी x * x
}
कार्य अभिवादन(पाठ नाम) {
लिखें("नमस्ते " + नाम + "!")
}
प्रारंभ
संख्या परिणाम = वर्ग(५)
लिखें("५ का वर्ग: " + परिणाम)
अभिवादन("राम")
समाप्ति

Recursive Function

/** फिबोनाची श्रृंखला */
कार्य फिबोनाची(संख्या n) {
यदि (n <= १) {
वापसी n
} अन्यथा {
वापसी फिबोनाची(n-१) + फिबोनाची(n-२)
}
}
प्रारंभ
के लिए (i = ०; i <= ७; i++) {
संख्या परिणाम = फिबोनाची(i)
लिखें("फिब(" + i + ") = " + परिणाम)
}
समाप्ति

Array Programs

Array Operations

/** सरणी संचालन */
प्रारंभ
सरणी संख्याएं = [१०, २०, ३०, ४०, ५०]
संख्या योग = ०
// सभी तत्वों का योग
के लिए (i = ०; i < आकार(संख्याएं); i++) {
योग = योग + संख्याएं[i]
}
लिखें("कुल योग: " + योग)
लिखें("औसत: " + (योग / आकार(संख्याएं)))
समाप्ति

Linear Search

/** रैखिक खोज */
प्रारंभ
सरणी डेटा = [५, १२, ८, ३, १६]
संख्या लक्ष्य = ८
संख्या स्थिति = -१
के लिए (i = ०; i < आकार(डेटा); i++) {
यदि (डेटा[i] == लक्ष्य) {
स्थिति = i
}
}
यदि (स्थिति != -१) {
लिखें("तत्व मिला स्थिति: " + स्थिति)
} अन्यथा {
लिखें("तत्व नहीं मिला")
}
समाप्ति

Advanced Programs

Pattern Printing

/** तारा पैटर्न */
प्रारंभ
संख्या पंक्तियां = ५
के लिए (i = १; i <= पंक्तियां; i++) {
पाठ पैटर्न = ""
के लिए (j = १; j <= i; j++) {
पैटर्न = पैटर्न + "* "
}
लिखें(पैटर्न)
}
समाप्ति
Output Pattern:
*
* *
* * *
* * * *
* * * * *

Number System Converter

/** दशमलव से बाइनरी रूपांतरण */
कार्य बाइनरी_में_बदलें(संख्या दशमलव) {
पाठ बाइनरी = ""
जब तक (दशमलव > ०) {
संख्या शेष = दशमलव % २
बाइनरी = शेष + बाइनरी
दशमलव = दशमलव / २
}
वापसी बाइनरी
}
प्रारंभ
संख्या संख्या = २५
पाठ परिणाम = बाइनरी_में_बदलें(संख्या)
लिखें(संख्या + " का बाइनरी: " + परिणाम)
समाप्ति

Complete Project: Student Management

/** छात्र प्रबंधन प्रणाली */
कार्य छात्र_जोड़ें(सरणी छात्र_सूची, पाठ नाम, संख्या अंक) {
सरणी छात्र = [नाम, अंक]
धक्का(छात्र_सूची, छात्र)
लिखें("छात्र जोड़ा गया: " + नाम)
}
कार्य औसत_अंक(सरणी छात्र_सूची) {
संख्या कुल = ०
के लिए (i = ०; i < आकार(छात्र_सूची); i++) {
कुल = कुल + छात्र_सूची[i][१]
}
वापसी कुल / आकार(छात्र_सूची)
}
प्रारंभ
सरणी छात्र_डेटा = []
छात्र_जोड़ें(छात्र_डेटा, "राम", ८५)
छात्र_जोड़ें(छात्र_डेटा, "सीता", ९२)
छात्र_जोड़ें(छात्र_डेटा, "अर्जुन", ७८)
दशमलव औसत = औसत_अंक(छात्र_डेटा)
लिखें("कक्षा का औसत अंक: " + औसत)
// सभी छात्रों की सूची
के लिए (i = ०; i < आकार(छात्र_डेटा); i++) {
सरणी छात्र = छात्र_डेटा[i]
लिखें("छात्र: " + छात्र[०] + ", अंक: " + छात्र[१])
}
समाप्ति
खो

Search Results

Find documentation, examples, and resources quickly

Search Sanskriti Documentation

Enter keywords to find syntax, functions, examples, and more

Popular Searches:

Search Tips

Search Techniques

  • • Use Sanskrit keywords for better results
  • • Search for function names like "लिखें" or "पढ़ें"
  • • Try English equivalents like "print" or "if"
  • • Use quotes for exact phrases

Content Categories

  • Syntax: Language structure and grammar
  • Functions: Built-in and user-defined functions
  • Examples: Code samples and programs
  • Keywords: Reserved words and tokens
थी

Theme Settings

Customize your documentation experience

Appearance

Typography

Small Large
Current: 16px
Compact Spacious
Current: 1.6

Code Highlighting

Color Scheme

Preview

प्रारंभ
संख्या आयु = २५
पाठ नाम = "राम"
यदि (आयु >= १८) {
लिखें("वयस्क")
}
समाप्ति

Layout

Narrow Wide
Current: 256px

Compact Mode

Reduce spacing for more content

Cultural Elements

Sanskrit Decorations

Show cultural dividers and ornaments

Devanagari Icons

Use Sanskrit letters in section headers