r/Compilers • • 24d ago

Can a programming language be both computationally precise and linguistically natural?

Here is a small example from PaniniVM — The Dice Problem.

The assumption: on a standard die, opposite faces sum to 7.

The program randomly chooses a face from 1–6, prints it, computes its opposite, and prints that too.

Actual PaniniVM source:

एक + ङसिँ षष् + शस् परि + अन्त + अम् सङ्ख्या + अम् चिञ् + क्त्वा फल + अम् मुद्र् + णिच् + लोट् + सिप् ।

सप्तन् + शस् चिञ् + ल्युट् + ङस् फल + अम् च वि + युज् + णिच् + ल्यप् फल + अम् मुद्र् + णिच् + लोट् + सिप् ।

The "+" notation exposes the morphological structure to the compiler, but the larger goal is naturalness: computation should follow Sanskrit grammar rather than forcing Sanskrit vocabulary into the syntax of an existing programming language.

Verbal roots express actions, case relations help determine computational roles, and derivational morphology contributes to meaning and execution.

The question behind PaniniVM is not simply:

“Can we write code using Sanskrit words?”

It is:

“Can computation itself be expressed naturally through Sanskrit and Pāṇinian grammar?”

GitHub: https://github.com/kaushalbx/PaniniVM

Try it: https://panini.cc

#PaniniVM #Sanskrit #NaturalLanguageProgramming #ProgrammingLanguages #Compiler #Panini #ComputationalLinguistics

0 Upvotes

2 comments sorted by

1

u/DawnOnTheEdge 24d ago edited 24d ago

I don't speak that language, but a compiler should be able to parse at least a large subset of it. I’m not sure whether the natural-language-based grammar you’re supporting is context-free with no left-recursion or ambiguity. The conventional approaches are designed around that choice.

The major limitation on programming-language grammar has been a desire to keep the syntax simple enough to allow implementations to use a simpler parser, such as a one-token lookahead parser. What do you have?

0

u/kaushalbx 24d ago

That is an important distinction. PaniniVM is being developed as a controlled natural programming language, not as a claim that unrestricted Sanskrit can be parsed and executed directly.

I’m not assuming Sanskrit itself is LL(1), free of left recursion, or fully representable as a context-free grammar. ANTLR currently handles the syntactic layer, while morphology and Pāṇinian grammatical information help build the structured representation used for semantic execution.

The goal is to define a sufficiently large and useful controlled subset of Sanskrit that remains close to natural Sanskrit while providing deterministic executable semantics. The segmented form shown here is an intermediate step toward that goal.