Skip to main content

PyLGEN

PyPI - 0.7.2 PyPI - 3.12 PyPI - LICENSE CI codecov Supported OS

From prototype to production: a Python-native compiler framework that brings the "Dragon Book" to life in Python, with clarity throughout.

PyLGEN gives you complete control over every stage of language processing. Build interpreters and compilers from scratch without leaving the Python ecosystem. Prototype rapidly in pure Python, then compile to native speed with Cython for production workloads.

Why PyLGEN?

  • Full pipeline control: You own every step: lexer, parser, AST, semantic analysis, and evaluation.

  • Dual‑nature design: Pure Python for development and debugging; Cython for near‑C performance.

  • Handles large inputs: 2‑million‑line files parsed in ~61.62 s, about 1.89x faster than Lark + lark_cython.

  • Python ecosystem integration: Leverage NumPy, SciPy, or any library from within your language.

📊 Benchmark at a Glance

Lark + lark_cython PyLGEN
Parsing (2M lines, 40 MB) 116.73 s 61.62 s
AST Construction Separate pass Integrated
Full Interpreter — ~67.52 s (incl. semantic checks + eval)
Peak Memory ~4 GB ~968 MB

more details in the benchmark section of documentation →

PyLGEN is a framework for building interpreters, covering the full compilation pipeline from lexical analysis to execution.

🚀 Minimal Example

from pylgen.lexer import Lexer
from pylgen.grammar import AttributedGrammar
from pylgen.parser import ParserBuilder, ParserType
from pylgen.common.enums import TokenType
from pylgen.common.types import Symbol

class TokenTypeEnum(TokenType):
    NUMBER = 'NUMBER'
    PLUS = 'PLUS'

    # ...

def mapping_function(t:TokenTypeEnum,tx:str) -> Symbol:
    # ....

# 1. Define tokens & lexer
lexer = Lexer(mapping_function, r'\s+')
lexer[0, TokenTypeEnum.NUMBER] = r'\d+'
lexer[1, TokenTypeEnum.PLUS]   = r'\+'

# 2. Define grammar with AST builders
# Assumes the following are already defined:
#   E, T, plus, binary_reductor, single_reductor
G = AttributedGrammar(Symbol('E'))
G[E] += (E, plus, T), binary_reductor
G[E] += (T,),        single_reductor

# 3. Build the parser
parser = ParserBuilder.build_parser_from_attributed(G, ParserType.LALR1)

# 4. Parse, analyse, execute
text = '1 + 2' # your text to parse
lexer.load_text(text)
ast = parser.parse(lexer.tokens)
# ... your semantic visitors & evaluator ...

🧩 Architecture

flowchart LR
    Source["Source Code"] --> Lexer["Lexer"]
    Lexer --> Parser["Parser LALR(1)"]
    Parser --> AST["AST"]
    AST --> Visitors["Visitors"]
    Visitors --> Result["Result / Errors"] 
Module Purpose
common Core types: Symbol, AST, Token, ASTListView, and error hierarchy
automaton Finite automata(DFA/NFA), determinization, Hopcroft minimization
regex Full regex engine -> automata conversion
lexer Regex‑based tokenization with priority and validation
grammar CFG and attributed grammar with reducers
parser LALR(1) parser generation and runtime
analysis Visitor pattern, traversal strategies, context management
visual Interactive HTML visualization of ASTs, parse trees, automata and parsing tables

All modules are fully usable from Python and Cython, prototype in Python, ship in C.

⚡ Quick Start

pip install pylgen-core

Then build your interpreter step by step, following the complete tutorial in the documentation.

📖 Learn More

  • Step‑by‑step tutorial: Build a full arithmetic REPL from scratch.

  • VecLang case study: Production‑grade language with vectors, functions, and slicing.

  • Deep‑dive API tour: Understand every module inside out.

  • Under the hood: Build a lexer and parser from scratch, using the same building blocks that the framework uses internally.

  • Examples: See practical examples of using PyLGEN to build interpreters and DSLs.

Read the full documentation →

PyLGEN: Where compiler theory meets Python pragmatism.

Contributing

Contributions are welcome. Please open an issue or submit a pull request. See Contributing.md for details.

License

