PHPackages                             vovan-ve/lr0-parser - 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. vovan-ve/lr0-parser

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

vovan-ve/lr0-parser
===================

LR(0) parser with state table generator for any LR(0) grammar

v2.0.1(7y ago)21031MITPHPPHP ^7.1

Since Jul 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Vovan-VE/parser)[ Packagist](https://packagist.org/packages/vovan-ve/lr0-parser)[ RSS](/packages/vovan-ve-lr0-parser/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (3)Versions (31)Used By (1)

LR(0) parser
============

[](#lr0-parser)

[![Latest Stable Version](https://camo.githubusercontent.com/e387b5c52dbf33b340c2a9cf31d359b54c9618a180ed8ab3edde4d42e3c0cd71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766f76616e2d76652f6c72302d7061727365722e737667)](https://packagist.org/packages/vovan-ve/lr0-parser)[![Latest Dev Version](https://camo.githubusercontent.com/d1cb9f7fda9fb278aa8799d2db5e3fe64d24f8ee21b975a01efaf2c9792eeb92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f766f76616e2d76652f6c72302d7061727365722e737667)](https://packagist.org/packages/vovan-ve/lr0-parser)[![Build Status](https://camo.githubusercontent.com/8fa1d7396d3e751f0c71e70c0981cbee3f0dd8f70a5aa8efea789204dd976a3d/68747470733a2f2f7472617669732d63692e6f72672f566f76616e2d56452f7061727365722e737667)](https://travis-ci.org/Vovan-VE/parser)[![License](https://camo.githubusercontent.com/1a84a490866d3c75fe8eb2921885720bc248112a33a7efcc650859128b22b3f9/68747470733a2f2f706f7365722e707567782e6f72672f766f76616e2d76652f6c72302d7061727365722f6c6963656e7365)](https://packagist.org/packages/vovan-ve/lr0-parser)

This package contains [LR(0) parser](https://en.wikipedia.org/wiki/LR_parser) to parse texts according to custom LR(0) grammar.

Synopsis
--------

[](#synopsis)

See also following example in [examples/](examples/).

```
use VovanVE\parser\actions\ActionsMadeMap;
use VovanVE\parser\Parser;

$grammar =  function ($content) { return (int)$content; },

    'Value' => Parser::ACTION_BUBBLE_THE_ONLY,
    'Value(neg)' => function ($v) { return -$v; },

    'Product(V)' => Parser::ACTION_BUBBLE_THE_ONLY,
    'Product(mul)' => function ($a, $b) { return $a * $b; },
    'Product(div)' => function ($a, $b) { return $a / $b; },

    'Sum(P)' => Parser::ACTION_BUBBLE_THE_ONLY,
    'Sum(add)' => function ($a, $b) { return $a + $b; },
    'Sum(sub)' => function ($a, $b) { return $a - $b; },
]);

$tree = $parser->parse('2 * (-10 + 33) - 4', $actions);

echo 'Result is ', $tree->made(), PHP_EOL;
echo 'Tree:', PHP_EOL;
echo $tree->dumpAsString();
```

Output:

```
Result is 42
Tree:
 `- Sum(sub)
     `- Sum(P)
     |   `- Product(mul)
     |       `- Product(V)
     |       |   `- Value
     |       |       `- int
     |       `- Value
     |           `- Sum(add)
     |               `- Sum(P)
     |               |   `- Product(V)
     |               |       `- Value(neg)
     |               |           `- Value
     |               |               `- int
     |               `- Product(V)
     |                   `- Value
     |                       `- int
     `- Product(V)
         `- Value
             `- int

```

Description
-----------

[](#description)

This package contains:

- Lexer to parse input string into tokens. There is separate Lexer configurable by regexps.
- Grammar object to describe a grammar of a language.
- Parsing table to let parser to switch states with respect to grammar.
- LR(0) parser itself. It parse input string for AST using the table.

First this package was made just to apply the theory in practice. It may easily be used for small grammars to parse small source codes. But later I did apply it in my another package.

Installation
------------

[](#installation)

Install through [composer](http://getcomposer.org/):

```
composer require vovan-ve/lr0-parser

```

or add to `require` section in your composer.json:

```
"vovan-ve/lr0-parser": "~2.0.0"

```

Theory
------

[](#theory)

[LR parser](https://en.wikipedia.org/wiki/LR_parser).

License
-------

[](#license)

This package is under [MIT License](https://opensource.org/licenses/MIT)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~2 days

Total

28

Last Release

2801d ago

Major Versions

v1.7.0 → v2.0.02018-10-29

PHP version history (2 changes)v1.0.0PHP &gt;=5.5

v2.0.0PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1166581?v=4)[Vladimir](/maintainers/Vovan-VE)[@Vovan-VE](https://github.com/Vovan-VE)

---

Top Contributors

[![Vovan-VE](https://avatars.githubusercontent.com/u/1166581?v=4)](https://github.com/Vovan-VE "Vovan-VE (164 commits)")

---

Tags

grammarlexerlr-parser

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vovan-ve-lr0-parser/health.svg)

```
[![Health](https://phpackages.com/badges/vovan-ve-lr0-parser/health.svg)](https://phpackages.com/packages/vovan-ve-lr0-parser)
```

###  Alternatives

[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k34.1M146](/packages/cebe-markdown)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M42](/packages/mck89-peast)[dallgoot/yaml

Provides loader, dumper and an API for YAML content. Loader builds to equivalent data types in PHP 8.x

42233.1k9](/packages/dallgoot-yaml)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[softark/creole

Creole Wiki parser for PHP extended from cebe/markdown

1446.3k2](/packages/softark-creole)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)

PHPackages © 2026

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