A Sanskrit-inspired programming language with Python-based interpreter, built-in editor, and REPL.
Sanskrit Programming Language is a modern programming language that draws inspiration from the precision, structure, and elegance of Sanskrit grammar. It features Sanskrit-based syntax, strong type inference, and a comprehensive standard library with Sanskrit naming conventions.
- Sanskrit-based Syntax: Keywords, operators, and grammar follow Sanskrit terminology
- Strong Type System: Elegant type inference inspired by Sanskrit word classification (वर्ण)
- Python-based Interpreter: Written in pure Python for portability and ease of use
- Built-in Editor: GUI editor with syntax highlighting using tkinter
- Interactive REPL: Read-Eval-Print Loop for live coding and experimentation
- Sanskrit Error Messages: Clear, informative error messages in Sanskrit/Devanagari
- गणित (Ganita): Mathematics and numerical operations
- शब्द (Shabda): String manipulation and text processing
- प्रवेश (Pravesh): Input/output operations and file handling
- Documentation System: Built-in
doc
command for help and documentation - Example Programs: Comprehensive examples demonstrating language features
- Type Safety: Compile-time type checking with Sanskrit-inspired type names
- Unicode Support: Full support for Devanagari script and Sanskrit text
- Python 3.8 or higher
- tkinter (usually included with Python)
- No external dependencies required for core functionality
git clone https://github.com/prakhardoneria/sanskrit-lang.git
cd sanskrit-lang
python main.py --help
python main.py --repl
# or simply
python main.py
python main.py --editor
python main.py examples/hello.sans
python main.py examples/fibonacci.sans
python main.py examples/types.sans
# Variables (चर)
धारणा नाम = "राम" # Variable declaration
धारणा उम्र = २५ # Using Devanagari numerals
स्थिर पाई = ३.१४१५९ # Constant declaration
# Output (आउटपुट)
मुद्रण("नमस्ते संसार!") # Print statement
मुद्रण("नाम:", नाम) # Print with variables
# Functions (कार्य)
कार्य अभिवादन(व्यक्ति) {
मुद्रण("नमस्कार", व्यक्ति)
वापसी सत्य # Return statement
}
# Conditionals (शर्त)
यदि उम्र >= १८ {
मुद्रण("वयस्क")
} अथवा {
मुद्रण("नाबालिग")
}
# Loops (लूप)
धारणा i = १
यावत् i <= ५ { # While loop
मुद्रण(i)
i = i + १
}
प्रति संख्या में सूची { # For loop
मुद्रण(संख्या)
}
- संख्या (Numbers): १२३, ३.१४, -५
- शब्द (Strings): "नमस्ते", 'Hello'
- सत्य/असत्य (Booleans): सत्य, असत्य
- शून्य (Null): शून्य
- Arithmetic: + (yoga), - (vyavakalana), * (guna), / (bhaga), % (shesh)
- Comparison: == (sama), != (asama), < (laghu), > (mahan), <= (laghu_sama), >= (mahan_sama)
- Logical: च (and), वा (or), न (not)
- मुद्रण() - Print output
- प्रकार() - Get type of variable
- लम्बाई() - Get length
- संख्या() - Convert to number
- सुन्दर() - Convert to string
आयात गणित
गणित.वर्गमूल(१६) # Square root: 4
गणित.sin(गणित.pi/२) # Sine: 1
गणित.factorial(५) # Factorial: 120
आयात शब्द
शब्द.uchcha("नमस्ते") # Uppercase
शब्द.lambai("संस्कृत") # Length: 7
शब्द.vibhajan("क,ख,ग", ",") # Split
आयात प्रवेश
नाम = प्रवेश.paath("नाम दर्ज करें: ") # Input
प्रवेश.file_padhiye("test.txt") # Read file
प्रवेश.file_likhiye("output.txt", "data") # Write file
The examples/
directory contains sample programs:
- hello.sans - Basic syntax demonstration with variables, functions, and loops
- fibonacci.sans - Fibonacci sequence using both recursive and iterative approaches
- types.sans - Type system examples and type conversions
When using the interactive REPL, you can use these special commands:
सहायता
/help
- Show help informationबाहर
/exit
- Exit the REPLइतिहास
/history
- Show command historyसाफ
/clear
- Clear screenचर
/vars
- Show defined variablesदस्तावेज़ [topic]
- Show documentation for a topicउदाहरण [topic]
- Show examples
All error messages are displayed in Sanskrit/Devanagari script:
- व्याकरण त्रुटि - Syntax Error
- रनटाइम त्रुटि - Runtime Error
- प्रकार त्रुटि - Type Error
- नाम त्रुटि - Name Error
✅ Complete Implementation
- Sanskrit-based lexer with Devanagari support
- Recursive descent parser with proper AST generation
- Tree-walking interpreter with environment-based scoping
- Variable declarations and assignments
- Control flow (if/else, while loops, for loops)
- Function definitions and calls with parameters
- Built-in functions and standard library modules
- Interactive REPL with command history and help
- GUI editor with syntax highlighting
- Comprehensive error handling in Sanskrit
✅ Unicode Support
- Full Devanagari script support for keywords and identifiers
- Devanagari numeral support (०१२३४५६७८९)
- Mixed Sanskrit/English identifier support
- Unicode string handling
✅ Development Tools
- Built-in syntax highlighting editor
- Interactive REPL with special commands
- Example programs demonstrating language features
- Built-in documentation system
The Sanskrit Programming Language is designed to showcase Sanskrit-inspired programming concepts. The implementation demonstrates:
- Sanskrit Grammar Influence: Keywords and operators follow Sanskrit terminology
- Type System: Inspired by Sanskrit word classification (वर्ण)
- Cultural Programming: Bridging ancient wisdom with modern technology
- Educational Value: Teaching programming through Sanskrit linguistic concepts
This project is open source and available for educational and research purposes