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.2

โšก 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/                    # Source code directory
โ”‚   โ””โ”€โ”€ glimlang/           # Core compiler & interpreter package
โ”‚       โ”œโ”€โ”€ __init__.py     # Package initialization
โ”‚       โ”œโ”€โ”€ __main__.py     # CLI execution entrypoint
โ”‚       โ”œโ”€โ”€ 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         # Programmatic API entrypoint
โ”‚       โ””โ”€โ”€ stdlib.glim     # Code helper utilities written in GlimLang
โ”œโ”€โ”€ docs/                   # Documentation and Guides
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md     # Pipeline state flows and design patterns
โ”‚   โ”œโ”€โ”€ CLI.md              # Global CLI command references
โ”‚   โ”œโ”€โ”€ EXAMPLES.md         # Example catalog with detailed output keys
โ”‚   โ”œโ”€โ”€ GETTING_STARTED.md  # Installation and REPL setup instructions
โ”‚   โ”œโ”€โ”€ INSTALL.md          # Brief installation info
โ”‚   โ”œโ”€โ”€ LANGUAGE_GUIDE.md   # Core syntax, scoping, OOP, and builtins list
โ”‚   โ”œโ”€โ”€ README_WEB.md       # Web playground readme
โ”‚   โ”œโ”€โ”€ glimlang_docs.html  # Compiled docs in HTML
โ”‚   โ””โ”€โ”€ index.html          # Documentation index HTML
โ”œโ”€โ”€ examples/               # Example programs in GlimLang
โ”‚   โ”œโ”€โ”€ arrays.glim         # Array syntax and allocations
โ”‚   โ”œโ”€โ”€ builtins.glim       # Demonstrates built-in function groups
โ”‚   โ”œโ”€โ”€ builtins_demo.glim  # Rich showcase of standard builtins
โ”‚   โ”œโ”€โ”€ calculator.glim     # Match-based interactive calculator
โ”‚   โ”œโ”€โ”€ conditions.glim     # Conditional check control flows
โ”‚   โ”œโ”€โ”€ countdown.glim      # Simple countdown loop
โ”‚   โ”œโ”€โ”€ error_handling.glim # Error catching syntax tests
โ”‚   โ”œโ”€โ”€ fizzbuzz.glim       # FizzBuzz implementation
โ”‚   โ”œโ”€โ”€ functions.glim      # Scope boundaries and functions
โ”‚   โ”œโ”€โ”€ grade_checker.glim  # Nested grade categorization
โ”‚   โ”œโ”€โ”€ greeting.glim       # Standard greetings
โ”‚   โ”œโ”€โ”€ hello.glim          # Hello World program
โ”‚   โ”œโ”€โ”€ import_demo.glim    # Demo of loading dependencies
โ”‚   โ”œโ”€โ”€ indexing.glim       # Array index getters and setters
โ”‚   โ”œโ”€โ”€ lambdas_demo.glim   # Anonymous functions and closures
โ”‚   โ”œโ”€โ”€ match_demo.glim     # Advanced pattern matching features
โ”‚   โ”œโ”€โ”€ math.glim           # Expressions and math utilities
โ”‚   โ”œโ”€โ”€ nested_conditions.glim # Deeply nested conditions
โ”‚   โ”œโ”€โ”€ simple_menu.glim    # Simple menu loops
โ”‚   โ”œโ”€โ”€ stdlib_demo.glim    # Demonstrates stdlib integrations
โ”‚   โ”œโ”€โ”€ strings.glim        # Dynamic f-string interpolation
โ”‚   โ”œโ”€โ”€ utils.glim          # Basic utility functions
โ”‚   โ”œโ”€โ”€ variables.glim      # Basic let-bindings and identifiers
โ”‚   โ””โ”€โ”€ while_loop.glim     # While loop control structures
โ”œโ”€โ”€ vscode-extension/       # Visual Studio Code editor extension
โ”‚   โ””โ”€โ”€ glimlang-vscode/    # Syntax highlighting and snippet files for VS Code
โ”œโ”€โ”€ web/                    # Interactive web-based playground/terminal
โ”‚   โ”œโ”€โ”€ server.py           # Web application server
โ”‚   โ”œโ”€โ”€ requirements.txt    # Web playground dependencies
โ”‚   โ””โ”€โ”€ templates/          # HTML templates for the playground
โ”œโ”€โ”€ 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

For more guides and documentation, visit glimlang.org.

Deep-dive into GlimLang subsystems using these detailed local 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.2.tar.gz (47.9 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.2-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: glimlang-1.2.2.tar.gz
  • Upload date:
  • Size: 47.9 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.2.tar.gz
Algorithm Hash digest
SHA256 03353856daabe6a87ca27f3d8472a4bd2d1e9968ed77b3cdf27f7e41deb31667
MD5 485ef4c8b57fa35c9a9ac4231747bfef
BLAKE2b-256 49dfbdbd0997a53f59457ada4e30243a706b3655fc0e3ca73859ed416274edea

See more details on using hashes here.

Provenance

The following attestation bundles were made for glimlang-1.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: glimlang-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 45.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6788a1badeab77d3bae63b9d4ada68eb2b41ab47694971c3cb617cfdb88d1db4
MD5 c5e9a0775e171a19cde9db7ae434339e
BLAKE2b-256 41ce8a70d0fca83e144efe179be9e63c6638091dc70f48d67b24ef79b4f7b6cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for glimlang-1.2.2-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