PHPackages                             stenin-nikita/php-yacc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. stenin-nikita/php-yacc

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

stenin-nikita/php-yacc
======================

A PHP YACC Parser-Generator library

0221PHP

Since Feb 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/stenin-nikita/PHP-Yacc)[ Packagist](https://packagist.org/packages/stenin-nikita/php-yacc)[ RSS](/packages/stenin-nikita-php-yacc/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP-Yacc
========

[](#php-yacc)

[![StyleCI](https://camo.githubusercontent.com/331c0f1dfde78db2fc12664f42484fcd91ddb41d91fda12d8ed6f8ffadce24e1/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131353336343034372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/115364047)[![Scrutinizer CI](https://camo.githubusercontent.com/fab8a493f58174e44c0c6e41c704f419f82703f37d32fd5f54e241c2b0625c38/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7374656e696e2d6e696b6974612f5048502d596163632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/stenin-nikita/PHP-Yacc/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/a43515016a4226e06abc03a44ee4061541ac691e41e87a6722a7cd159461cb6f/68747470733a2f2f706f7365722e707567782e6f72672f7374656e696e2d6e696b6974612f7068702d796163632f762f737461626c65)](https://packagist.org/packages/stenin-nikita/php-yacc)[![Latest Unstable Version](https://camo.githubusercontent.com/0b8e0a6914ea45ec8248b731bc2c6cff545a0e1b59cfd388321edc52852c741e/68747470733a2f2f706f7365722e707567782e6f72672f7374656e696e2d6e696b6974612f7068702d796163632f762f756e737461626c65)](https://packagist.org/packages/stenin-nikita/php-yacc)[![License](https://camo.githubusercontent.com/e6481f719bdeb38200baffbbfc56c054f27716b76894c0e0e08ad04d4151d5da/68747470733a2f2f706f7365722e707567782e6f72672f7374656e696e2d6e696b6974612f7068702d796163632f6c6963656e7365)](https://packagist.org/packages/stenin-nikita/php-yacc)

This is a port of [`kmyacc`](https://github.com/moriyoshi/kmyacc-forked) into PHP. It is a parser-generator, meaning it takes a YACC grammar file and generates a parser file.

A Direct Port (For Now)
-----------------------

[](#a-direct-port-for-now)

Right now, this is a direct port. Meaning that it works exactly like `kmyacc`. Looking in the examples, you can see that this means that you must supply a "parser template" in addition to the grammar.

Longer term, we want to add simplifying functionality. We will always support providing a template, but we will offer a series of default templates for common use-cases.

Basic Usage
-----------

[](#basic-usage)

Require this package with composer:

```
composer require stenin-nikita/php-yacc
```

Run command in console:

```
vendor/bin/phpyacc -s "/path/to/template" -o "/path/to/output" -c "MyParser" "/path/to/grammar.phpy"
```

What can I do with this?
------------------------

[](#what-can-i-do-with-this)

You can parse most structured and unstructured grammars. There are some gotchas to [LALR(1) parsers](https://en.wikipedia.org/wiki/LALR_parser) that you need to be aware of (for example, Shift/Shift conflicts and Shift/Reduce conflicts). But those are beyond this simple intro.

How does it work?
-----------------

[](#how-does-it-work)

I don't know. I just ported the code until it worked correctly.

YACC Grammar
------------

[](#yacc-grammar)

That's way beyond the scope of this documentation, but checkout [The YACC page here](http://dinosaur.compilertools.net/yacc/) for some info.

Over time we will document the grammar more...

How do I use it?
----------------

[](#how-do-i-use-it)

For now, check out the examples folder. The current state of the CLI tool will change, so any usage today should please provide feedback and use-cases so that we can better design the tooling support.

Why did you do this?
--------------------

[](#why-did-you-do-this)

Many projects have the need for parsers (and therefore parser-generators). Nikita's [PHP-Parser](https://github.com/nikic/PHP-Parser) is one tool that uses kmyacc to generate its parser. There are many other projects out there that either use hand-written parsers, or use kmyacc or another parser-generator.

Unfortunately, not many parser-generators exist for PHP. And those that do exist I have found to be rigid or not powerful enough to parse PHP itself.

This project is an aim to resolve that.

Performance
-----------

[](#performance)

There's a TON of performance optimizations possible here. The original code was a direct port, so some structures are definitely sub-optimal. Over time we will improve the performance.

However, this will always be at least a slightly-slow process. Generating a parser requires a lot of resources, so should never happen inside of a web request.

Using the generated parser however should be quite fast (the generated parser is fairly well optimized already).

What's left to do?
------------------

[](#whats-left-to-do)

A bunch of things. Here's the wishlist:

- Refactor to make conventions consistent (some parts currently use camel-case, some parts use snakeCase, etc).
- Performance tuning
- Unit test as much as possible
- Document as much as possible (It's a complicated series of algorithms with no source documentation in either project).
- Redesign the CLI binary and how it operates
- Decide whether multi-language support is worth while, or if we should just move to only PHP codegen support.
- Add default templates and parser implementations
    - At least one of which generates an "AST" by default, similar to Ruby's [Treetop library](https://github.com/nathansobo/treetop)
- Build a reasonably performant lexer-generator (very likely as a separate project)
- A lot of debugging (though we don't know of any bugs, they are there)
- Building out of features we didn't need for the initial go (for example, support for `%union`, etc).

And a lot more.

Contributing
------------

[](#contributing)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef39b0b46136030c30f3fea73eb251ccaea7c439deda9064dad59572e78bb93f?d=identicon)[stenin-nikita](/maintainers/stenin-nikita)

---

Top Contributors

[![nikic](https://avatars.githubusercontent.com/u/216080?v=4)](https://github.com/nikic "nikic (51 commits)")[![ircmaxell](https://avatars.githubusercontent.com/u/660654?v=4)](https://github.com/ircmaxell "ircmaxell (44 commits)")[![stenin-nikita](https://avatars.githubusercontent.com/u/8615201?v=4)](https://github.com/stenin-nikita "stenin-nikita (28 commits)")[![ProgMiner](https://avatars.githubusercontent.com/u/6567920?v=4)](https://github.com/ProgMiner "ProgMiner (1 commits)")

### Embed Badge

![Health badge](/badges/stenin-nikita-php-yacc/health.svg)

```
[![Health](https://phpackages.com/badges/stenin-nikita-php-yacc/health.svg)](https://phpackages.com/packages/stenin-nikita-php-yacc)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
