Skip to content

An interactive, web-based visualizer for classic operating system CPU scheduling algorithms like FCFS and SJF, built with Python and React

License

Notifications You must be signed in to change notification settings

Siva-PythonPirates/polygot-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ The Polyglot Interpreter Project

โšก A revolutionary cross-language development environment that seamlessly executes C, Python, and Java code in a single pipeline with automatic variable sharing, nested language blocks, and intelligent cross-language conversion.

This isn't just another code runner โ€” it's a paradigm shift. What started as a proof-of-concept evolved into an intelligent orchestrator that breaks down language barriers, enabling developers to leverage the best features of each language in a unified workflow.

๐Ÿ—๏ธ Architecture 2.0: SharedStateOrchestrator

Major architectural breakthrough: We've completely rewritten the execution engine with a clean, maintainable OOP design that makes the system incredibly robust and extensible.

What's New:

  • ๐ŸŽฏ Centralized State Management: Single global state dictionary for all cross-language variables
  • ๐Ÿ”„ Placeholder-Based Processing: Elegant nested block handling without complex position tracking
  • ๐Ÿ“ฆ Modular Design: Clear separation of concerns across specialized methods
  • ๐Ÿ›ก๏ธ Type Safety: Full TypeScript-style type hints throughout the codebase
  • ๐Ÿ”ง Enhanced Maintainability: Easy to understand, modify, and extend

The new SharedStateOrchestrator class replaces the previous 900+ line monolithic approach with clean, testable methods while preserving 100% backward compatibility.

๐ŸŒ Live Demo | ๐Ÿ“š GitHub Repo


โœจ Revolutionary Features

๐Ÿ”„ Sequential Multi-Language Execution

Write C, Python, and Java code in sequence with automatic variable sharing - no manual JSON handling required!

::c
int nums[] = {50, 25, 75, 100, 10};
float pi = 3.14f;
char name[] = "Polyglot";
::/c

::py
# Variables from C are automatically available!
nums.sort()
pi_doubled = pi * 2
message = f"Hello from {name}! Pi doubled = {pi_doubled}"
::/py

::java
// All variables seamlessly passed to Java
System.out.println("Sorted numbers: " + Arrays.toString(nums));
System.out.println("Message: " + message);
::/java

๐ŸŽฏ Revolutionary Nested Language Blocks

World's first nested language execution with two powerful modes:

๐Ÿ”„ Loop-Based Nested Execution

Embed multiple languages inside C loops with automatic iteration:

::py
results = []
::/py

::c
int numbers[] = {1, 2, 3, 4, 5};
for(int i = 0; i < 5; i++) {
    ::py 
    print(f"Processing number {numbers[i]}")
    results.append(numbers[i] ** 2)
    ::/py
    
    ::java 
    System.out.println("Java says: " + numbers[i] + " squared!");
    ::/java
}
::/c

::py
print("Final results:", results)
::/py

โšก Simple Nested Execution

Cross-language variable sharing within single blocks:

::c
int a = 5;
int b = 10;

::py
result = a * b * 2
print("Python calculated:", result)
::/py

printf("C result: %d\n", a + b + result);
::/c

โœจ Magic Features:

  • Automatic variable extraction: C variables (a, b) automatically available in Python
  • Bidirectional communication: Python results (result) automatically available in C
  • Cross-language type conversion: Seamless int, float, string, array conversions
  • Real-time execution: WebSocket streaming shows each step

๐ŸŽ›๏ธ Smart Debug Mode Toggle

Perfect for both development and production use:

  • ๐Ÿ” Debug ON: Detailed execution pipeline, variable tracking, state transitions
  • โœจ Debug OFF: Clean output showing only your program results

๐ŸŒ Professional Web Interface

  • ๐Ÿ–ฅ๏ธ Live code editor with multi-language syntax highlighting
  • โšก Real-time WebSocket execution for instant feedback
  • ๐Ÿ“ File upload/download for .poly files
  • ๐Ÿ“ฑ Responsive design that works everywhere
  • ๐ŸŽจ Dark theme optimized for coding

