Skip to main content

A simple toy programming language built in Python

Project description

GlimLang ๐ŸŒŸ

PyPI Version Python Version License Build Status

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 match construct 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.2.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:

  1. ๐Ÿ Getting Started Guide โ€” Steps for installing Python, GlimLang CLI, and launching the REPL.
  2. ๐Ÿ“ Language Syntax Guide โ€” Comprehensive syntax definitions, classes, built-ins, and common mistakes.
  3. ๐Ÿ’ป CLI Reference Guide โ€” CLI flags, arguments, stdout, stderr, and exit codes.
  4. โš™๏ธ Architecture & Implementation Design โ€” Source code flow diagram, environment frames, and a tutorial on how to add a feature.
  5. ๐Ÿ“‚ 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

glimlang-1.2.1.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glimlang-1.2.1-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file glimlang-1.2.1.tar.gz.

File metadata

  • Download URL: glimlang-1.2.1.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for glimlang-1.2.1.tar.gz
Algorithm Hash digest
SHA256 7d618c1b320c8323937edaa3f4516d5e752ebcc392be07a88cfc1376f5bd3081
MD5 88d36b426dfb5fa1e952b28bba81f9a1
BLAKE2b-256 af6a27464f51ec9e40999eaa7473bb4a375d5b336b5cb1d5a8aa65d96bb6658f

See more details on using hashes here.

Provenance

The following attestation bundles were made for glimlang-1.2.1.tar.gz:

Publisher: publish.yml on salmanghouridev/glimlang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glimlang-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: glimlang-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for glimlang-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5767a4b6cfd697f76bc18460dd82b9891b545cc57a9d284813b4b8d28f92b161
MD5 018e6619d4d3beddc2381721a40253ef
BLAKE2b-256 cee424634cfadd302a59875867552bb4c1f0c842b8c73e4e915ca144385b7446

See more details on using hashes here.

Provenance

The following attestation bundles were made for glimlang-1.2.1-py3-none-any.whl:

Publisher: publish.yml on salmanghouridev/glimlang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page