Skip to content

theSohamTUmbare/NO_language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NO Language — Natural-language-first DSL that compiles to Python

NO Language is an experimental, natural-language-first programming language (a small DSL) that turns human instructions into executable Python.

Instead of writing low-level syntax everywhere, you write intent:

make_dataframe ```pandas {
    create a dataframe with 5 rows of random numbers
    print the mean of the first column
}

Visualizer ```matplotlib {
    plot the data from make_dataframe as a red line
    show it
}

Output

output_image

output_code ->

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(5, 3))
print(df[0].mean())

import matplotlib.pyplot as plt
plt.plot(df[0], color='red')
plt.show()

Behind the scenes, NO:

  1. Parses your .no file using a real grammar (Lark).
  2. Transpiles each block into Python using Gemini.
  3. Validates the generated code (syntax + security checks).
  4. Executes the final program.

This repo is intentionally small but engineered like a real compiler pipeline.


Why this project is interesting (engineering value)

This is not “just prompts.” It’s a language toolchain:

  • Formal parsing: A dedicated grammar (core/grammar.lark) with nested blocks, named blocks, optional type hints, and verbatim blocks.
  • Context-aware compilation: Each block is compiled with the already-generated Python as context so references resolve naturally.
  • Defense-in-depth execution: Generated Python is AST-parsed for syntax, then scanned for dangerous calls before it can run.
  • Built-in AI debugging: When execution fails, the engine requests a compact explanation + likely .no-level fix.

Project metrics (from this repo)

  • 249 lines of Python across the compiler runtime (main.py + core/*.py).
  • 13 grammar productions defining the NO syntax (core/grammar.lark).
  • 2 compilation modes:
    • “Natural language blocks” → Python
    • :::lang verbatim code blocks (e.g., C++/Java) → Python
  • 7 blocked high-risk API patterns in the default security blacklist.
  • 2 runtime dependencies: lark, google-genai

How it works (high-level architecture)

.no file
	↓
Lark parser (core/grammar.lark)
	↓
AST walk per block
	↓
Gemini transpilation (block-by-block, context aware)
	↓
Sanitize output (strip markdown fences if any)
	↓
Validate:
	- Syntax: ast.parse()
	- Security: blacklist scan on AST
	↓
exec() the final Python program

Core components:

  • core/engine.py: parsing + compilation orchestration + execution + AI debugger
  • core/validator.py: AST-based validation (syntax + blacklist security scan)
  • core/grammar.lark: language grammar
  • main.py: minimal CLI entrypoint

Setup

0) Use a virtual environment (recommended)

create your own venv:

python -m venv .venv
./.venv/Scripts/Activate.ps1

1) Install dependencies

pip install -r requirements.txt

2) Configure Gemini API key

This project reads the API key from the environment variable GEMINI_API_KEY.

PowerShell:

$env:GEMINI_API_KEY = "YOUR_KEY_HERE"

Run

Make sure your venv is activated first (so google-genai is available).

python main.py test.no

What you’ll see:

  • A “Compiling …” line for each NO block
  • The full generated Python printed before execution
  • The program output

Language syntax (quick reference)

NO is block-based.

1) Standard block

[type_hint] block_name [library_list] {
	commands...
	nested blocks...
}
  • type_hint: func, function, or class (optional)
  • block_name: an identifier, optionally with parameters: name(a, b)
  • library_list (optional): triple-backtick token followed by library names, used as a transpilation hint

Example:

func make_dataframe ```pandas {
		create a dataframe with 5 rows of random numbers
		print the mean of the first column
}

2) Verbatim block

Use this when you want to paste code from another language and ask NO to convert it into Python.

:::cpp cpp_block <---
// C++ here
--->

Safety model (important)

NO executes LLM-generated Python. To reduce risk, the runtime includes a basic AST-based denylist that blocks calls matching these patterns:

  • os.system
  • subprocess
  • shutil
  • eval
  • exec
  • open
  • remove

Notes:

  • This is a best-effort safeguard, not a hardened sandbox.
  • Treat .no programs like code execution: run in an isolated environment.

Limitations (current)

  • Output quality depends on the LLM; generated code can still be wrong even if syntactically valid.
  • The security layer is intentionally simple and may miss dangerous constructs.
  • There’s no persistent module system yet; compilation is currently “single-file, in-order”.

Roadmap ideas

  • Replace denylist with a safer execution model (capabilities / allowlist / sandbox)
  • Add deterministic semantics for variables + types (symbol table enforcement)
  • Add test harness and golden-file tests for stable transpilation
  • Improve error mapping from Python tracebacks back to .no blocks

About

I am making a coding language with no (minimum) rules possible using the AI to eliminate the need of syntax memorizing for the user.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages