- [WARNING] This programming language is still under active development and is not stable.
- Using it may cause unexpected behavior, memory leaks, or other critical issues.
- Many features are incomplete or experimental.
- It is strongly advised not to use this language in production or for important projects until development is fully completed and thoroughly validated.MercuryLang is a lightweight, free, and open-source programming language written in C++, inspired by the simplicity of Lua and Python. It provides clean syntax, dynamic typing, powerful standard libraries, and a fast interpreter โ ideal for beginners and language creators alike.
- ๐น Python-like clean syntax
- ๐น First-class functions
- ๐น Built-in math & list support
- ๐น Dynamic variables and control flow
- ๐น Interactive REPL +
.merfile runner - ๐น C++ API to embed or customize MercuryLang
1. Navigate to the MercuryLang-main folder.
2. Open Command Prompt.
3. Run make to build from source, and mer, merc, mpi will be in MercuryLang-main/Bin/
4. Rename MercuryLang-main into MercuryLang and then move it to C:/
5. Edit environment path to C:/MercuryLang/Bin/
- C++ Compiler (MSVC / GCC / Clang)
- CMake 3.12+
mer # Launch REPL
mer main.mer # Run fileimport "IO" # standard IO library
print("hello world") # output: hello world
import "IO"
let x = 10
print(x)
import "IO"
let a = "hello, "
let b = "world"
print(a + b)
import "IO"
let fruits = [["apple, "orange", "pineapple"], "banana", "water"]
fruit *= 2
print(fruits[0][1])
frutis[0][2] = "watermelon"
let other_food = ["fish", "egg"]
print(fruits + other_food)
import "IO"
let f(x) = [1, 2, 3, 4, x]
print(f(3)[0])
import "IO"
func add(x, y) do
return x + y
end
print(add(2, 3))
import "IO"
let x = 0
while x < 100 do
print(x)
x += 1
end
import "IO"
for i in range(0, 1000) do
print(i)
end
import "IO"
let x = 0
loop
print(x)
x += 1
if x > 100 then
break
end
end
import "IO"
let a = 1
if a == 1 then
print("a = 1")
end
elif a == 2 then
print("a = 2")
end
else
print("other value")
end
class Animal do
let name = ""
let age = 0
func init_name(n, a) do
this.name = n
this.age = a
end
end
class Dog extends Animal do
name = "Dog"
age = 12
func bark() do
print("woof")
end
end
class Cat extends Animal do
name = "Cat"
age = 15
func meow() do
print("meow")
end
end
let pup = Dog()
let kirby = Cat()
pup.init_name("Pup Dog", 16)
kirby.init_name("LongTail Cat", 20)
print(pup.name)
print(kirby.name)
MercuryLang supports calling C++ functions from dynamic libraries (.dll on Windows) via the dll_load function.
dll_load("<path_to_dll>", "<function_name>", [arg1, arg2, ...])<path_to_dll>: Path to your compiled DLL or shared library.<function_name>: Name of the exported C++ function.[arg1, arg2, ...]: Arguments passed to the C++ function (as a list).
#include <Mercury.h> // Include Mercury API
START_DLL // Required macro for Mercury DLL
// Exported function must return table* and accept table* args[]
DLL_EXPORT table* extend(table* args[]) {
table *item1 = args[0];
table *item2 = args[1];
if (item1->is_list && item2->is_list) {
item1->list_v->args.insert(item1->list_v->args.end(),
item2->list_v->args.begin(),
item2->list_v->args.end());
item1->list_v->size += item2->list_v->size;
return item1;
}
else if (item1->is_str && item2->is_str) {
item1->f_str_v->buff.insert(item1->f_str_v->buff.end(),
item2->f_str_v->buff.begin(),
item2->f_str_v->buff.end());
item1->f_str_v->size += item2->f_str_v->size;
return item1;
}
else {
item1->cval += item2->cval;
item1->value += item2->value;
return item1;
}
}
END_DLL // Required macroCompile the C++ file into a .dll (Windows), then call it from Mercury:
func extend(item1, item2) do
return dll_load("init.dll", "extend", [item1, item2])
end
extend([1, 2, 3], [4, 5, 6]) # => [1, 2, 3, 4, 5, 6]
extend("Hello, ", "World!") # => "Hello, World!"MercuryLang also supports many other syntax features such as break, return, continue, and, or, not, is, include, import, do, end, if, elif, else, while, for, loop, and more.
- MercuryLang has a library for graphic and game (
MGL) - This code here is a example for a simple jumping game using
MGL - If you want to use the library graphic and game download
SDL3.dlland then move it into..\Bin
import "MGL" # import Mercury Game Library
screen_width = 500
screen_height = 500
screen_init(screen_width, screen_height)
cube_width = 50
cube_height = 50
cube_x = 0
cube_y = screen_height - cube_height
cube_vel = 5
cube_color = [255, 255, 255]
while true do
screen_fill(0, 0, 0)
screen_draw(cube_x, cube_y, cube_width, cube_height, cube_color[0], cube_color[1], cube_color[2])
let key = get_key_char(key_pressed())
if same(key, "a") then
cube_x -= cube_vel
end
if same(key, "d") then
cube_x += cube_vel
end
if cube_x >= screen_width - cube_width then
cube_x = screen_width - cube_width
end
if cube_x <= 0 then
cube_x = 0
end
screen_flip()
end
screen_quit()#include <Mercury.h>
int main() {
let_S = "gan";
PRINT_S = "in";
WHILE_S = "lap";
IF_S = "neu";
THEN_S = "thi";
END_S = "ketthuc";
LANGUAGE = "MercuryLangTiengViet";
AUTHOR = "Dinh Son Hai";
prompt();
}If Python has pip, so MercuryLang has mpi
-
mpi(Mercury Package Installer) is the official tool for installing external libraries in MercuryLang โ just likepipin Python. -
Unlike Python or Lua which use centralized package markets,
MercuryLang uses GitHub as the main source for libraries.
Installing a library with mpi is simple. Just type:
mpi --install https://github.com/author/repoExample:
mpi --install https://github.com/dinhsonhai132/mathWhen done just import it:
import "math"
Replace
author/repowith the actual GitHub repository of the library you want to install.
To be recognized as a valid MercuryLang library, the repository must contain:
- This is the entry point of the library.
- If itโs missing or named incorrectly,
mpiwill reject the repo.
- A metadata file that describes the library.
- Example format:
{
"name": "your-library-name",
"version": "1.0.0",
"description": "A short description of your library.",
"author": "YourName"
}Made by dinhsonhai132
