$ composer require --dev phplrt/phplrt
The built-in tools allow you to easily implement a complete and powerful lexer using the PCRE2 regular expression language.
$lexer->lex('23+42');
The phplrt toolkit provides an EBNF-like grammar compiler based on the Hoa library, which in turn has been expanded and improved.
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>