This project is licensed under the BSD 3-Clause License. See LICENSE for details.

Changelog

All notable changes to this project are documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[0.7.2] - 2026-10-09

Added

  • Support for extended Latin characters (accented vowels, diaeresis, and eñe: á é í ó ú ü ñ and their uppercase forms) as literals in regular expressions.
  • Support for Spanish punctuation marks (¿ ¡ « ») as literals.

Changed

  • Breaking: the lexer and the constants (\D, \S, \W, ., and the default negated class) now operate over the extended alphabet instead of string.printable. Inputs containing non-ASCII characters that previously produced a tokenization error are now recognized as CHAR.
  • Breaking: the complement of a character class ([^...]) is computed against the extended alphabet, not string.printable.

Fixed

  • Regular expressions containing Spanish letters (niño, camión, pingüino, …) failed in the lexer because those characters were not in string.printable.
  • The ¡ and ¿ signs are no longer discarded as invalid characters.

[0.7.1] - 2026-09-28

Fixed

  • BaseLexer wrong behavior with idented languages.

[0.7.0] - 2026-09-27

Changed

  • AST now exposes start_position and end_position properties instead of separate line and column. The constructor now receives start_line, start_column, end_line, and end_column instead of just line and column. Breaking change for any subclass of AST or any reductor that instantiates AST nodes.

  • Moved ErrorType from pylgen.analysis.error_type to pylgen.common.enums. Update your imports accordingly. Breaking change.

  • Moved Error, LexicalError, SyntaxError, SemanticError and RuntimeError from pylgen.analysis.error to pylgen.common.types. Update your imports accordingly. Breaking change.

[0.6.2] - 2026-08-29

Fixed

  • Fixed type mismatches in BottomUpParser with the enum BottomUpParserAction.

Metadata

Release files for pylgen-core 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylgen-core 0.7.2
File Size Uploaded
pylgen_core-0.7.2.tar.gz 2.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pylgen-core 0.7.2
File
pylgen_core-0.7.2-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pylgen_core-0.7.2-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.2-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
pylgen_core-0.7.2-cp314-cp314-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.15+ x86-64 Details
pylgen_core-0.7.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pylgen_core-0.7.2-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.2-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
pylgen_core-0.7.2-cp313-cp313-macosx_10_13_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.13+ x86-64 Details
pylgen_core-0.7.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pylgen_core-0.7.2-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
pylgen_core-0.7.2-cp312-cp312-macosx_10_13_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.13+ x86-64 Details

Total release size: 90.1 MB

Release files / pylgen_core-0.7.2.tar.gz

Download URL pylgen_core-0.7.2.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
1689a22469f4b873515266a523e6ef5ce0be86a0d60078893defb0bdffdfd8bb
BLAKE2b-256 checksum
How to use checksums
ddcc9890b50e32992307a198825a825934c95e7303c33ad383b40bda8376178b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp314-cp314-win_amd64.whl

Download URL pylgen_core-0.7.2-cp314-cp314-win_amd64.whl
Size 3.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
73735ee98567505dce0fb6e951dfd2245d3c979acefd00d9217d5227856cef56
BLAKE2b-256 checksum
How to use checksums
f320af87c24aa8ac4ee3ac50feda9c5552e59348b9f228e74dfaec7134a2beb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.2-cp314-cp314-musllinux_1_2_x86_64.whl
Size 9.7 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
d0e4fefdcd4a7c7d0dbdc2be5b9aa268f3a5648093908b1600422c49fe020ce3
BLAKE2b-256 checksum
How to use checksums
f662df9081a6232ca2cde5d13e3729293ca2b39dc91d96b3f782c77bd91b553e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.6 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f75b570ee0e6d2d447084bb10ce17380c309a41c4d4c3abed2725904c78ff455
BLAKE2b-256 checksum
How to use checksums
6e8abf030752d66f3be593c922632a9967af8b08dfd8447b8c345c197dbd0aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp314-cp314-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.2-cp314-cp314-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9967dbc3d07215214cdbb149158c8325fcf9b8d96364c036d2fff3e83ad9cb24
BLAKE2b-256 checksum
How to use checksums
9d9e8c3a388a0360d2355b23bc78f37bbf9b23a038f57b57314cca89d9a7f8fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp314-cp314-macosx_10_15_x86_64.whl

