https://github.com/sauravbhattacharya001/sauravcode
Frustrated by syntax-heavy languages, I designed *sauravcode* for simplicity and clarity. It removes unnecessary punctuation and rigid conventions, focusing purely on logic. With minimal syntax, it allows ideas to flow naturally without distraction. *Sauravcode* is my tool for coding as a seamless, intuitive process, free from constraints.
https://github.com/sauravbhattacharya001/sauravcode
c-language code-generation compiler custom-language interpreter language-design parser programming-language python transpiler
Last synced: 1 day ago
JSON representation
Frustrated by syntax-heavy languages, I designed *sauravcode* for simplicity and clarity. It removes unnecessary punctuation and rigid conventions, focusing purely on logic. With minimal syntax, it allows ideas to flow naturally without distraction. *Sauravcode* is my tool for coding as a seamless, intuitive process, free from constraints.
- Host: GitHub
- URL: https://github.com/sauravbhattacharya001/sauravcode
- Owner: sauravbhattacharya001
- License: mit
- Created: 2024-11-10T02:31:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-02T13:43:42.000Z (1 day ago)
- Last Synced: 2026-04-02T17:41:19.123Z (1 day ago)
- Topics: c-language, code-generation, compiler, custom-language, interpreter, language-design, parser, programming-language, python, transpiler
- Language: Python
- Size: 1.79 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: docs/SECURITY.md
Awesome Lists containing this project
README
sauravcode
A programming language designed for clarity. No noise, just logic.
---
**sauravcode** is a programming language that strips away the ceremony of traditional syntax. No parentheses for function calls. No commas between arguments. No semicolons. No braces. Just clean, readable code that flows like thought.
It comes with both an **interpreter** for rapid prototyping and a **compiler** that produces native executables via C code generation.
π **[Documentation Site](https://sauravbhattacharya001.github.io/sauravcode/)** Β· π **[Language Reference](docs/LANGUAGE.md)** Β· ποΈ **[Architecture Guide](docs/ARCHITECTURE.md)**
---
## β¨ Features
- **Minimal syntax** β no parentheses, commas, semicolons, or braces
- **Dual execution** β interpreted (`saurav.py`) or compiled to native (`sauravcc.py`)
- **Interactive REPL** β experiment with sauravcode in real-time
- **Functions & recursion** β with clean call syntax
- **Lambda expressions** β `lambda x -> x * 2` for inline functions
- **Pipe operator** β `"hello" |> upper |> reverse` for chaining
- **Dynamic typing** β integers, floats, booleans, strings, lists, maps
- **Control flow** β if/else if/else, while, range-based for, for-each, break/continue
- **Pattern matching** β `match` expressions with wildcard and literal patterns
- **Generators** β functions with `yield` for lazy sequences
- **Enums** β named constant groups with dot access
- **Classes** β with fields, methods, and `self`
- **Error handling** β try/catch/throw blocks
- **Import system** β `import "module.srv"` with closure scoping
- **Lists** β dynamic arrays with append, pop, len, indexing, slicing, comprehensions
- **Maps** β key-value dictionaries with `{}` syntax, bracket access, and built-in functions
- **105 built-in functions** β strings, math, stats, regex, date/time, JSON, encoding, hashing, HTTP, I/O, bitwise
- **String interpolation** β `f"Hello {name}, you are {age} years old"` f-strings
- **Logical operators** β `and`, `or`, `not`
- **Compiler generates readable C** β inspect with `--emit-c`
- **Developer tooling** β formatter, linter, profiler, debugger, coverage, benchmarks, AST visualizer, playground, dependency graph, complexity analyzer, notebook runner, watch mode, snapshot testing
- **VS Code extension** β syntax highlighting, 25 snippets, and language configuration
## π Quick Start
### Install from PyPI
```bash
pip install sauravcode
```
After installation, two commands are available globally:
- `sauravcode` β interpreter + interactive REPL
- `sauravcode-compile` β compiler (.srv β C β native executable)
### Prerequisites
- **Python 3.8+**
- **gcc** (for compiler β MinGW on Windows, Xcode CLI on macOS)
### Interactive REPL
Start the REPL with no arguments for instant experimentation:
```bash
python saurav.py
```
```
sauravcode REPL v1.0
Type "help" for commands, "quit" to exit.
>>> x = 10
>>> print x + 5
15
>>> function double n
... return n * 2
...
>>> print double x
20
>>> vars
x = 10
>>> quit
Bye!
```
REPL commands: `help`, `vars`, `funcs`, `clear`, `history`, `load FILE`, `quit`
### Run a File
```bash
python saurav.py hello.srv
```
### Compile to Native Executable
```bash
python sauravcc.py hello.srv # Compile and run
./hello # Run the binary directly
```
## π Language at a Glance
### Hello World
```
print "Hello, World!"
```
### Functions
No parentheses, no commas β just the function name and its arguments:
```
function greet name
print "Hello,"
print name
greet "world"
```
### Variables & Arithmetic
```
x = 10
y = 3
print x + y # 13
print x * y # 30
print x % y # 1
```
### Control Flow
```
score = 85
if score >= 90
print "A"
else if score >= 80
print "B"
else
print "below B"
```
### Loops
```
# While
i = 0
while i < 5
print i
i = i + 1
# For (range-based)
for i 1 6
print i # prints 1 through 5
# Break and Continue
for i 0 10
if i == 5
break # exit loop early
if i % 2 == 0
continue # skip even numbers
print i # prints 1, 3
```
### Recursion
Use parentheses only when you need to disambiguate nested expressions:
```
function factorial n
if n <= 1
return 1
return n * factorial (n - 1)
print factorial 10 # 3628800
```
### Lists
```
nums = [10, 20, 30]
print nums[0] # 10
print len nums # 3
append nums 40
print nums[3] # 40
```
### Maps (Dictionaries)
```
# Create a map with { key: value } syntax
person = {"name": "Alice", "age": 30, "active": true}
print person["name"] # Alice
# Add/update keys
person["email"] = "alice@example.com"
person["age"] = 31
# Built-in map functions
k = keys person # list of keys
v = values person # list of values
print has_key (person) "name" # true
print contains (person) "email" # true
print len person # 4
print type_of person # map
# Word frequency counter
words = split "hello world hello" " "
freq = {}
for i 0 len words
word = words[i]
if contains (freq) word
freq[word] = freq[word] + 1
else
freq[word] = 1
print freq["hello"] # 2
```
### String Interpolation (F-Strings)
Embed expressions directly in strings with the `f"..."` syntax:
```
name = "Alice"
age = 30
print f"Hello, {name}!" # Hello, Alice!
print f"{name} is {age} years old" # Alice is 30 years old
print f"2 + 3 = {2 + 3}" # 2 + 3 = 5
# Works with any expression
items = [1, 2, 3]
print f"count: {len items}" # count: 3
print f"upper: {upper name}" # upper: ALICE
# Escaped braces: {{ and }} produce literal { and }
x = 42
print f"value: {{x}} = {x}" # value: {x} = 42
```
### Classes
```
class Point
function init x y
self.x = x
self.y = y
```
### Error Handling
```
try
x = risky_operation
catch err
print "something went wrong"
```
### Standard Library
Sauravcode includes **95 built-in functions** β no imports needed. See the full [Standard Library Reference](STDLIB.md).
```
# String functions
print upper "hello" # HELLO
print lower "HELLO" # hello
print trim " spaces " # spaces
print replace "hi world" "world" "sauravcode"
words = split "a-b-c" "-" # ["a", "b", "c"]
print join ", " words # a, b, c
print contains "hello" "ell" # true
print starts_with "hello" "he" # true
print substring "hello" 0 3 # hel
print char_at "hello" 0 # h
# Math functions
print sqrt 16 # 4
print power 2 10 # 1024
print round 3.14159 2 # 3.14
print floor 3.7 # 3
print ceil 3.2 # 4
print abs (-42) # 42
# Statistics
print mean [1, 2, 3, 4, 5] # 3.0
print median [1, 3, 5, 7] # 4.0
print stdev [2, 4, 4, 4, 5] # 0.894...
# Regex
print regex_match "^\d+$" "42" # true
print regex_replace "\s+" "-" "a b c" # a-b-c
# Date/Time
print now # 2026-03-07T15:...
d = date_add (now) 7 "days" # one week from now
# JSON
data = json_parse "{\"x\": 1}" # {"x": 1}
print json_pretty data # formatted
# Hashing & Encoding
print sha256 "hello" # 2cf24dba...
print base64_encode "hello" # aGVsbG8=
# Map functions
m = {"a": 1, "b": 2}
k = keys m # ["a", "b"]
v = values m # [1, 2]
print has_key (m) "a" # true
print contains (m) "c" # false
```
Type `builtins` in the REPL to see all available functions with usage.
## βοΈ Compiler
The compiler (`sauravcc.py`) translates sauravcode to C, then uses gcc to produce native executables.
```bash
# Compile and run
python sauravcc.py program.srv
# Emit C code only (inspect the generated code)
python sauravcc.py program.srv --emit-c
# Compile to a specific output name
python sauravcc.py program.srv -o myprogram
# Keep the intermediate .c file
python sauravcc.py program.srv --keep-c
# Verbose output
python sauravcc.py program.srv -v
```
### Compilation Pipeline
```
ββββββββββββ βββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββ
β .srv βββββΆβ Tokenize βββββΆβ Parse βββββΆβ Generate βββββΆβ gcc β
β source β β (lexer) β β (AST) β β (C code)β β (native) β
ββββββββββββ βββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββ
```
### Supported Features
| Feature | Interpreter | Compiler |
|---------|:-----------:|:--------:|
| Interactive REPL | β
| β |
| Functions & recursion | β
| β
|
| Variables & assignment | β
| β
|
| Arithmetic (+, -, *, /, %) | β
| β
|
| Comparisons (==, !=, <, >, <=, >=) | β
| β
|
| Booleans & logical ops | β
| β
|
| If / else if / else | β
| β
|
| While loops | β
| β
|
| For loops (range-based) | β
| β
|
| Break & continue | β
| β
|
| Strings | β
| β
|
| Lists (dynamic arrays) | β
| β
|
| Maps (dictionaries) | β
| β |
| String interpolation (f-strings) | β
| β |
| Lambda expressions | β
| β |
| Pipe operator | β
| β |
| Pattern matching | β
| β |
| Generators (yield) | β
| β |
| Enums | β
| β |
| Import system | β
| β |
| Classes | β
| β
|
| Try / catch | β
| β
|
| Parenthesized expressions | β
| β
|
| Negative numbers | β
| β
|
## π³ AST Visualizer
Explore how sauravcode parses your programs with the AST visualizer (`sauravast.py`):
```bash
# Pretty tree view
python sauravast.py hello.srv
# Limit depth for large programs
python sauravast.py program.srv --depth 3
# Machine-readable JSON
python sauravast.py program.srv --json
# Node statistics
python sauravast.py program.srv --stats
# Graphviz DOT graph (pipe to dot -Tpng for images)
python sauravast.py program.srv --dot | dot -Tpng -o ast.png
```
Example output:
```
Program
βββ AssignmentNode
β βββ expression: NumberNode
β β βββ value: 42.0
β βββ name: 'x'
βββ FunctionNode
β βββ body: [2 items]
β β βββ [0]: PrintNode ...
β β βββ [1]: ReturnNode ...
β βββ name: 'greet'
β βββ params: ['name']
βββ FunctionCallNode
βββ arguments: [1 items]
β βββ [0]: StringNode
β βββ value: 'World'
βββ name: 'greet'
```
## π₯ Advanced Features
### Lambda Expressions
Inline anonymous functions for quick transformations:
```
double = lambda x -> x * 2
print double 5 # 10
# With higher-order functions
nums = [1, 2, 3, 4, 5]
doubled = map (lambda x -> x * 2) nums
print doubled # [2, 4, 6, 8, 10]
filtered = filter (lambda x -> x > 3) nums
print filtered # [4, 5]
```
### Pipe Operator
Chain transformations left-to-right for readable data pipelines:
```
result = "hello world" |> upper |> reverse
print result # DLROW OLLEH
# Multi-step pipelines
" Hello, World! " |> trim |> lower |> print
# hello, world!
```
### Pattern Matching
Declarative branching with `match` expressions:
```
function describe x
match x
1 -> print "one"
2 -> print "two"
3 -> print "three"
_ -> print "something else"
describe 2 # two
describe 99 # something else
```
### Generators
Lazy sequences with `yield` for memory-efficient iteration:
```
function countdown n
while n > 0
yield n
n = n - 1
gen = countdown 5
print next gen # 5
print next gen # 4
print next gen # 3
```
### Enums
Named constant groups with dot-notation access:
```
enum Color
RED
GREEN
BLUE
c = Color.RED
print c # Color.RED
match c
Color.RED -> print "red!"
Color.GREEN -> print "green!"
_ -> print "other"
```
### Imports
Modular code with file-based imports:
```
# math_utils.srv
function square x
return x * x
function cube x
return x * x * x
# main.srv
import "math_utils.srv"
print square 5 # 25
print cube 3 # 27
```
## π οΈ Developer Tooling
Sauravcode ships with a comprehensive suite of developer tools:
| Tool | Command | Description |
|------|---------|-------------|
| **Formatter** | `python sauravfmt.py file.srv` | Auto-format code with consistent indentation and spacing |
| **Linter** | `python sauravlint.py file.srv` | Static analysis for style, complexity, and potential bugs |
| **Profiler** | `python sauravprof.py file.srv` | Execution profiling with call counts and timing |
| **Debugger** | `python sauravdb.py file.srv` | Interactive debugger with breakpoints and step-through |
| **Coverage** | `python sauravcov.py file.srv` | Code coverage analysis (line-level hit/miss) |
| **Benchmarks** | `python sauravbench.py` | Performance benchmarks (fibonacci, sort, recursion, etc.) |
| **AST Viewer** | `python sauravast.py file.srv` | Parse tree visualization (text, JSON, Graphviz DOT) |
| **Playground** | `python sauravplay.py` | Interactive sandbox for experimenting |
| **Semantic Diff** | `python sauravdiff.py a.srv b.srv` | Structural diff between sauravcode files |
| **Doc Generator** | `python sauravdoc.py file.srv` | Extract documentation from source files |
| **Dependency Graph** | `python sauravdeps.py file.srv` | Visualize import dependencies between modules |
| **Complexity** | `python sauravcomplex.py file.srv` | Cyclomatic complexity analysis per function |
| **Notebook** | `python sauravnb.py file.srvnb` | Jupyter-style notebook for literate sauravcode |
| **Watch Mode** | `python sauravwatch.py file.srv` | Auto-rerun on file changes (live reload) |
| **Snapshot Test** | `python sauravsnap.py file.srv` | Snapshot testing for output verification |
| **Enhanced REPL** | `python sauravrepl.py` | REPL with history, multi-line editing, and syntax hints |
| **Canvas** | `python sauravcanvas.py file.srv` | Turtle graphics β generate SVG/HTML from drawing commands |
## ποΈ Architecture
The codebase has two execution paths sharing a common tokenizer design:
- **`saurav.py`** β Tree-walk interpreter. Tokenizes, parses to AST, evaluates directly.
- **`sauravcc.py`** β Compiler. Tokenizes, parses to AST, generates C source, invokes gcc.
The compiler generates clean, readable C. Lists become dynamic arrays (`SrvList`) with bounds checking. Try/catch maps to `setjmp`/`longjmp`. Classes compile to C structs with associated functions.
For the full deep-dive, see the [Architecture Guide](docs/ARCHITECTURE.md).
## π Project Structure
```
sauravcode/
βββ saurav.py # Interpreter + interactive REPL
βββ sauravcc.py # Compiler (.srv β C β native)
βββ sauravast.py # AST visualizer (tree, JSON, DOT, stats)
βββ sauravbench.py # Benchmark runner (fib, sort, recursion, etc.)
βββ sauravcov.py # Code coverage analysis
βββ sauravdb.py # Interactive debugger
βββ sauravdiff.py # Semantic diff between .srv files
βββ sauravdoc.py # Documentation generator
βββ sauravfmt.py # Code formatter
βββ sauravlint.py # Linter (style, complexity, bugs)
βββ sauravplay.py # Interactive playground
βββ sauravprof.py # Execution profiler
βββ sauravcomplex.py # Cyclomatic complexity analyzer
βββ sauravdeps.py # Import dependency graph
βββ sauravnb.py # Jupyter-style notebook runner
βββ sauravrepl.py # Enhanced REPL with history
βββ sauravsnap.py # Snapshot testing
βββ sauravwatch.py # File watcher (live reload)
βββ sauravcanvas.py # Turtle graphics (SVG/HTML output)
βββ tests/ # 2,300+ pytest tests (40 test modules)
βββ editors/
β βββ vscode/ # VS Code extension (syntax, snippets)
βββ docs/
β βββ LANGUAGE.md # Language reference & EBNF grammar
β βββ ARCHITECTURE.md # Compiler/interpreter internals
β βββ EXAMPLES.md # Annotated examples
βββ site/
β βββ index.html # Documentation website
βββ .github/
β βββ workflows/ # CI/CD (CodeQL, Pages)
βββ STDLIB.md # Standard library reference (95 functions)
βββ CHANGELOG.md # Version history
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # MIT License
```
## π§ͺ Running Tests
Run the comprehensive test suite:
```bash
# Full test suite (interpreter + compiler + REPL)
python -m pytest tests/ -v
# Run .srv test files directly
python saurav.py test_all.srv
# Compiler
python sauravcc.py test_all.srv
```
## π Language Comparison
See how sauravcode compares to other languages for common tasks:
| Task | sauravcode | Python | JavaScript |
|------|-----------|--------|------------|
| Print | `print "hello"` | `print("hello")` | `console.log("hello")` |
| Function | `function add a b`
` return a + b` | `def add(a, b):`
` return a + b` | `function add(a, b) {`
` return a + b; }` |
| Call | `add 3 5` | `add(3, 5)` | `add(3, 5)` |
| For loop | `for i 1 6`
` print i` | `for i in range(1, 6):`
` print(i)` | `for (let i=1; i<6; i++)`
` console.log(i)` |
| Lambda | `lambda x -> x * 2` | `lambda x: x * 2` | `x => x * 2` |
| Pipe | `"hi" \|> upper \|> reverse` | N/A (nested calls) | N/A (method chaining) |
| F-string | `f"Hi {name}"` | `f"Hi {name}"` | `` `Hi ${name}` `` |
| List comp | `[x * 2 for x in range 1 6]` | `[x*2 for x in range(1,6)]` | `[...Array(5)].map((_,i)=>(i+1)*2)` |
**Key differences:** No parentheses for calls, no commas between arguments, no semicolons, no braces. Indentation defines blocks (like Python), but function calls are cleaner.
## π― Design Philosophy
> Code should read like thought. No ceremony, no noise β just logic.
Traditional languages carry decades of syntactic baggage. Sauravcode asks: *what if we kept only what matters?*
- **Function calls without parentheses** β `add 3 5` instead of `add(3, 5)`
- **Indentation-based blocks** β no `{}` or `end` keywords
- **Minimal punctuation** β colons, semicolons, and most commas are gone
- **Disambiguation when needed** β parentheses are available for complex expressions
The result is code that reads almost like pseudocode but actually runs.
## π Documentation
| Document | Description |
|----------|-------------|
| [Standard Library](STDLIB.md) | All 95 built-in functions with signatures and examples |
| [Language Reference](docs/LANGUAGE.md) | Complete spec with EBNF grammar, types, operators, precedence |
| [Architecture Guide](docs/ARCHITECTURE.md) | How the tokenizer, parser, interpreter, and compiler work |
| [Examples](docs/EXAMPLES.md) | Annotated programs covering all features |
| [Changelog](CHANGELOG.md) | Version history and notable changes |
| [Website](https://sauravbhattacharya001.github.io/sauravcode/) | Interactive documentation |
| [Home Page](https://sites.google.com/view/sauravcode) | Project home |
## βοΈ Editor Support
### Visual Studio Code
Full syntax highlighting, 25 code snippets, and language configuration for VS Code.
**Quick install:**
```bash
# Symlink the extension (Windows)
mklink /D "%USERPROFILE%\.vscode\extensions\sauravcode" "path\to\sauravcode\editors\vscode"
# Symlink the extension (macOS / Linux)
ln -s path/to/sauravcode/editors/vscode ~/.vscode/extensions/sauravcode
```
See [`editors/vscode/README.md`](editors/vscode/README.md) for full details.
## π€ Contributing
Contributions are welcome! Here's how to get started:
1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/my-feature`)
3. **Make** your changes with tests
4. **Test** with both interpreter and compiler
5. **Submit** a pull request
### Ideas for Contributions
- Additional data structures (sets, tuples)
- Compiler support for maps, f-strings, generators, and pattern matching
- Editor support for more editors (Sublime Text, Vim, Emacs, JetBrains)
- Optimization passes in the compiler
- Async/concurrent execution
- Package manager for .srv modules
## π License
This project is licensed under the [MIT License](LICENSE).
## π€ Author
**Saurav Bhattacharya** β [GitHub](https://github.com/sauravbhattacharya001)