dabeaz

ply: Build Python Lexers and Parsers

PLY is a zero-dependency Python library for building lexers and LALR(1) parsers using lex and yacc conventions. It suits developers implementing language tools or learning compiler construction, but its author says no further maintenance is expected.

View on GitHub Compare
Stars
2.9k
Forks
480
Stars, last 30 days
-2

Our take

Health score

27/100

How it is scored
Activity
19
Community
49
Issues
21
Pull requests
20

-2 stars in the last 30 days

Project history

Daily GitHub snapshots since Oct 7, 2026. History covers stars and forks; health signals are not tracked historically.

Selected snapshot

Stars

2,906

Forks

480

Change since Nov 16, 2026: 0 stars·0 forks

Overview

PLY is a small Python implementation of the traditional lex and yacc tools. It provides tokenization and LALR(1) parsing for projects that need to turn text into structured representations, such as abstract syntax trees, without relying on third-party dependencies.

Its introspection-based API uses Python functions and docstrings to define tokens and grammar rules. PLY is most relevant when you want direct control over a parser, are studying compiler construction, or need to keep the parser code inside your own project.

Key Features

  • Implements lexer and parser tools modeled on lex and yacc.
  • Uses the LALR(1) parsing algorithm.
  • Defines token rules with regular expressions and grammar rules with Python functions and docstrings.
  • Supports building abstract syntax trees and other custom parsing results.
  • Has no third-party dependencies.
  • Can be copied into a project and renamed or moved as needed.

Use Cases

  • Compiler students can use it to practice tokenization, grammar design, and parsing.
  • Language-tool developers can build a lexer and parser for a small programming language.
  • Developers processing structured text can convert input into an AST or another application-specific representation.
  • Protocol-tool authors can use it to parse protocol data when a grammar-based parser is appropriate.

Getting Started

Copy the ply directory into your project, then import its lexer and parser modules:

from ply import lex, yacc

See the README and documentation for grammar and usage details.

Considerations

The README specifies Python 3.6 or newer and states that no further maintenance is expected. PLY is intentionally focused on core lexing and LALR(1) parsing rather than a broad parsing framework. The repository provides no license value in the supplied metadata, so check the repository files for licensing terms before adopting or redistributing it. Since it is not distributed through a package manager, projects generally copy the source files directly.

Found this useful?

Share it with someone who would like ply.