Language Recognition Tool

for PHP

$ composer require --dev 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
  : BinaryExpression()

BinaryExpression
  : AdditiveExpression()

AdditiveExpression -> {
    return new AdditionOrSubtraction(...);
}
  : (MultiplicativeExpression() (<T_PLUS> | <T_MINUS>))*
    MultiplicativeExpression()

MultiplicativeExpression -> {
    return new MultiplicationOrDivision(...);
}
  : (UnaryExpression() (<T_DIV> | <T_MUL>))*
    UnaryExpression()

UnaryExpression
  : ::T_BRACE_OPEN:: Expression() ::T_BRACE_CLOSE::
  | Literal()

Literal -> { return new Literal(...); }
  : <T_FLOAT>
  | <T_INT>

            
Learn More