๐Ÿ—๏ธ Intelligent Variable Management

  • ๐Ÿ” Static analysis detects variable declarations and modifications
  • ๐Ÿ”„ Automatic type conversion between languages (int[], List, int[])
  • ๐Ÿ“Š Cross-language data structures (arrays, strings, objects)
  • ๐ŸŽฏ Smart variable injection eliminates manual JSON handling

๐ŸŽฏ Advanced Examples

Complex Data Processing Pipeline

::c
int sales_data[] = {150, 200, 175, 300, 250};
char region[] = "North America";
float tax_rate = 0.08f;
::/c

::py
import statistics
total_sales = sum(sales_data)
avg_sales = statistics.mean(sales_data)
tax_amount = total_sales * tax_rate
report = {
    "region": region,
    "total": total_sales,
    "average": round(avg_sales, 2),
    "tax_due": round(tax_amount, 2)
}
::/py

::java
System.out.println("=== SALES ANALYSIS REPORT ===");
System.out.println("Region: " + report.get("region"));
System.out.println("Total Sales: $" + report.get("total"));
System.out.println("Tax Due: $" + report.get("tax_due"));
::/java

Nested Language Loops

::c
int matrix[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
printf("Processing matrix:\n");
for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
        printf("Element [%d][%d] = ", i, j);
        ::py print(matrix[i][j] ** 2) ::/py
        printf(" ");
    }
    printf("\n");
}
::/c

๐Ÿ› ๏ธ Tech Stack & Architecture

Backend (Python)

  • FastAPI - High-performance async API framework
  • Docker - Containerized execution environments for each language
  • WebSockets - Real-time bidirectional communication
  • Advanced AST parsing - Intelligent variable detection and injection

Frontend (React)

  • Vite - Lightning-fast build tool and dev server
  • Zustand - Lightweight state management
  • React Simple Code Editor - Syntax-highlighted code editing
  • Prism.js - Multi-language syntax highlighting

Infrastructure

  • Vercel - Frontend deployment with auto-deployment from Git
  • GitHub Codespaces - Backend hosting with Docker support
  • Cross-origin configured - Seamless production communication

๐Ÿš€ Getting Started

๐ŸŽฎ Try it Online (Recommended)

Visit https://polygot-interpreter-zcom.vercel.app/ and start coding immediately!

๐Ÿ’ป Local Development Setup

Prerequisites

  • Docker Desktop (running)
  • Node.js (v18+)
  • Python (v3.8+)
  • Git

Quick Start

# Clone the repository
git clone https://github.com/Siva-PythonPirates/polygot-interpreter.git
cd polygot-interpreter

# Backend setup
cd backend
pip install -r requirements.txt
python server.py

# Frontend setup (new terminal)
cd frontend
npm install
npm run dev

๐ŸŒ Open http://localhost:5173 to start coding!


๐Ÿš€ Production Deployment

Frontend (Vercel)

  1. Fork the repository
  2. Connect to Vercel
  3. Set environment variable: VITE_BACKEND_URL=your-backend-url
  4. Deploy automatically on push to main

Backend (GitHub Codespaces)

  1. Open repository in Codespaces
  2. Run: cd backend && python server.py
  3. Copy the Codespaces URL for frontend configuration

๐Ÿงช Testing & Development

Test Suite Organization

All test files are organized in backend/tests/ for a clean workspace:

backend/tests/
โ”œโ”€โ”€ test_nested_debug.py          # Your simple nested code tests
โ”œโ”€โ”€ test_websocket_nested.py      # WebSocket integration tests  
โ”œโ”€โ”€ test_your_websocket.py        # Custom nested execution tests
โ”œโ”€โ”€ test_enhanced_nested.py       # Advanced nested features
โ”œโ”€โ”€ test_debug_toggle.py          # Debug mode functionality
โ””โ”€โ”€ ... (30+ comprehensive tests)

Run Tests

cd backend

# Test simple nested execution
python tests/test_nested_debug.py

# Test WebSocket integration  
python tests/test_websocket_nested.py

# Test your custom code
python tests/test_your_websocket.py

