Introducing RelaxLang: A Beginner-Friendly Programming Language**

In the vast and ever-evolving world of programming languages, creating one from scratch is a feat that blends art, science, and a touch of magic. Today, I am excited to introduce RelaxLang, a simple yet powerful interpreted programming language. Inspired by Robert Nystrom's Crafting Interpreters and the Lox programming language, RelaxLang is designed to be accessible for beginners while being feature-rich for enthusiasts who want to dive deeper into language design and implementation. Why RelaxLang? RelaxLang stems from a vision to provide a lightweight, easy-to-understand programming language that serves as both a learning tool and a practical solution for basic scripting needs. Built with Java and C, it offers: Dynamic Typing: Simplifies coding by inferring variable types at runtime. First-Class Functions: Enables functional programming paradigms by treating functions as first-class citizens. Classes and Inheritance: Introduces object-oriented programming with a straightforward syntax. Built-In Standard Library: Provides out-of-the-box utilities for string manipulation, array operations, and more. Whether you're an aspiring developer eager to learn how programming languages work or a seasoned programmer seeking an educational tool, RelaxLang caters to you. Architecture Key Features of RelaxLang 1. Dynamic Typing In RelaxLang, you don’t need to worry about specifying types for variables. The interpreter takes care of it, allowing you to focus on logic and creativity. var name = "RelaxLang"; // Automatically inferred as String var version = 1.0; // Automatically inferred as Float var isActive = true; // Automatically inferred as Boolean print(name); // Output: RelaxLang print(version); // Output: 1.0 print(isActive); // Output: true 2. First-Class Functions Functions are versatile in RelaxLang. They can be assigned to variables, passed as arguments, and even returned from other functions. fun add(a, b) { return a + b; } var sum = add(5, 3); print(sum); // Output: 8 fun operate(func, x, y) { return func(x, y); } var result = operate(add, 10, 15); print(result); // Output: 25 3. Classes and Inheritance RelaxLang supports object-oriented programming, making it a great tool to understand and implement OOP concepts. class Animal { var name; init(name) { this.name = name; } fun speak() { print(this.name + " makes a sound."); } } class Dog < Animal { fun speak() { print(this.name + " barks."); } } var myDog = Dog("Buddy"); myDog.speak(); // Output: Buddy barks. 4. Control Flow With intuitive if-else statements and loops, you can control the flow of your programs effortlessly. var age = 18; if (age < 18) { print("Minor"); } else { print("Adult"); } for (var i = 0; i < 5; i = i + 1) { print(i); // Output: 0 1 2 3 4 } How to Get Started 1. Prerequisites Ensure you have the following installed: Java JDK 11 or later (Download here) (Optional) Docker for a containerized setup 2. Installation Clone the Repository: git clone https://github.com/Ravikisha/RelaxLang.git cd RelaxLang Compile the Source Code: javac src/*.java 3. Running RelaxLang Using the JAR File: java -jar lox.jar Using Docker: docker pull ravikishan63392/relaxlang:lastest docker run -it ravikishan63392/relaxlang:lastest Example Usage RelaxLang scripts are simple to write and execute. For instance, here’s a script example.rl: fun greet(name) { print("Hello, " + name + "!"); } greet("World"); Run it with: java -jar lox.jar example.rl The Technical Journey RelaxLang’s implementation involves: Lexical Analysis: Breaking down source code into tokens. Parsing: Constructing an Abstract Syntax Tree (AST) from tokens. Interpreting: Executing the AST by traversing it node by node. Developed in Java for platform independence and in C for low-level optimizations, RelaxLang’s design reflects a balance between simplicity and functionality. Resources and Contributions Docker Image: RelaxLang Docker Image GitHub Repository: RelaxLang on GitHub We welcome contributions! Whether it's bug fixes, feature requests, or documentation improvements, your input makes RelaxLang better. Please check out the contributing guidelines in the repository. Final Thoughts RelaxLang is not just a programming language; it’s a journey into the heart of language design. By exploring its features, experimenting with scripts, and diving into its implementation, you can gain insights into how modern programming languages work. Give RelaxLang a try and embark on this exciting adventure. Let’s code, learn, and relax!

Jan 16, 2025 - 20:54
Introducing RelaxLang: A Beginner-Friendly Programming Language**

