A simple toy programming language built in Python
Project description
GlimLang ๐
GlimLang is a lightweight, educational toy programming language designed and implemented entirely from scratch in Python. It features a hand-written Lexical Analyzer (Lexer), a recursive descent Parser that structures tokens into an Abstract Syntax Tree (AST), and a stateful, tree-walking Interpreter supporting first-class environments.
GlimLang is packed with modern language constructs including first-class anonymous functions (lambdas), pattern matching (match statements), classes (OOP), and a highly capable pre-compiled built-ins library. It serves as an accessible entry point for students, educators, and curious developers seeking to understand compiler design and programming language internals.
๐ Key Features
- โ๏ธ Hand-Written Pipeline: Completely custom Lexer and Parser written in readable Python with zero external parsing dependencies.
- ๐ฆ Rich Type System: Numbers (floats/integers), Strings (with f-string dynamic interpolation), Booleans, explicit
null, dynamic Arrays, and custom Blueprint Classes. - ๐ฏ Anonymous Functions & Closures: Standard function statements (
def) and inline lambdas (fn) that carry outer lexical scopes. - ๐ Advanced Pattern Matching: A robust
matchconstruct supporting piped patterns (|), fallback wildcards (_), and multi-statement block arms. - ๐๏ธ Object-Oriented Programming (OOP): Custom blueprint templates (
class), constructor instantiators (init), self-referencing properties (self.x), and standard methods. - ๐ ๏ธ Native Built-ins Library: Over 40 native helper functions covering complex arithmetic, string slicing, array filter/maps, file reader/writers, and user input prompts.
๐ฆ Installation
Ensure you have Python 3.8 or higher installed. Clone the repository and install it in editable developer mode:
git clone https://github.com/YOUR_GITHUB_USERNAME/glimlang.git
cd glimlang
pip install -e .
Verify your installation has registered the global gl command utility:
gl version
Expected Output:
GlimLang v1.1.1
โก Syntax Preview & Showcase
Functions and Lexical Closures
# Let's create an anonymous function and assign it to a variable
let double = fn(x) { return x * 2 }
print double(10) # Prints 20.0
# Pass named/anonymous functions directly into array helper functions
let scores = [1, 2, 3, 4]
let doubled_scores = map(scores, double)
print doubled_scores # Prints [2.0, 4.0, 6.0, 8.0]
Pattern Matching (match)
let browser_status = 404
match browser_status {
200 => print "Success"
404 => print "Page Not Found"
500 | 502 => {
print "Server Error!"
print "Please try again later."
}
_ => print "Unknown Status Code"
}
๐ Quick Start CLI Usage
Run GlimLang Files
Save a simple print statement inside hello.glim and run it:
gl run examples/hello.glim
Run the Interactive REPL
Type GlimLang expressions directly in an active terminal loop:
gl repl
REPL Shell:
GlimLang> let msg = "Hello from REPL!"
GlimLang> print msg
Hello from REPL!
GlimLang> exit
๐ Project Structure
glimlang/
โโโ src/ # Compiler & Interpreter Core Engine
โ โโโ lexer.py # Lexical analysis (character streams -> tokens)
โ โโโ parser.py # Syntactic analysis (token lists -> AST nodes)
โ โโโ ast_nodes.py # Abstract Syntax Tree structural dataclasses
โ โโโ interpreter.py # Stateful environment walker & native builtins
โ โโโ errors.py # Standardized diagnostics and trace compiler
โ โโโ cli.py # Positional argument CLI router (run, repl, help)
โ โโโ main.py # Basic programmatic entrypoint
โ โโโ stdlib.glim # Code helper utilities written in GlimLang
โโโ docs/ # Beginner-Friendly Educational Guides
โ โโโ GETTING_STARTED.md # Installation, first hello-world, and REPL setup
โ โโโ LANGUAGE_GUIDE.md # Core syntax, scoping, OOP, and builtins list
โ โโโ CLI.md # Global CLI command references and output keys
โ โโโ ARCHITECTURE.md # Pipeline state flows and how to add a feature
โ โโโ EXAMPLES.md # Example catalog with detailed output keys
โโโ examples/ # Progressively structured test programs
โ โโโ hello.glim # Hello World
โ โโโ variables.glim # Declarations and dynamic scoping
โ โโโ math.glim # Exponentiation, division, and modulo
โ โโโ strings.glim # Dynamic f-string interpolation
โ โโโ conditions.glim # Basic if-else branches
โ โโโ nested_conditions.glim # Nested condition evaluations
โ โโโ while_loop.glim # Iterative loops with break/continue
โ โโโ functions.glim # Named functions and recursive stacks
โ โโโ arrays.glim # Array syntax and allocations
โ โโโ indexing.glim # Element retrieval and modification
โ โโโ builtins.glim # Demonstrates all built-in function groups
โ โโโ countdown.glim # Countdown iterations
โ โโโ fizzbuzz.glim # Classic FizzBuzz algorithm
โ โโโ calculator.glim # Matching calculator script
โ โโโ grade_checker.glim # Conditional grade calculator
โ โโโ simple_menu.glim # Menu state machine
โโโ pyproject.toml # Modern build metadata and CLI mapping
โโโ setup.py # Setuptools project routing configuration
โโโ CONTRIBUTING.md # Developer setup and AST feature safety checks
โโโ CHANGELOG.md # Historical release logs
โโโ LICENSE # Project License File (Apache 2.0)
๐ Documentation Reference Links
Deep-dive into GlimLang subsystems using these detailed guides:
- ๐ Getting Started Guide โ Steps for installing Python, GlimLang CLI, and launching the REPL.
- ๐ Language Syntax Guide โ Comprehensive syntax definitions, classes, built-ins, and common mistakes.
- ๐ป CLI Reference Guide โ CLI flags, arguments, stdout, stderr, and exit codes.
- โ๏ธ Architecture & Implementation Design โ Source code flow diagram, environment frames, and a tutorial on how to add a feature.
- ๐ Examples Catalog โ Review of pre-made sample files and expected terminal stdout.
๐ ๏ธ Development Setup
Check CONTRIBUTING.md to set up a virtual environment, run code style formats, verify parser changes, and submit structured pull requests.
๐ License
GlimLang is licensed under the Apache License 2.0. See the LICENSE file for the complete terms.
๐บ๏ธ Future Roadmap
- Standard Module Imports: File imports support (
import "math.glim"). - Class Inheritance: Support standard blueprint extensions (
class Dog in Animal). - Inline Dictionary Literals: Explicit dictionary literals (
let dict = { "x": 10 }). - LSP Server: Language Server Protocol integration for autocompletions in IDEs.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glimlang-1.1.1.tar.gz.
File metadata
- Download URL: glimlang-1.1.1.tar.gz
- Upload date:
- Size: 45.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58d3b9c4bd520738da932523d8be6d94fa9b894b2799954c7d92a7bef67c4f10
|
|
| MD5 |
52fdaf0c4ae4c61d8bd48ca46a21f2f6
|
|
| BLAKE2b-256 |
60ba0034f4d6df24127764c1d9ed7df2542825d273d3d626a01756bc19534b3e
|
Provenance
The following attestation bundles were made for glimlang-1.1.1.tar.gz:
Publisher:
publish.yml on salmanghouridev/glimlang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glimlang-1.1.1.tar.gz -
Subject digest:
58d3b9c4bd520738da932523d8be6d94fa9b894b2799954c7d92a7bef67c4f10 - Sigstore transparency entry: 1630242386
- Sigstore integration time:
-
Permalink:
salmanghouridev/glimlang@cc874def2392011ae8b6c0c8ab2adf77bffbc877 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/salmanghouridev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc874def2392011ae8b6c0c8ab2adf77bffbc877 -
Trigger Event:
push
-
Statement type:
File details
Details for the file glimlang-1.1.1-py3-none-any.whl.
File metadata
- Download URL: glimlang-1.1.1-py3-none-any.whl
- Upload date:
- Size: 42.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4431fc763145ee7d8d24e66980ce34e42efa299b5d1e4734d3fbb724a98b6307
|
|
| MD5 |
f36d049f7845ba91def9ab04abbe3a9f
|
|
| BLAKE2b-256 |
676c2fb1c7a3bcf8e2423dd7325d1b5aa01e35f30108fc6ec64b9782fe4da272
|
Provenance
The following attestation bundles were made for glimlang-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on salmanghouridev/glimlang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glimlang-1.1.1-py3-none-any.whl -
Subject digest:
4431fc763145ee7d8d24e66980ce34e42efa299b5d1e4734d3fbb724a98b6307 - Sigstore transparency entry: 1630242393
- Sigstore integration time:
-
Permalink:
salmanghouridev/glimlang@cc874def2392011ae8b6c0c8ab2adf77bffbc877 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/salmanghouridev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc874def2392011ae8b6c0c8ab2adf77bffbc877 -
Trigger Event:
push
-
Statement type: