Language Recognition Tool

for PHP

$ composer require phplrt/phplrt

Lexical Analysis

The built-in tools allow you to easily implement a complete and powerful lexer using the PCRE2 regular expression language.

$lexer->lex('23+42');
23
+
42
Learn More

Parser

The phplrt toolkit provides an EBNF-like grammar compiler based on the Hoa library, which in turn has been expanded and improved.

try it in action:

Expression: Addition() | Subtraction() | Term()

Term: Multiplication() | Division() | Factor()

Factor
  : ::T_BRACE_OPEN:: Expression() ::T_BRACE_CLOSE::
  | Value()

Subtraction ->
{ return new Ast\Subtraction($children, $offset); }
  : Term() ::T_MINUS:: Expression()

Addition ->
{ return new Ast\Addition($children, $offset); }
  : Term() ::T_PLUS:: Expression()

Multiplication ->
{ return new Ast\Multiplication($children, $offset); }
  : Factor() ::T_MUL:: Term()
  | Factor() Term()

Division ->
{ return new Ast\Division($children, $offset); }
  : Factor() ::T_DIV:: Term()

Value ->
{ return new Ast\Value($children, $offset); }
  : <T_FLOAT> | <T_INT>

            
Learn More