This is a programming language based on world’s first language, Sanskrit. Designed to demonstrate basic programming constructs such as arithmetic operations, conditionals, loops, and more. This project came from the claim that NASA has conducted research on Sanskrit in the context of AI is widely spread. While it cannot be definitively confirmed, In 1985, NASA associate scientist Rick Briggs published a research paper in the spring issue of Artificial Intelligence magazine entitled “Vedic Science — ‘Knowledge Representation in Sanskrit and Artificial Intelligence.’” The article argued that natural languages are the best option to be converted into the computing program for robotic control and artificial intelligence technology.
Briggs also argued that Sanskrit is particularly well-suited for this task because of its highly structured grammar and its ability to express complex ideas in a concise and unambiguous way He even went so far as to suggest that Sanskrit could one day be used as the primary programming language for artificial intelligence.
For example, in 2017, a team of researchers at the Indian Institute of Technology Bombay developed a Sanskrit natural language processing toolkit called SanskritNLP. This toolkit can be used to perform a variety of natural language processing tasks, such as text classification, sentiment analysis, and machine translation.
In 2018, a team of researchers at the University of California, Berkeley developed a Sanskrit-English machine translation system that was shown to be more accurate than existing state-of-the-art systems.
These are just a few examples of the growing interest in using Sanskrit for natural language processing and artificial intelligence applications. It is possible that Sanskrit could one day be used in coding as it is more efficient in complex algorithms as well but more research is needed to develop the necessary technologies. This is my initiative to explore programming concepts using the ancient language of Sanskrit. I invite all coding enthusiat
- Arithmetic Operations:
- Addition:
योजयति
- Subtraction:
वियोजयति
- Multiplication:
गुणयति
- Division:
विभजति
- Addition:
- Variable Assignment:
परिवर्तन
- Printing:
प्रदर्शयति
- Comparison Operations:
- Equal to:
==
- Not equal to:
!=
- Less than:
<
- Greater than:
>
- Less than or equal to:
<=
- Greater than or equal to:
>=
- Equal to:
- Conditional Statements:
यदि
andअन्यथा
- Loops:
यावत्
- String Literals:
""
Strings are enclosed in double quotes. - Block Statements:
{}
- Break and continue statements:
ब्रेक
andकंटिन्यू
- Arrays and nested arrays:
[0,1,2,3]
and[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
- Functions and Procedures: Function definition
कार्य
and Function callकॉल
- Mixed data types in arrays:
INT
,FLOAT
andSTRING
To run the Sanskrit programming language interpreter, follow these steps:
-
Clone the repository:
git clone https://github.com/meghaos/Sanskrit.git cd Sanskrit
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install ply sphinx pytest
Create a file named test.s
and write your Sanskrit code in it. Then run the interpreter to execute your code.
Here are some example codes to demonstrate the features of the language:
परिवर्तन(a, 10)
परिवर्तन(b, 20)
प्रदर्शयति(योजयति(a, b)) # 30
प्रदर्शयति(वियोजयति(b, a)) # 10
प्रदर्शयति(गुणयति(a, b)) # 200
प्रदर्शयति(विभजति(b, a)) # 2.0
परिवर्तन(x, 5)
प्रदर्शयति(x) # 5
परिवर्तन(x, 15)
प्रदर्शयति(x) # 15
परिवर्तन(x, 15)
परिवर्तन(y, 10)
यदि (x == y) प्रदर्शयति("x == y") अन्यथा प्रदर्शयति("x != y") # x != y
यदि (x != y) प्रदर्शयति("x != y") # x != y
यदि (x > y) प्रदर्शयति("x > y") # x > y
यदि (x < y) प्रदर्शयति("x < y") अन्यथा प्रदर्शयति("x >= y") # x >= y
यदि (x >= 15) प्रदर्शयति("x >= 15") # x >= 15
यदि (y <= 10) प्रदर्शयति("y <= 10") # y <= 10
परिवर्तन(i, 1)
यावत् (i <= 5) {
प्रदर्शयति(i)
परिवर्तन(i, योजयति(i, 1))
}
परिवर्तन(x, 5)
प्रदर्शयति("Initial value of x is:")
प्रदर्शयति(x) # 5
परिवर्तन(y, 10)
यदि (x < y) {
प्रदर्शयति("x is less than y")
परिवर्तन(x, योजयति(x, y)) # x = x + y = 15
}
प्रदर्शयति("New value of x is:")
प्रदर्शयति(x) # 15
परिवर्तन(matrix, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
प्रदर्शयति(matrix[0][1]) # 2
प्रदर्शयति(matrix[1][2]) # 6
प्रदर्शयति(matrix[2][0]) # 7
परिवर्तन(matrix[1][1], 99)
प्रदर्शयति(matrix[1][1]) # 99
परिवर्तन(matrix[2], [10, 11, 12])
प्रदर्शयति(matrix[2][2]) # 12
परिवर्तन(mixedNestedArray, [[1, "two"], [3.0, "four"], [5, 6.7]])
प्रदर्शयति(mixedNestedArray[0][1]) # "two"
प्रदर्शयति(mixedNestedArray[1][0]) # 3.0
प्रदर्शयति(mixedNestedArray[2][1]) # 6.7
परिवर्तन(mixedNestedArray[1][1], "changed")
प्रदर्शयति(mixedNestedArray[1][1]) # "changed"
परिवर्तन(array, [10, 20, 30, 40, 50])
परिवर्तन(i, 0)
यावत् (i < 5) {
परिवर्तन(array[i], योजयति(array[i], 1))
परिवर्तन(i, योजयति(i, 1))
}
प्रदर्शयति(array[0]) # 11
प्रदर्शयति(array[1]) # 21
प्रदर्शयति(array[2]) # 31
प्रदर्शयति(array[3]) # 41
प्रदर्शयति(array[4]) # 51
परिवर्तन(array1, [1, 2, 3])
परिवर्तन(array2, [4, 5, 6])
परिवर्तन(array3, [7, 8, 9])
परिवर्तन(nestedArrays, [array1, array2, array3])
प्रदर्शयति(nestedArrays[0][1]) # 2
प्रदर्शयति(nestedArrays[1][1]) # 5
प्रदर्शयति(nestedArrays[2][1]) # 8
परिवर्तन(matrix, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
परिवर्तन(i, 0)
यावत् (i < 3) {
परिवर्तन(j, 0)
यावत् (j < 3) {
परिवर्तन(matrix[i][j], गुणयति(matrix[i][j], 2))
परिवर्तन(j, योजयति(j, 1))
}
परिवर्तन(i, योजयति(i, 1))
}
प्रदर्शयति(matrix[0][0]) # 2
प्रदर्शयति(matrix[1][1]) # 10
प्रदर्शयति(matrix[2][2]) # 18
परिवर्तन(mixedMatrix, [[1, "a"], [2.5, "b"], ["c", 3]])
प्रदर्शयति(mixedMatrix[0][1]) # "a"
प्रदर्शयति(mixedMatrix[1][0]) # 2.5
प्रदर्शयति(mixedMatrix[2][1]) # 3
परिवर्तन(mixedMatrix[1][1], "updated")
प्रदर्शयति(mixedMatrix[1][1]) # "updated"
कार्य(मेरा_कार्य) {
प्रदर्शयति("कार्य से नमस्ते")
}
कॉल(मेरा_कार्य)
कार्य(सहायक_कार्य) {
परिवर्तन(x, 10)
प्रदर्शयति(x)
}
कॉल(सहायक_कार्य)
कार्य(गणित_कार्य) {
परिवर्तन(a, 5)
परिवर्तन(b, 3)
परिवर्तन(c, योजयति(a, b))
प्रदर्शयति(c)
}
कॉल(गणित_कार्य)
कार्य(जांच_कार्य) {
परिवर्तन(x, 10)
यदि (x > 5) {
प्रदर्शयति("x is greater than 5")
} अन्यथा {
प्रदर्शयति("x is not greater than 5")
}
}
कॉल(जांच_कार्य)
कार्य(लूप_कार्य) {
परिवर्तन(x, 0)
यावत् (x < 5) {
प्रदर्शयति(x)
परिवर्तन(x, योजयति(x, 1))
}
}
कॉल(लूप_कार्य)
कार्य(बाहरी_कार्य) {
प्रदर्शयति("बाहरी कार्य")
कॉल(आंतरिक_कार्य)
}
कार्य(आंतरिक_कार्य) {
प्रदर्शयति("आंतरिक कार्य")
}
कॉल(बाहरी_कार्य)
कार्य(सरणी_कार्य) {
परिवर्तन(arr, [1, 2, 3, 4, 5])
प्रदर्शयति(arr[2]) # Expected output: 3
}
कॉल(सरणी_कार्य)
कार्य(नेस्टेड_सरणी_कार्य) {
परिवर्तन(matrix, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
प्रदर्शयति(matrix[1][2]) # Expected output: 6
}
कॉल(नेस्टेड_सरणी_कार्य)
Run your interpreter script:
python interpreter.py
Make sure the test.s file contains your Sanskrit code. The interpreter will read this file, parse the code, and execute it.
License: This project is licensed under the GNU General Public License Version 2. See the LICENSE file for details.
Contributing: Contributions are welcome! Please create a pull request with your changes and ensure that your code follows the existing coding style.
Acknowledgements: This project is inspired by the rich linguistic heritage of Sanskrit and is designed as a fun way to learn and explore programming concepts.