In the vast and ever-evolving world of programming languages, creating one from scratch is a feat that blends art, science, and a touch of magic. Today, I am excited to introduce RelaxLang, a simple yet powerful interpreted programming language. Inspired by Robert Nystrom's Crafting Interpreters and the Lox programming language, RelaxLang is designed to be accessible for beginners while being feature-rich for enthusiasts who want to dive deeper into language design and implementation.

Why RelaxLang?

RelaxLang stems from a vision to provide a lightweight, easy-to-understand programming language that serves as both a learning tool and a practical solution for basic scripting needs. Built with Java and C, it offers:

  • Dynamic Typing: Simplifies coding by inferring variable types at runtime.
  • First-Class Functions: Enables functional programming paradigms by treating functions as first-class citizens.
  • Classes and Inheritance: Introduces object-oriented programming with a straightforward syntax.
  • Built-In Standard Library: Provides out-of-the-box utilities for string manipulation, array operations, and more.

Whether you're an aspiring developer eager to learn how programming languages work or a seasoned programmer seeking an educational tool, RelaxLang caters to you.

Architecture

RelaxLang Diagram

Key Features of RelaxLang

1. Dynamic Typing

In RelaxLang, you don’t need to worry about specifying types for variables. The interpreter takes care of it, allowing you to focus on logic and creativity.

var name = "RelaxLang";  // Automatically inferred as String
var version = 1.0;       // Automatically inferred as Float
var isActive = true;     // Automatically inferred as Boolean

print(name);            // Output: RelaxLang
print(version);         // Output: 1.0
print(isActive);        // Output: true

2. First-Class Functions

Functions are versatile in RelaxLang. They can be assigned to variables, passed as arguments, and even returned from other functions.

fun add(a, b) {
    return a + b;
}

var sum = add(5, 3);
print(sum);  // Output: 8

fun operate(func, x, y) {
    return func(x, y);
}

var result = operate(add, 10, 15);
print(result);  // Output: 25

3. Classes and Inheritance

RelaxLang supports object-oriented programming, making it a great tool to understand and implement OOP concepts.

class Animal {
    var name;

    init(name) {
        this.name = name;
    }

    fun speak() {
        print(this.name + " makes a sound.");
    }
}

class Dog < Animal {
    fun speak() {
        print(this.name + " barks.");
    }
}

var myDog = Dog("Buddy");
myDog.speak();  // Output: Buddy barks.

4. Control Flow

With intuitive if-else statements and loops, you can control the flow of your programs effortlessly.

var age = 18;

if (age < 18) {
    print("Minor");
} else {
    print("Adult");
}

for (var i = 0; i < 5; i = i + 1) {
    print(i);  // Output: 0 1 2 3 4
}

How to Get Started

1. Prerequisites

Ensure you have the following installed:

  • Java JDK 11 or later (Download here)
  • (Optional) Docker for a containerized setup

2. Installation

Clone the Repository:

git clone https://github.com/Ravikisha/RelaxLang.git
cd RelaxLang

Compile the Source Code:

javac src/*.java

3. Running RelaxLang

Using the JAR File:

java -jar lox.jar

Using Docker:

docker pull ravikishan63392/relaxlang:lastest
docker run -it ravikishan63392/relaxlang:lastest

Example Usage

RelaxLang scripts are simple to write and execute. For instance, here’s a script example.rl:

fun greet(name) {
    print("Hello, " + name + "!");
}

greet("World");

Run it with:

java -jar lox.jar example.rl

The Technical Journey

RelaxLang’s implementation involves:

  1. Lexical Analysis: Breaking down source code into tokens.
  2. Parsing: Constructing an Abstract Syntax Tree (AST) from tokens.
  3. Interpreting: Executing the AST by traversing it node by node.

Developed in Java for platform independence and in C for low-level optimizations, RelaxLang’s design reflects a balance between simplicity and functionality.

Resources and Contributions

Docker Image:

RelaxLang Docker Image

GitHub Repository:

RelaxLang on GitHub

We welcome contributions! Whether it's bug fixes, feature requests, or documentation improvements, your input makes RelaxLang better. Please check out the contributing guidelines in the repository.

Final Thoughts

RelaxLang is not just a programming language; it’s a journey into the heart of language design. By exploring its features, experimenting with scripts, and diving into its implementation, you can gain insights into how modern programming languages work.

Give RelaxLang a try and embark on this exciting adventure. Let’s code, learn, and relax!