Skip to content

salahuddinmania/EasyLang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyLang Compiler Lab

A complete, web-based educational IDE for the simple, English-like programming language, EasyLang. This project provides a hands-on environment to understand and visualize the core principles of compilers and interpreters.


✨ Features

  • Dual Execution Modes: Instantly switch between an Interpreter (executes code directly) and a Compiler (translates to Python first).
  • Live Code Editor: A professional-grade editor powered by CodeMirror with custom EasyLang syntax highlighting, line numbers, and active line styling.
  • Transparent Process: The "Process Log" gives a step-by-step view of the compiler's work, showing timings for lexing, parsing, and execution.
  • Beginner-Friendly Language: EasyLang is designed to be readable and intuitive, allowing students to focus on programming logic rather than complex syntax.
  • Rich UI Experience: Features a modern design, a vibrant logo, dark/light themes, and font size controls for a polished and accessible user experience.
  • Well-Structured Codebase: The project is organized professionally with separate modules for the lexer, parser, AST, interpreter, and compiler, making it easy to study and extend.
  • Zero-Installation: As a web application, it requires no setup for the end-user. Anyone with a web browser can start learning immediately.

🚀 Setup and Installation

Follow these steps to run the EasyLang Compiler Lab on your local machine.

Prerequisites

  • Python 3.8 or newer
  • pip (Python's package installer)

Step-by-Step Instructions

  1. Clone or Download the Project

    Download the project files and unzip them into a directory of your choice.

  2. Navigate to the Project Directory

    Open your terminal or command prompt and change to the project's root directory.

    cd path/to/your/EasyLang
  3. Create a Virtual Environment (Recommended)

    This creates an isolated environment for the project's dependencies.

    # For Windows
    python -m venv venv
    venv\Scripts\activate
    
    # For macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
  4. Install Dependencies

    Install the required packages using the requirements.txt file.

    pip install -r requirements.txt
  5. Run the Application

    Start the Flask development server.

    python compiler_app.py
  6. Open in Browser

    Once the server is running, open your web browser and go to the following address:

    http://127.0.0.1:5000

You should now see the EasyLang Compiler Lab interface and can start coding!


🛠️ How It Works: The Compiler Pipeline

The application follows a classic compiler architecture. When you click "Compile" or "Interpret", your EasyLang code goes through the following stages:

  1. Lexical Analysis (Lexing)

    • Component: compiler/lexer.py
    • Job: The raw code string is scanned and broken down into a sequence of tokens (e.g., KEYWORD, IDENTIFIER, NUMBER). Comments and whitespace are discarded.
  2. Syntax Analysis (Parsing)

    • Component: compiler/parser.py
    • Job: The stream of tokens is organized into a hierarchical structure called an Abstract Syntax Tree (AST) based on the rules of the EasyLang grammar. This tree represents the logical structure of the program.
  3. Execution (Interpretation or Compilation) The AST is then passed to one of two backends:

    • The Interpreter (compiler/interpreter.py)

      • Method: Tree Walking.
      • Process: It recursively "walks" the AST, evaluating each node directly. For example, when it sees a BinaryOp node for addition, it evaluates the children, performs the addition, and holds the result.
    • The Compiler (compiler/compiler.py)

      • Method: Source-to-Source Translation.
      • Process: It walks the AST and generates equivalent source code in a target language (in this case, Python). For example, an EasyLang if-then-else block is translated into a Python if-else block. The resulting Python script is then executed in a safe, separate process.

📂 Project Structure

The project is organized into a clean, modular structure:

/
|-- compiler_app.py         # Main Flask application (routes and server logic)
|-- requirements.txt        # Python package dependencies
|-- README.md               # This documentation file
|
|-- compiler/               # Core compiler components
|   |-- lexer.py
|   |-- parser.py
|   |-- ast.py
|   |-- interpreter.py
|   |-- compiler.py
|
|-- templates/
|   |-- index.html          # The single-page HTML user interface
|
|-- samples/                # Directory for all .ey sample programs
    |-- 01_basics.ey
    |-- ... (and 9 other sample files)

About

An interactive, web-based educational IDE for EasyLang, a simple programming language designed to teach the core concepts of compilers and interpreters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors