MyLang — a statically-typed language that compiles to Python
Project description
MyLang Compiler
A statically-typed programming language that compiles to Python — built from scratch in Python with zero dependencies.
Install
pip install mylang-compiler
Quick Start
Create a file hello.myl:
program HelloWorld
let name: text = "World"
print "Hello, " + name + "!"
endprogram
Compile and run:
mylang hello.myl
Output:
Hello, World!
CLI Flags
mylang hello.myl # compile + run (clean output)
mylang hello.myl --phases # show all 7 compiler phases
mylang hello.myl --show-tokens # Phase 1: token stream
mylang hello.myl --show-ast # Phase 2: Abstract Syntax Tree
mylang hello.myl --show-symbols # Phase 3: symbol table
mylang hello.myl --show-tac # Phase 4: Three Address Code
mylang hello.myl --show-python # Phase 5: generated Python source
mylang hello.myl --compile-only # compile only, don't execute
Bundled Examples
After installing, run any example:
python -c "import os, mylang; print(os.path.dirname(mylang.__file__))"
Copy that path and run:
mylang <path>\examples\01_hello.myl
mylang <path>\examples\02_control_flow.myl --phases
mylang <path>\examples\03_functions.myl
mylang <path>\examples\05_showcase.myl
mylang <path>\examples\new_features.myl
The 7 Compiler Phases
Source (.myl)
│
▼ Phase 1 — Lexical Analysis tokens from raw text
▼ Phase 2 — Syntax Analysis Abstract Syntax Tree
▼ Phase 3 — Semantic Analysis type & scope checking
▼ Phase 4 — Intermediate Rep. Three Address Code
▼ Phase 5 — Code Generation emit Python source
▼ Phase 6 — Optimisation constant folding, dead code
▼ Phase 7 — Execute run via Python runtime
Language Features
| Feature | Syntax |
|---|---|
| Variable | let age: num = 25 |
| Function | fun add(a: num, b: num) as num |
| If / else | if x > 0 then ... else ... endif |
| For loop | for i from 1 to 10 step 1 |
| While | while x > 0 begin ... end |
| Repeat N | repeat 5 times begin ... end |
| Do-while | do ... while cond enddo |
| Switch | switch x begin case 1: ... endswitch |
| Struct | struct Point begin x: num endstruct |
| Pointer | let p: ptr = &x then *p = 10 |
| Type check | type(expression) |
| Debug step | thinkstep expression |
Run Without Installing
python -m mylang hello.myl
Built For
Compiler Design coursework. All 7 phases are in separate, self-contained files under mylang/.
36/36 tests passing across all phases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mylang_compiler-1.0.2.tar.gz.
File metadata
- Download URL: mylang_compiler-1.0.2.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c25ff4adc5d4c8aa0c309ad210dab5414584cdfaa40896a241108320767ccdc
|
|
| MD5 |
a1561fa9e9aa1b3dd475882a0494f0b2
|
|
| BLAKE2b-256 |
c77eccccb63be5d68640891ef9d3e0473435e3c14f9021717e212a628c563b08
|
File details
Details for the file mylang_compiler-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mylang_compiler-1.0.2-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96230e655d50c44216df0b499a56139f166b3be18b8b9d0bf6613b4612bebe29
|
|
| MD5 |
39566e8da73de5347305830ebc7950f1
|
|
| BLAKE2b-256 |
71f7fbe081d4ed71760d48a31c3d88ff2ba70f62ceb3daccf9e432d8da7173ef
|