Sanskrit as a programming language

Sangram Kesari Ray
4 min readJan 27, 2021

Before we talk about whether Sanskrit is suitable for computer programming, let’s talks about what is a programming language.

A programming language is basically a set of instructions you pass to a computer to do a certain tasks.

Computer understands what we call Machine code. A computer can only do computation if it can do these 3 things:

  1. It can move to a given location
  2. It can read from a given location
  3. It can write to a given location

A machine that can do these 3 things is a Turing machine, named after one of the pioneers in Theoretical computer science, Alan Turing.

A programming language that can ask a Turning machine to perform these 3 operations is a language which is Turing complete.

If you study x86, the mov instruction is turning complete, you can read from volatile memory, you can write to it and you can access any part of the volatile memory, known as addressed, in x86 it’s 32-bit addressing.

With those basics lets talk about how a given language translates into machine code.

First phase is to build tokens from the given txt file.

Second is to build a tree structure called Abstract Syntax Tree from those tokens.

Third is to build the machine code from that tree.

That’s all there’s to converting any programming language to machine code.

This machine code is understood by the CPU, the CPU does 3 operations; Fetch, Decode, Execute. So it fetches the instruction given in machine code or bytes, then decodes what’s asked to do, then it does the actual operation.

In case of mov operation;

let’s say it’s

mov eax, 3

it means the following in machine code

b8 03 00 00 00

So, the CPU will take care of the actual operation from this point once you’ve given it a file containing those bites. Literally if you can write a text file with bytes in it and save it as .exe, it’ll execute, you don’t need to write a C program or need a compiler. Using a Hex editor you can write programs directly in machine code.

Next, how the CPU does these operations is through digital logic, as we know there are two universal logic gates NAND and NOR, so it’ll be able to control the current flow to initialize a capacitor to store the charge. Transistors control the flow of charge/dielectricity/electrons, while capacitor stores it. This is temporary, but for persistent storage we use magnetic components in case of a hard-drive by initializing it’s dipole polarity.

What we’re looking at is capacitance, resistance, permittivity and permeability using elements from Earth.

That’s a lot to take in but this is the gestalt understanding of how computers work.

With this we can now discuss sanskrit. All we need to do is to build a tokenizer to take the instructions from Sanskrit grammar, build the Abstract Syntax Tree and convert it to machine code.

Now let’s discuss if Sanskrit is more suitable than English to write the source-code in the first place, because the other conversion parts will be the same and we’ve to get to those binary format at the end.

Let’s take this shloka from Bhagwad Gita 18:78, here Krishna is telling Arjuna,

यत्र योगेश्वर: कृष्णो यत्र पार्थो धनुर्धर: | तत्र श्रीर्विजयो भूतिध्रुवा नीतिर्मतिर्मम ||

Translation (English)

Wherever there is Shree Krishna, the Lord of all Yog, and wherever there is Arjun, the supreme archer, there will also certainly be unending opulence, victory, prosperity, and righteousness. Of this, I am certain.

Python pseudo-code

Class Krishna:  yogeshwar = TrueClass Arjuna:  dhanurdhara = True# conditionalif Krishna() and Arjuna():  return self.victory

As you can see the Sanskrit is a succinct translation to python code, this can be done to any programming language for that matter. It’s even more efficient if written in x86. Like this

mov krishna_yogeshwar, 1mov arjuna_dhanurdhara, 1; conditionalmov eax, krishna_isYogeshwarmov ebx, arjuna_isDhanurdharacmp eax, ebxje victory

This happens because of Sanskrit grammar, which creates an efficient human language. Sanskrit is a direct translatable to any programming language and x86.

Various methods to develop Sanskrit as a programming language:

  1. Create an interpreter to generate bytecode for Python or Java VM
  2. Create a compiler front-end using LLVM
  3. Create an assembler/compiler to generate the machine-code directly

Bottom line is, with Sanskrit you don’t need to have a huge book of a thousand pages as you’ve in Java or Python or Assembler to discuss what’s possible with a language. You only need to be good enough in Sanskrit as a human language, reading, speaking, writing.

Sanskrit is ideal for Natural language processing and we can recite some verses and the computer will be able to write the program for us. We don’t even have to write the code by hand. Imagine that!

Sanskrit algorithms will be self-contained, they don’t need any elaborate descriptions like others.

Here’s a an algorithm for infinite loop from Aitareya Brahmana, 7.15, can be used in system programming and servers.

Charaiveti, charaiveti.

Translation(English)

Keep moving, keep moving!

Let’s translate it to x86

section .text
global _start
_start:
jmp _start

Just one word for infinite-loop in Sanskrit, self-contained sentence, same as x86. Sanskrit programming language book will be without a pseudo-code, that book would consist of verses like above in 18:78 or 7.15.

With Sanskrit you get to convey in a succinct manner, the recipient gets exactly what you’ve conveyed, this is because of the grammar developed by Panini’s Ashtadhyayi and rich vocabulary. You’ll have to first learn Sanskrit to be able to program in Sanskrit and develop the programming language for it.

Next Sanskrit programming language to build the compiler for Sanskrit programming language. Once the first compiler/assembler written in Sanskrit is ready to take input as .skt source files for Sanskrit, then this language becomes self-sufficient. Its compiler/assembly will produce the bytecode which Python or Java VM can understand or machine-code which the CPU can understand. Of course, using NLP we don’t even have to write the code ourselves once we have the Compiler pipeline ready.

Aham Brahmasmi - ich bin dieses Brahman.

--

--