if (preg_match($regex, $string, $matches, null, $offset)) { $tokenDetails = new stdClass(); $tokenDetails->token = $token; $tokenDetails->value = trim($matches[0]); $tokens[] = $tokenDetails; $offset += strlen($matches[0]); continue 2; } } throw new Exception(sprintf('Unexpected character: >%s< offset >%d<', $string[$offset], $offset)); } $eofToken = new stdClass(); $eofToken->token = Token::EOF; $eofToken->value = 'eof'; $tokens[] = $eofToken; return $tokens; } } $params = ' int $age int[] $ages object $agent { string $name int $count }'; $tokenizer = new Tokenizer(); $tokens = $tokenizer->lex($params); $tree = new Parser($tokens); echo 'Param: ' . $params . PHP_EOL; print_r($tree->S()); echo '===' . PHP_EOL;