Blip Programming Language

A lightweight, interpreted scripting language

Overview

Blip is a simple, interpreted programming language designed for ease of use and flexibility. It supports variables, functions, loops, conditionals, lists, dictionaries, and built-in functions for mathematical, list, file, JSON, and HTTP operations. Blip is ideal for quick scripting tasks, API interactions, and learning programming concepts.

Syntax

Blip uses a straightforward syntax with Python-like semantics. Below are the key elements:

Example syntax:


{debug}
x = 10;

func add(a, b)
    return a + b;
end;

for i in range(1, 5)
    print(i);
end;

if x > 5
    print("x is greater than 5");
else
    print("x is 5 or less");
end;

data = {"key": "value"};
print(data.key);

write_file("test.txt", "Hello, Blip!");
            

Built-in Functions

Blip provides a rich set of built-in functions for various tasks:

For a full list, refer to the interpreter's b dictionary in the source code.

Examples

Fibonacci Sequence


func fib(n)
    if n <= 0
        return 0;
    end;
    if n == 1
        return 1;
    end;
    a = 0;
    b = 1;
    for i in range(2, n + 1)
        temp = a + b;
        a = b;
        b = temp;
    end;
    return b;
end;

print(fib(10));
                

Factorial Calculation


func factorial(n)
    if n <= 1
        return 1;
    end;
    return n * factorial(n - 1);
end;

print(factorial(5));
                

List Operations


numbers = [1, 2, 3];
append(numbers, 4);
print(numbers);
print(numbers[2]);
print(numbers.length);
                

HTTP Requests and Dictionaries


response = get("https://jsonplaceholder.typicode.com/todos/1");
print(response.status);
print(response.json);
data = {"title": "foo", "body": "bar", "userId": 1};
response = post("https://jsonplaceholder.typicode.com/posts", data);
print(response.status);
print(response.json);
                

File Operations


write_file("test.txt", "Hello, Blip!");
content = read_file("test.txt");
print(content);
append_file("test.txt", "\nMore text.");
print(file_exists("test.txt"));
print(file_size("test.txt"));
                

JSON Operations


data = {"name": "Blip", "version": 1.0};
write_json("config.json", data);
parsed = read_json("config.json");
print(parsed.name);
json_str = json_stringify(data);
print(json_str);
                

Known Errors

Below are common errors you may encounter when using Blip: