A from-scratch compiler IDE for the MiniLang programming language (.mlg) — a custom-designed language with its own hand-written scanner, recursive predictive parser, and tree-walk interpreter. Built entirely with Python & tkinter, zero external dependencies.
| Feature | Description |
|---|---|
| Lexer | Hand-written state-machine scanner, no re module |
| Parser | Recursive Predictive Parser (LL(1)) |
| Parse Tree | TreeView text tree + Canvas graphical drawing |
| Interpreter | Tree-walk executor with real input() dialogs |
| IDE | Modern dark GUI with syntax highlighting |
- Python 3.8+
tkinter(included with standard Python on Windows & Linux)
python minilang_compiler.pyNo pip installs needed — zero external dependencies.
MiniLang-Compiler/
├── minilang_compiler.py ← main file (run this)
├── MiniLang_Spec.md ← full language specification
├── examples/
│ ├── hello.mlg ← hello world
│ ├── loops.mlg ← for loop examples
│ └── comparisons.mlg ← comparison operators
└── README.md
// variables
x = 42
pi = 3.14
msg = "hello"
// if / else
IF (x > 0) :
{
print(x)
}
else
{
print(msg)
}
// for loop
for (i = 0 , i < 10 , i++)
{
x = x + 1
}
// method
method add(a, b) :
{
c = a + b
}
// print & input
print(x)
input(y)
Recognizes all tokens using explicit state machines:
| State Machine | Tokens Produced |
|---|---|
| Whitespace (states 22–24) | skipped |
| Identifier / Keyword (states 9–11) | ID, KW |
| Unsigned Numbers (states 12–21) | INTEGER, FLOAT, SCIENTIFIC |
| String literal (S0–S2) | STRING |
| Relational Operators (R0–R8) | EQ NEQ LT GT LEQ GEQ |
| Arithmetic & symbols | PLUS STAR ASSIGN PLUSPLUS … |
Output → Lexical Table: Token | Type | Line | Col
Grammar is LL(1) — no left recursion, no backtracking. Each non-terminal maps to exactly one function:
Program → Statement*
Statement → Assignment | IfStatement | ForLoop | ...
Expression → ArithExpr [ relop ArithExpr ]
ArithExpr → Term { + Term }
Term → Factor { * Factor }
Factor → INTEGER | FLOAT | SCIENTIFIC | STRING | ID
Output → Parse Tree (TreeView) + Visual Canvas Tree
- Syntax Highlighting — debounced (250 ms), never freezes
- Line Numbers gutter
- File Operations — New / Open / Save / Save As (
.mlgfilter) - Keyboard Shortcuts —
F5Compile ·F6Run ·Ctrl+SSave ·Ctrl+HFind & Replace ·Ctrl+Z/YUndo/Redo - Error Highlighting — first error line turns red in editor
- Visual Parse Tree — colour-coded Canvas drawing with scroll
- Interpreter — executes the AST, real
input()popup dialog
| Token | Example | Colour |
|---|---|---|
| Keyword | IF for print |
Violet |
| Integer | 42 |
Orange |
| Float | 3.14 |
Orange |
| Scientific | 1.5E+10 |
Orange |
| String | "hello" |
Green |
| Comparison | == != < <= > >= |
Pink |
| Operator | + * = ++ |
Cyan |
MIT — free to use and modify.