[EXPERIMENT] PHP Base Compiler(Lexical Analyzer).
composer require wandu/compiler
Example.
$lexer = new \Wandu\Compiler\LexicalAnalyzer([
'\\+' => function () {
return 't_add';
},
'\\-' => function () {
return 't_minus';
},
'\\*' => function () {
return 't_multi';
},
'\\/' => function () {
return 't_divide';
},
'\\=' => function () {
return 't_equal';
},
'[1-9][0-9]*|0([0-7]+|(x|X)[0-9A-Fa-f]*)?' => function ($word) {
return "t_number";
},
'\s' => null,
]);
$lexer->analyze('10 + 20 = 0')); // ['t_number', 't_add', 't_number', 't_equal', 't_number',]