Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Compiler Assistant

A browser-based IDE for a custom programming language - featuring a full compiler pipeline (Lexer → Parser → AST → Evaluator) with an AI-powered error correction and auto-fix engine.

Language Backend Frontend AI


What is this?

Most compilers just throw a cryptic error and leave you alone. This one doesn't.

AI Compiler Assistant is a fully functional browser-based IDE where you write code in a custom programming language. When your code compiles successfully, you see the output instantly. When it fails, an AI assistant takes over - analyzing the error, explaining what went wrong in plain language, suggesting a fix, and giving you corrected code you can apply with a single click.

Built as a team project. Entire compiler pipeline written from scratch in Python.


Demo

Write code → Run → See output or get AI-corrected code instantly

integer a = 10;
integer b = 20;
a = a + b;
print(a);

Output:

30

If you write broken code:

integer a = 10
print(a)        ← missing semicolons

The AI assistant returns:

  • Errors - exactly which lines failed and why
  • Explanation - plain language description of the issue
  • Fix - what you need to change
  • Optimization - any improvements beyond the fix
  • Corrected Code - ready to use, one click to apply

Architecture

User Code (CodeMirror Editor)
        │
        ▼
┌───────────────┐
│     Lexer     │  Tokenizes raw source code into typed tokens
└───────┬───────┘
        │
        ▼
┌───────────────┐
│    Parser     │  Recursive descent parser — builds an Abstract Syntax Tree (AST)
└───────┬───────┘
        │
        ▼
┌───────────────┐
│   Evaluator   │  Walks the AST, executes statements, maintains symbol table
└───────┬───────┘
        │
   ┌────┴────┐
   │         │
SUCCESS    FAILURE
   │         │
   ▼         ▼
Output   AI Assistant
console  (Online LLM → Offline fallback)
         Returns: Errors, Explanation,
         Fix, Optimization, Corrected Code

Language Grammar

The compiler supports a custom DSL with the following formal grammar:

PROGRAM      → STMT_LIST EOF
STMT_LIST    → (STMT)*
STMT         → DECL | ASSIGN | PRINT_STMT
DECL         → "integer" ID "=" EXPR ";"
ASSIGN       → ID "=" EXPR ";"
PRINT_STMT   → "print" "(" EXPR ")" ";"
EXPR         → TERM { ("+" | "-") TERM }
TERM         → FACTOR { ("*" | "/") FACTOR }
FACTOR       → NUMBER | STRING | ID | "(" EXPR ")"
NUMBER       → DIGIT+
STRING       → '"' CHAR* '"'
ID           → LETTER (LETTER | DIGIT | "_")*

Supported operations:

  • Variable declaration with integer
  • Arithmetic: +, -, *, /
  • Grouped expressions with parentheses
  • String literals
  • print() statements

Features

Feature Description
Full compiler pipeline Lexer → Parser → AST → Evaluator, built from scratch
AI error correction On compile failure, LLM returns structured fix + corrected code
Online + offline fallback Uses online LLM when available, falls back to offline assistant automatically
One-click auto-replace Apply corrected code directly into the editor with a single button
CodeMirror editor Syntax-highlighted editor with Dracula theme
Live output console See program output in real time
Copy to clipboard Copy corrected code instantly
Symbol table inspection Final variable state displayed after successful execution

Tech Stack

Layer Technology
Backend Python
Compiler modules Custom Lexer, Parser, Evaluator (pure Python, no compiler libraries)
AI integration Online LLM API + Offline fallback assistant
Frontend HTML, CSS, JavaScript
Code editor CodeMirror (Dracula theme)
Server Python HTTP server (compiler_server.py)

Project Structure

AI-Compiler-Assisstant/
├── Compiler/
│   ├── Lexer.py            # Tokenizer — converts source to token stream
│   ├── Parser.py           # Recursive descent parser — builds AST
│   ├── Evaluator.py        # AST walker — executes the program
│   ├── OnlineAssistant.py  # LLM-powered error correction (online)
│   └── OfflineAssistant.py # Fallback error assistant (offline)
├── WebPage/
│   ├── compiler_server.py  # Python HTTP server — run this to start
│   ├── index.html          # Browser IDE frontend
│   ├── style.css           # Styling
│   └── script.js           # Editor logic + API calls
├── main.py                 # Core orchestration: run() + fallback logic
├── requirements.txt        # Python dependencies
└── README.md

How to Run

1. Clone the repository

git clone https://github.com/manishkrmahato/AI-Compiler-Assisstant.git
cd AI-Compiler-Assisstant

2. Install dependencies

pip install -r requirements.txt

3. Start the server

cd WebPage
python compiler_server.py

4. Open in browser

http://localhost:8000

Write code in the editor, click Run. That's it.


Example Programs

Arithmetic

integer x = 5;
integer y = 3;
integer z = x * y + 2;
print(z);

Output: 17

String print

print("Hello, World!");

Output: Hello, World!

Variable reassignment

integer a = 100;
a = a / 4;
print(a);

Output: 25


How the AI Fallback Works

When the compiler's Evaluator raises an exception, main.py catches it and calls run_compiler_from_code(). This sends the broken code to the AI assistant with a structured system prompt that includes the full language grammar.

The AI returns a response in five structured sections:

  1. Errors - exact lines and what failed
  2. Explanation - plain language description
  3. Fix - minimal change needed
  4. Optimization - suggestions beyond correctness
  5. Corrected Code - clean, runnable version

If the online LLM is unavailable, the system automatically falls back to the offline assistant - ensuring the IDE never leaves the user without feedback.


Contributors

Built as a collaborative team project at NIT Warangal.

Contributor GitHub
Manish Kumar Mahato @manishkrmahato
Pranav Umbarkar @PranavUmbarkar06
Mistry Ritik @kai11017

About

Browser-based IDE for a custom DSL - full compiler pipeline (Lexer → Parser → AST → Evaluator) with AI-powered error correction, auto-fix, and CodeMirror editor. Python + HTML/JS.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages