RL-Optimized Source-to-Source Compiler

Note: The initial compilation may take a few seconds on first visit due to cold start latency in Render's free deployment tier.

Source Code

Input Data

Enter input values here, one per line

Compilation Pipeline

1

Lexical Analysis

Breaks down source code into individual tokens (keywords, operators, identifiers, etc.)

Run compilation to see tokens...
2

Abstract Syntax Tree

Builds a tree structure representing the grammatical structure of the program

Run compilation to see AST...
3

Semantic Analysis

Checks for semantic errors like undefined variables and type mismatches

Run compilation to see semantic analysis...
4

Intermediate Code

Generates three-address code as an intermediate representation

Run compilation to see intermediate code...
5

RL-Based Optimization

Uses reinforcement learning to optimize code through constant folding, dead code elimination, etc.

Run compilation to see optimization log...
Optimized code will appear here...
6

Python Code Generation

Translates optimized intermediate code into executable Python

Run compilation to see generated Python code...
7

Execution Results

Secure execution of the generated Python code with captured output

Execution time: --
Status: Ready

Output

Run compilation to see output...

Errors


                                

Language Overview

This custom programming language is designed to demonstrate the core phases of compilation through a simple and readable syntax. It is translated into Python using a structured pipeline that includes tokenization, syntax analysis, semantic validation, intermediate code generation, and optimization. The language serves as an educational tool to explore how compilers work end-to-end, focusing on clarity, transformation accuracy, and performance-aware code generation.

Variables and Assignment

Basic Assignment

x = 10;
name = "John";
print(x);
print(name);

Output:

10
John

Compound Assignment

x = 5;
x += 3;  // x = x + 3
print(x);

Output:

8

Arithmetic Operations

a = 10;
b = 3;
print(a + b);
print(a - b);
print(a * b);
print(a / b);

Output:

13
7
30
3.3333333333333335

Control Flow

If Statements

age = 20;
if (age >= 18) {
    print("Adult");
} else {
    print("Minor");
}

Output:

Adult

While Loops

counter = 1;
while (counter <= 3) {
    print(counter);
    counter += 1;
}

Output:

1
2
3

Input and Output

print("Enter name:");
scan(name);
print("Hello");
print(name);

Output (with input "Alice"):

Enter name:
Hello
Alice

Operators

Arithmetic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division

Comparison Operators

  • > Greater than
  • < Less than
  • >= Greater than or equal
  • <= Less than or equal
  • == Equal to
  • != Not equal to

Logical Operators

  • && Logical AND
  • || Logical OR
  • ! Logical NOT

Assignment Operators

  • = Assign
  • += Add and assign
  • -= Subtract and assign

Compiler Features

  • Lexical Analysis: Tokenizes source code into meaningful symbols
  • Syntax Analysis: Builds Abstract Syntax Tree (AST) from tokens
  • Semantic Analysis: Checks for semantic errors and variable usage
  • Intermediate Code Generation: Creates three-address code representation
  • RL Optimization: Uses reinforcement learning for code optimization
  • Code Generation: Translates to executable Python code
  • Secure Execution: Runs generated code in a safe environment