Expected Output

Simple Nested Execution:

=== Testing NESTED with DEBUG_MODE = True ===
๐Ÿ”„ No loop found - executing simple nested blocks
๐Ÿ”„ Extracted C variables: {'a': 5, 'b': 10}
Python calculated: 100
C result: 115

=== Testing NESTED with DEBUG_MODE = False ===
Python calculated: 100
C result: 115

๐Ÿ“Š What Makes This Special?

๐ŸŒŸ Innovation Highlights

  • ๐ŸŽฏ Dual nested execution modes - Loop-based iteration + simple cross-language blocks
  • โšก Zero boilerplate - Automatic variable extraction and injection
  • ๐Ÿ”„ Bidirectional communication - Variables flow seamlessly between languages
  • ๐ŸŒ Production-ready - Full Vercel + Codespaces deployment pipeline
  • ๐ŸŽ›๏ธ Professional developer experience - Debug toggle, WebSocket streaming, clean UI
  • ๐Ÿ“ฑ Cross-platform - Works in any browser, no local setup required
  • ๐Ÿงช Comprehensive testing - 30+ test cases covering all execution modes

๐Ÿ”ฌ Technical Achievements

  • ๐Ÿง  Advanced nested block parsing - Detects loop vs simple nested structures
  • ๐Ÿ”„ Smart variable extraction - C int declarations automatically parsed and injected
  • โšก Bidirectional state management - Python results automatically available in C
  • ๐ŸŒŠ Real-time WebSocket streaming - Live execution feedback with debug toggle
  • ๐Ÿณ Secure Docker execution - Isolated containers for each language
  • ๐ŸŽจ Professional UI/UX - Syntax highlighting, file upload, responsive design
  • ๐Ÿงช Comprehensive test suite - 30+ test cases in organized structure

๐Ÿ—๏ธ SharedStateOrchestrator Architecture

The heart of the system is the new SharedStateOrchestrator class that provides:

class SharedStateOrchestrator:
    def __init__(self):
        self.global_state = {}  # Centralized variable storage
        self.language_contexts = {}  # Language-specific contexts
    
    def parse_mixed_structure(code_str) -> List[Dict]  # Smart parsing
    def execute_blocks(blocks) -> None                  # Unified execution
    def extract_variable_references(code, lang) -> set  # Variable analysis
    def inject_variable_declarations(lang, vars) -> str # Code generation

Key Benefits:

  • ๐ŸŽฏ Single Source of Truth: All variables managed in global_state
  • ๐Ÿ”„ Smart Parsing: Handles sequential, nested, and mixed structures
  • ๐Ÿ›ก๏ธ Type Safety: Full typing support for better development experience
  • ๐Ÿ“ฆ Modular Methods: Each concern handled by specialized methods
  • ๐Ÿ”ง Easy Extension: Adding new languages is straightforward

๐ŸŽฏ Use Cases

  • Algorithm prototyping - leverage each language's strengths
  • Educational tool - learn multiple languages simultaneously
  • Cross-language integration - bridge existing codebases
  • Performance comparison - implement same logic in different languages
  • Polyglot development - unified workflow for multi-language projects

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  • ๐Ÿ› Bug reports - Found an issue? Let us know!
  • ๐Ÿ’ก Feature requests - Have ideas? We'd love to hear them!
  • ๐Ÿ”ง Pull requests - Code improvements are always welcome!
  • ๐Ÿ“– Documentation - Help improve our docs!

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Free to use, modify, and distribute. Build something awesome! ๐Ÿš€


๐Ÿ™ Acknowledgments

  • Docker - For containerization technology
  • FastAPI - For the excellent async Python framework
  • React ecosystem - For powerful frontend tooling
  • Prism.js - For beautiful syntax highlighting
  • Vercel & GitHub - For seamless deployment platforms

Built with โค๏ธ by Siva-PythonPirates

"Breaking down language barriers, one line of code at a time." ๐ŸŒŸ

About

An interactive, web-based visualizer for classic operating system CPU scheduling algorithms like FCFS and SJF, built with Python and React

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published