Mirror of github.com/ewanc26/selenium
  • Python 96.9%
  • Nix 2%
  • C 1.1%
Find a file
2026-07-16 18:22:46 +01:00
examples docs: add docstrings to source files and examples 2026-06-29 21:52:55 +01:00
selenium docs: add docstrings to source files and examples 2026-06-29 21:52:55 +01:00
.gitignore Update .gitignore to ignore generated files 2026-04-06 19:52:53 +01:00
.pre-commit-config.yaml chore: add pre-commit config with black and isort 2026-04-13 18:42:14 +01:00
AGENTS.md docs: correct agent guidance after source audit 2026-07-16 18:22:46 +01:00
flake.nix docs: add docstrings to source files and examples 2026-06-29 21:52:55 +01:00
LICENSE Initial commit 2026-04-06 19:18:09 +01:00
pyproject.toml feat: add --run flag, fix author, rewrite README, add hello_world example 2026-04-06 20:44:20 +01:00
README.md Update README with Tangled mirror link and current project details 2026-04-25 00:06:17 +01:00

Selenium compiler

Selenium is a small esoteric language with a lunar / poetic surface and a strict, C-like core.
It compiles to C via a Python compiler.

🧶 Also available on Tangled


Installation

pip install -e .

This installs the seleniumc command.


Usage

# Compile to a C file
seleniumc hello.sel -o hello.c

# Compile, run with gcc, and execute immediately
seleniumc hello.sel --run

# Use a different C compiler
seleniumc hello.sel --run --cc clang

Language reference

Types

Selenium C equivalent Notes
int int 32-bit integer
float double 64-bit float
bool _Bool true / false literals
char char single-quoted character
string const char * double-quoted literal
void void return type only

Comments

// single line comment
/* block
   comment */

Variables

wax int x = 5;       // mutable
seal int y = 10;     // immutable (const)

Variables are declared with wax (mutable) or seal (immutable), followed by type and name.
Top-level declarations become C globals. Declarations inside blocks are local.

Functions

ritual add(int a, int b) -> int {
    return a + b;
};

Functions are defined with ritual, take typed parameters, and specify a return type after ->.
Recursion is supported. Functions may be called before they are defined.

I/O

whisper expr;              // print any type, followed by newline
wax int x = read_int();    // read int from stdin
wax float f = read_float();
wax bool b = read_bool();
wax char c = read_char();

Control flow

// if / else
eclipse (condition) {
    ...
} shadow {
    ...
};

// while
tide (condition) {
    ...
};

// for
orbit (wax int i = 0; i < 10; i = i + 1) {
    ...
};

// switch
switch (expr) {
    case 1: { whisper "one"; break; };
    case 2: { whisper "two"; break; };
    default: { whisper "other"; break; };
};

break exits a loop or switch; continue skips to the next loop iteration.

Operators

Category Operators
Arithmetic + - * / %
Comparison < <= > >= == !=
Logical && || !
Bitwise & | ^ << >>
Prefix ++ --
Ternary cond ? then : else

Cast

wax float f = cast(float, 5);
wax int i = cast(int, 3.14);

Explicit type conversion between numeric types, bool, and char.


Examples

Hello, World!

whisper "Hello, World!";

Functions

ritual fact(int n) -> int {
    eclipse (n <= 1) {
        return 1;
    } shadow {
        return n * fact(n - 1);
    };
};

whisper fact(10);

While loop

wax int i = 0;
tide (i < 5) {
    whisper i;
    i = i + 1;
};

Ternary

seal int a = 3;
seal int b = 7;
wax int max = a > b ? a : b;
whisper max;

Project layout

selenium/
  lexer.py       tokeniser (keywords, literals, operators)
  parser.py      recursive-descent parser → AST
  ast.py         AST node types
  sema.py        type checker and semantic analyser
  codegen_c.py   C code generator
  main.py        CLI entry point
examples/        sample .sel programs

Notes

  • The compiler is intentionally strict — no implicit type coercion.
  • All types must be declared explicitly.
  • Top-level wax/seal declarations are emitted as C globals; everything else runs in main.
  • Function definitions can appear anywhere at the top level; forward calls are supported.