Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

⬡ MiniLang Compiler IDE

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.

Python Lexer Parser Tree License


📸 Features at a Glance

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

🚀 Getting Started

Requirements

  • Python 3.8+
  • tkinter (included with standard Python on Windows & Linux)

Run

python minilang_compiler.py

No pip installs needed — zero external dependencies.


🗂️ Project Structure

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

📝 MiniLang Quick Syntax

// 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)

⚙️ How It Works

Lexer / Scanner

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

Recursive Predictive Parser

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


🎨 IDE Features

  • Syntax Highlighting — debounced (250 ms), never freezes
  • Line Numbers gutter
  • File Operations — New / Open / Save / Save As (.mlg filter)
  • Keyboard ShortcutsF5 Compile · F6 Run · Ctrl+S Save · Ctrl+H Find & Replace · Ctrl+Z/Y Undo/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 Reference

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

📄 License

MIT — free to use and modify.

About

A from-scratch compiler IDE for MiniLang (.mlg) — hand-written Lexer, Recursive Predictive Parser, Visual Parse Tree & tree-walk Interpreter. Built entirely with Python & tkinter, zero external dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages