wandu/compiler

This package is abandoned and no longer maintained. No replacement package was suggested.

[EXPERIMENT] PHP Base Compiler(Lexical Analyzer).

v3.0.4 2016-10-25 16:33 UTC

README

Latest Stable Version Latest Unstable Version Total Downloads License

[EXPERIMENT] PHP Base Compiler(Lexical Analyzer).

Installation

composer require wandu/compiler

Useage

LexicalAnalyzer

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',]

References