HappyScript

A simple, educational programming language implemented in C++. It supports variables, operators, control flow, and print statements — making it great for learning interpreters and language design.

Variables

Supports integers, floats, and strings with simple declarations.

Operators

Arithmetic: +, -, *, /, %
Comparison: ==, !=, <, >, <=, >=

Control Flow

ana = if, elsa = else, fun = while.

Printing

Output values using smile().

Blocks

Group statements with { ... } for structured logic.

Educational

Designed to be readable and extendable — perfect for learning.

Installation

1. Manual Build

git clone https://github.com/Matei-thecoder/happyscript.git
cd happyscript
g++ -std=c++17 -o happyscript main.cpp lexer.cpp parser.cpp interpreter.cpp

2. Or using CMake - make sure you have CMake installed

git clone https://github.com/Matei-thecoder/happyscript.git
cd happyscript
mkdir build
cd build
cmake ..
make

Usage

Write your Happyscript code in a file, in the same directory with the happyscript executable, e.g. test.happy:

int x = 5;
fun (x > 0) {
    smile(x);
    x = x - 1;
}

Run the interpreter:

./happyscript test.happy

This will execute your Happyscript program and print the output.

Example - code snippet

int x = 10;
float y = 2.0;
string z = "Hello ";
string h = "World!";
fun (x >= 0) {
    ana (x % 2 == 0) {
        smile(x+y);
    } elsa {
        smile(z+h);
    }
    x = x - 1;
}

Language Rules

Statement Termination

Every statement in Happyscript must end with a semicolon (;). This ensures clarity and consistency in parsing and avoids ambiguity for the interpreter.

Supported Types

Happyscript supports three main types: int for integers, float for decimal numbers, and string for sequences of characters. Choose the type according to the data you want to store.

String Concatenation

You can concatenate only two strings at a time using the + operator. For example, "hello" + "world" works, but combining a string with a number like "hello" + 1 is invalid. This keeps the language simple and type-safe.

Type Safety

Happyscript enforces strict type safety: you cannot add or concatenate numbers with strings. For example, 5 + "hello" is invalid. This helps beginners learn proper type usage and avoids runtime errors.

Keyword Fun & Anecdote

In Happyscript, traditional programming keywords have been replaced as a playful twist:

  • ifana
  • elseelsa
  • whilefun
  • printsmile

The choices are intentional: fun and smile reflect the "Happy" theme of the language name. ana and elsa were chosen as an inside joke with a friend when I started coding. This adds a bit of personality and makes learning more fun!