public function testAnalyze()
 {
     $result = '';
     $lexer = new 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) use(&$result) {
         $result .= $word;
         return "t_number";
     }, '\\s' => null]);
     $this->assertEquals(['t_number', 't_add', 't_number', 't_equal', 't_number'], $lexer->analyze('10 + 20 = 0'));
     $this->assertEquals('10200', $result);
 }
Beispiel #2
0
 public function analyze($context)
 {
     // get lex tokens
     $predefinedTokens = array_flip($this->tokens);
     $lexTokens = array_map(function ($lexToken) use($predefinedTokens) {
         if ($lexToken instanceof Token) {
             return $lexToken;
         }
         if (isset($predefinedTokens[$lexToken])) {
             return new Token($lexToken);
         }
         throw new UnknownTokenFromLexException($lexToken);
     }, $this->lexer->analyze($context));
     // get FIRST
     //        print_r($this->syntaxes);
     // get FOLLOW
     // get LOOKAHEAD
     // with null
     //
     $parsingTables = [];
     // [NO_STATES][NO_SYMBOLS + 1]
     //        print_r($lexTokens);
     return '';
 }