Skip to main content

PyLGEN

PyPI - 0.6.0 PyPI - 3.12 PyPI - LICENSE CI

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.

  • Built for scale: Handles 2‑million‑line inputs with ~1.92x faster parsing 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 60.80 s
AST Construction Separate pass Integrated
Full Interpreter — ~66.03 s (incl. semantic checks + eval)
Peak Memory ~4 GB ~927 MB

PyLGEN is not just a parser, it's a complete, production‑ready interpreter framework that outperforms industry‑standard tools.

🚀 Minimal Example

from pylgen.lexer import Lexer
from pylgen.grammar import AttributedGrammar
from pylgen.parser import ParserBuilder, ParserType

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

# 2. Define grammar with AST builders
G = AttributedGrammar(start=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
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
automaton Finite automata(DFA/NFA), determinization, Hopcroft minimisation
regex Full regex engine -> automata conversion
lexer Regex‑based tokenisation 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 visualisation 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.

Read the full documentation →

PyLGEN: Where compiler theory meets Python pragmatism.

Metadata

Release files for pylgen-core 0.6.0

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.6.0
File Size Uploaded
pylgen_core-0.6.0.tar.gz 2.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylgen-core 0.6.0
File Interpreter ABI Platform
pylgen_core-0.6.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details

Total release size: 5.8 MB

Release files / pylgen_core-0.6.0.tar.gz

Download URL pylgen_core-0.6.0.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
d335c8f6b60c88d69117329e53fea5ef32d35adb736735db070507296781d00b
BLAKE2b-256 checksum
How to use checksums
87ff96301a144ab43764586c56681a7b573acdb1a3354674732e766822594749
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.6.0-cp313-cp313-win_amd64.whl

Download URL pylgen_core-0.6.0-cp313-cp313-win_amd64.whl
Size 3.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f2ccecfabce78820647676568d7dc5418db1b4d36425bb00edf4f63de266d348
BLAKE2b-256 checksum
How to use checksums
6d2b40ade6ec8272ce14a494e1dea8afe2b84b8f9f9ef0a9ca39b2aa4e8bb3d2
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

0.7.2

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

This release

0.6.0 This release

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