Download URL pylgen_core-0.7.2-cp314-cp314-macosx_10_15_x86_64.whl
Size 3.4 MB
Tags CPython 3.14 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
1dcb63c1393b1ea08fb30fdc350085c32ad9a7fbff52e50cb8e89964b3d69e68
BLAKE2b-256 checksum
How to use checksums
b8a7f211f19a3a8b7752095750d68703b13b76680d48dba8347b5e0969b631d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp313-cp313-win_amd64.whl

Download URL pylgen_core-0.7.2-cp313-cp313-win_amd64.whl
Size 3.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
b30144af8fe53354461655ede732bfdc68be2279f21c66a87dd1b596b6c67e27
BLAKE2b-256 checksum
How to use checksums
70891cf5b223670a8c9c9471beb210f869476eb16356a94984809cf8b36bd3cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.2-cp313-cp313-musllinux_1_2_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
03a5a1614823a71ed34604e309cb34b30de1399a2ac7020f167d6a7a3aff13b2
BLAKE2b-256 checksum
How to use checksums
a1ca40a4f971710c8512d58de319a7a4b120df4a6c0027b2b7d0005f3e0cc289
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6d03e0461375d65350ae0ec9d41ab1e493aae9e8e67bc5ebfe2a6681912c72ce
BLAKE2b-256 checksum
How to use checksums
39d52cc87f4ea4d77c8b2abafe42588a6eeacb68f4f0d69d4c57918ccc24e103
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp313-cp313-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.2-cp313-cp313-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
36ad3e1336f7c03f2d6ffaeea60e2165b4db646793366fa317a0a14cd8dd0d01
BLAKE2b-256 checksum
How to use checksums
379ed12d2559f68752cae65552366e71248b652ca67c2c9f0134c35523e4bb3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp313-cp313-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.2-cp313-cp313-macosx_10_13_x86_64.whl
Size 3.3 MB
Tags CPython 3.13 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
9cf6137f896142a87ae4b0abb944a7b824cce6bfd2b3b902e60053551ab959c2
BLAKE2b-256 checksum
How to use checksums
63dee2f37bc6af164a235b0455beeb7fd15e354eeac710c2dd8add52fbc3df81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp312-cp312-win_amd64.whl

Download URL pylgen_core-0.7.2-cp312-cp312-win_amd64.whl
Size 3.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
94852c92831e9467d30f536d5f58cdd5a84fdd50953af50570063c2f40bcdee7
BLAKE2b-256 checksum
How to use checksums
ed9d064d0e239131cd7fe1810389c0b37f13ccfb56190591165f9f194d3f022c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.2-cp312-cp312-musllinux_1_2_x86_64.whl
Size 9.9 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
f864b7aff1ee41eec350daf35516b0e7127ed72aade776ac9e38dd58dd0b4600
BLAKE2b-256 checksum
How to use checksums
26b392f34af944ae053ffdd65bd2f5b1fec0abe214ed9500acd3f4da1357d625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
dcd8ad685efd0591c793bc812f51841f305fc2faec2c6e58eb7416850591e77c
BLAKE2b-256 checksum
How to use checksums
e5e097020eec0f8ead6129f2e5e7de0287e9dde0290337bdc3642c4fd984d48e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.2-cp312-cp312-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b70d1794243c9574296b64f4b2337278e8600807c937ffe1c4da959631d2eaba
BLAKE2b-256 checksum
How to use checksums
2c1f06e3b76c3b10acc6609520a311a2081ec0ac1da3a9fb561d516e691277bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.2-cp312-cp312-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.2-cp312-cp312-macosx_10_13_x86_64.whl
Size 3.4 MB
Tags CPython 3.12 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
4b57ba4aae68eec6379fd7e18b2ac9b4ff0860d85ddc34909d90f4ae0c1ab47b
BLAKE2b-256 checksum
How to use checksums
612e7245d3cfa7e7ce4c031ec5c0b30c0cbee93be3c84ffc5b7cfc21100346ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.7.2 This release

16 release files

0.7.1

16 release files

0.7.0

16 release files

0.6.3

16 release files

0.6.1

16 release files

0.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page