3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ILexer { /** * return associative array containing tokens for parser * @param string $input code to tokenize * @return array */ public function tokenize($input); } interface INameValidator { /** * Checks if name is valid. In a case of failure trigger syntax error. * @param string $name * @return void */ public function validate($name); } interface IParser { /** * Sets array of keywords. * @param array $keywords associative array where key is keyword and value respective php instruction. * @return void */ public function setKeywords(array $keywords); /** * Parses code. Checks for syntax errors. * If no error occurs returns data for compiler to assemble php class * otherwise trigger syntax error. * @param string $input code to parse. * @return array IParserResult */ public function parse($input); } interface IParseResult { public function getDefinition(); public function getName(); public function getConstants(); } interface ICompiler { /** * Compiles enum into valid php class * @param string $input code to compile. * @return string */ public function compile($input); } interface IErrorManager { /** * Triggers fatal error. * @param string $message error message * @return void */ public function ariseFatal($message); /** * Triggers warning. * @param string $message error message * @return void */ public function ariseWarning($message); /** * Triggers notice. * @param string $message error message * @return void */ public function ariseNotice($message); } //I know this lexer sucks. class Lexer extends CompilerElement implements ILexer { // Potential hidden dependency private $specialChars = array( '{' => 'start_body', '}' => 'end_body' ); public function tokenize($input) { if (!is_string($input)) { $this->getErrorManager()->ariseFatal(get_class($this).'::parse expects parameter 1 to be string. '.gettype($input).' given.'); } $tokens = array(); $token = $this->getEmptyToken(); $tokenMetadata = $this->getDefaultTokenMetadata(); $inputLength = strlen($input); for ($i = 0; $i < $inputLength; $i++) { $current = $input[$i]; //check if special character if (isset($this->specialChars[$current])) { $token[$this->specialChars[$current]] = $current; if ($i !== $inputLength - 1) continue; } if (isset($token['end_body'])) { $tokens[] = $token; $token = $this->getEmptyToken(); $tokenMetadata = $this->getDefaultTokenMetadata(); if ($i === $inputLength - 1) continue; } $isWhitespace = ctype_space($current); if (isset($token['start_body'])) { //skip if whitespace if ($isWhitespace) { continue; } if ($current === ',') { $tokenMetadata['newItem'] = true; $tokenMetadata['newItemNameResolved'] = false; continue; } if ($current === '=') { $tokenMetadata['newItemNameResolved'] = true; continue; } if ($tokenMetadata['newItem']) { $token['e_'.$current] = null; $tokenMetadata['newItem'] = false; } else { end($token); $lastKey = key($token); if (!$tokenMetadata['newItemNameResolved']) { unset($token[$lastKey]); $token[$lastKey.$current] = null; } else { $token[$lastKey] .= $current; } } continue; } if (!$tokenMetadata['typeResolved']) { if ($isWhitespace) { if (strlen($token['type']) === 0) { continue; } else { $tokenMetadata['typeResolved'] = true; } } else { $token['type'] .= $current; } } else if (!$tokenMetadata['nameResolved']) { if ($isWhitespace) { if (strlen($token['name']) === 0) { continue; } else { $tokenMetadata['nameResolved'] = true; } } else { $token['name'] .= $current; } } } return $tokens; } private function getEmptyToken() { return array( 'type' => '', 'name' => '' ); } private function getDefaultTokenMetadata() { return array( 'typeResolved' => false, 'nameResolved' => false, 'newItem' => true, 'newItemNameResolved' => false ); } public function __construct(IErrorManager $errorManager) { parent::__construct($errorManager); } } class NameValidator extends CompilerElement implements INameValidator { private $allowedChars; public function validate($name) { if (!is_string($name)) { $this->getErrorManager()->ariseFatal(get_class($this).'::validate expects parameter 1 to be string. '.gettype($name).' given.'); } $nameLength = strlen($name); for ($i = 0; $i < $nameLength; $i++) { $current = $name[$i]; if ($i === 0 && !ctype_alpha($current)) { $this->getErrorManager()->ariseFatal('Name should start with alphabetic characters. Given name '.$name.' starts with: '.$current); } if (!in_array(strtolower($current), $this->allowedChars, true)) { $this->getErrorManager()->ariseFatal('Unexpected character '.$current.' in name '.$name.'.'); } } } public function __construct(IErrorManager $errorManager) { parent::__construct($errorManager); // Yes, I hate that everything is allowed as name in php. $this->allowedChars = str_split('abcdefghijklmnopqrstuvwxyz0123456789'); } } class Parser extends CompilerElement implements IParser { private $lexer; private $nameValidator; private $keywords = array(); public function setKeywords(array $keywords) { $this->keywords = $keywords; } public function parse($input) { if (!is_string($input)) { $this->getErrorManager()->ariseFatal(get_class($this).'::parse expects parameter 1 to be string. '.gettype($input).' given.'); } $input = $this->cleanUp($input); $errorManager = $this->getErrorManager(); $allTokens = $this->lexer->tokenize($input); $result = array(); $currentResult = null; $processingBody = false; foreach ($allTokens as $tokens) { foreach ($tokens as $token => $tokenValue) { switch ($token) { case 'type': if ($currentResult !== null || !isset($this->keywords[$tokenValue])) { $errorManager->ariseFatal('Syntax error. Unexpected '.$tokenValue); } $currentResult = new ParseResult($this->keywords[$tokenValue], $errorManager); break; case 'name': if ($currentResult === null) { $errorManager->ariseFatal('Syntax error. Unexpected '.$tokenValue); } $this->nameValidator->validate($tokenValue); $currentResult->setName($tokenValue); break; case 'start_body': if ($currentResult === null || $currentResult->getName() === null) { $errorManager->ariseFatal('Syntax error. Unexpected '.$tokenValue); } $processingBody = true; break; case 'end_body': if ($currentResult === null || $currentResult->getName() === null || $processingBody === false) { $errorManager->ariseFatal('Syntax error. Unexpected '.$tokenValue); } $result[] = $currentResult; $currentResult = null; $processingBody = false; break; default: if ($processingBody === true && $currentResult !== null) { $name = ltrim($token, 'e_'); $this->nameValidator->validate($name); if ($tokenValue === null) { $constants = $currentResult->getConstants(); $last = end($constants); $value = ($last !== false) ? $last + 1 : 0; } else { $value = $tokenValue; } $currentResult->setItem($name, $value); } else { $errorManager->ariseFatal('Syntax error. Unexpected '.$tokenValue); } break; } } } return $result; } private function cleanUp($input) { return trim($input); } public function __construct(ILexer $lexer, INameValidator $nameValidator, IErrorManager $errorManager) { parent::__construct($errorManager); $this->lexer = $lexer; $this->nameValidator = $nameValidator; } } class ParseResult extends CompilerElement implements IParseResult { private $definition; private $name; private $constants = array(); public function getDefinition() { return $this->definition; } public function getName() { return $this->name; } public function getConstants() { return $this->constants; } public function setItem($name, $value) { if (!is_string($name)) { $this->getErrorManager()->ariseFatal('Enumeration item name can only be string.'); } if (!is_numeric($value)) { $this->getErrorManager()->ariseFatal('Enumeration item can only hold numeric value.'); } $this->constants[$name] = (ctype_digit($value) === true) ? (int)$value : (double)$value; } public function setName($name) { if (!is_string($name)) { $this->getErrorManager()->ariseFatal(get_class($this).'::setName expects parameter 1 to be string. '.gettype($name).' given.'); } $this->name = $name; } public function __construct($definition, IErrorManager $errorManager) { parent::__construct($errorManager); if (!is_string($definition)) { $this->getErrorManager()->ariseFatal(get_class($this).'::__construct expects parameter 1 to be string. '.gettype($definition).' given.'); } $this->definition = $definition; } } abstract class CompilerElement { private $errorManager; protected function getErrorManager() { return $this->errorManager; } protected function __construct(IErrorManager $errorManager) { $this->errorManager = $errorManager; } } class Enum2PhpCompiler implements ICompiler { const INDENTATION_CHAR = "\t"; private $parser; public function compile($input) { $parseResult = $this->parser->parse($input); $return = ''; foreach ($parseResult as $result) { $return .= $this->generateClass($result); } return $return; } private function generateClass(IParseResult $parseResult) { $return = $parseResult->getDefinition().' '.$parseResult->getName().' {'.PHP_EOL; foreach ($parseResult->getConstants() as $name => $value) { $return .= Enum2PhpCompiler::INDENTATION_CHAR.'const '.$name.' = '.$value.';'.PHP_EOL; } $return .= Enum2PhpCompiler::INDENTATION_CHAR.'private function __construct() {}'.PHP_EOL; $return .= '}'.PHP_EOL; return $return; } public function __construct(IParser $parser) { $this->parser = $parser; $this->parser->setKeywords(array('enum' => 'final class')); } } class ErrorManager implements IErrorManager { public function ariseFatal($message) { $this->triggerError($message, E_USER_ERROR); } public function ariseWarning($message) { $this->triggerError($message, E_USER_WARNING); } public function ariseNotice($message) { $this->triggerError($message, E_USER_NOTICE); } private function triggerError($message, $type) { trigger_error((string)$message, (int)$type); } } $errorManager = ErrorManager(); $nameValidator = NameValidator($errorManager); $lexer = new Lexer($errorManager); $parser = new Parser($lexer, $nameValidator, $errorManager); $compiler = new Enum2PhpCompiler($parser); $enum = <<<PHP enum MyEnum { Item1 = 1, Item2 = 5, Item3 } enum AnotherEnum { Item } PHP; eval($compiler->compile($enum)); var_dump(MyEnum::Item1, MyEnum::Item2, MyEnum::Item3, AnotherEnum::Item);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  (null)
number of ops:  43
compiled vars:  !0 = $errorManager, !1 = $nameValidator, !2 = $lexer, !3 = $parser, !4 = $compiler, !5 = $enum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   DECLARE_CLASS                                            'lexer', 'compilerelement'
  196     1        DECLARE_CLASS                                            'namevalidator', 'compilerelement'
  226     2        DECLARE_CLASS                                            'parser', 'compilerelement'
  320     3        DECLARE_CLASS                                            'parseresult', 'compilerelement'
  379     4        DECLARE_CLASS                                            'enum2phpcompiler'
  415     5        DECLARE_CLASS                                            'errormanager'
  433     6        INIT_FCALL_BY_NAME                                       'ErrorManager'
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !0, $6
  434     9        INIT_FCALL_BY_NAME                                       'NameValidator'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !1, $8
  435    13        NEW                                              $10     'Lexer'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $10
  436    17        NEW                                              $13     'Parser'
         18        SEND_VAR_EX                                              !2
         19        SEND_VAR_EX                                              !1
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !3, $13
  437    23        NEW                                              $16     'Enum2PhpCompiler'
         24        SEND_VAR_EX                                              !3
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !4, $16
  439    27        ASSIGN                                                   !5, '%09enum+MyEnum+%7B%0A%09%09Item1+%3D+1%2C%0A%09%09Item2+%3D+5%2C%0A%09%09Item3%0A%09%7D%0A%0A%09enum+AnotherEnum+%7B%0A%09++++Item%0A%09%7D'
  451    28        INIT_METHOD_CALL                                         !4, 'compile'
         29        SEND_VAR_EX                                              !5
         30        DO_FCALL                                      0  $20     
         31        INCLUDE_OR_EVAL                                          $20, EVAL
  453    32        INIT_FCALL                                               'var_dump'
         33        FETCH_CLASS_CONSTANT                             ~22     'MyEnum', 'Item1'
         34        SEND_VAL                                                 ~22
         35        FETCH_CLASS_CONSTANT                             ~23     'MyEnum', 'Item2'
         36        SEND_VAL                                                 ~23
         37        FETCH_CLASS_CONSTANT                             ~24     'MyEnum', 'Item3'
         38        SEND_VAL                                                 ~24
         39        FETCH_CLASS_CONSTANT                             ~25     'AnotherEnum', 'Item'
         40        SEND_VAL                                                 ~25
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Class ILexer:
Function tokenize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  tokenize
number of ops:  2
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function tokenize

End of class ILexer.

Class INameValidator:
Function validate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  validate
number of ops:  2
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function validate

End of class INameValidator.

Class IParser:
Function setkeywords:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  setKeywords
number of ops:  2
compiled vars:  !0 = $keywords
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function setkeywords

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  parse
number of ops:  2
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function parse

End of class IParser.

Class IParseResult:
Function getdefinition:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  getDefinition
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E > > RETURN                                                   null

End of function getdefinition

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  getName
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E > > RETURN                                                   null

End of function getname

Function getconstants:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  getConstants
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E > > RETURN                                                   null

End of function getconstants

End of class IParseResult.

Class ICompiler:
Function compile:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  compile
number of ops:  2
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function compile

End of class ICompiler.

Class IErrorManager:
Function arisefatal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  ariseFatal
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function arisefatal

Function arisewarning:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  ariseWarning
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function arisewarning

Function arisenotice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  ariseNotice
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function arisenotice

End of class IErrorManager.

Class Lexer:
Function tokenize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 131
Branch analysis from position: 131
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 26
Branch analysis from position: 133
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 39
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 26
Branch analysis from position: 133
Branch analysis from position: 26
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 53
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 99
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 61
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 68
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 73
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 81
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 96
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 115
Branch analysis from position: 102
2 jumps found. (Code = 43) Position 1 = 103, Position 2 = 112
Branch analysis from position: 103
2 jumps found. (Code = 43) Position 1 = 107, Position 2 = 109
Branch analysis from position: 107
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 109
1 jumps found. (Code = 42) Position 1 = 114
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 115
2 jumps found. (Code = 43) Position 1 = 118, Position 2 = 130
Branch analysis from position: 118
2 jumps found. (Code = 43) Position 1 = 119, Position 2 = 128
Branch analysis from position: 119
2 jumps found. (Code = 43) Position 1 = 123, Position 2 = 125
Branch analysis from position: 123
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 128
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 26
Branch analysis from position: 133
Branch analysis from position: 26
Branch analysis from position: 130
Branch analysis from position: 53
Branch analysis from position: 39
Branch analysis from position: 15
filename:       /in/QSkf7
function name:  tokenize
number of ops:  135
compiled vars:  !0 = $input, !1 = $tokens, !2 = $token, !3 = $tokenMetadata, !4 = $inputLength, !5 = $i, !6 = $current, !7 = $isWhitespace, !8 = $lastKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
   84     1        TYPE_CHECK                                   64  ~9      !0
          2        BOOL_NOT                                         ~10     ~9
          3      > JMPZ                                                     ~10, ->15
   85     4    >   INIT_METHOD_CALL                                         'getErrorManager'
          5        DO_FCALL                                      0  $11     
          6        INIT_METHOD_CALL                                         $11, 'ariseFatal'
          7        FETCH_THIS                                       ~12     
          8        GET_CLASS                                        ~13     ~12
          9        CONCAT                                           ~14     ~13, '%3A%3Aparse+expects+parameter+1+to+be+string.+'
         10        GET_TYPE                                         ~15     !0
         11        CONCAT                                           ~16     ~14, ~15
         12        CONCAT                                           ~17     ~16, '+given.'
         13        SEND_VAL_EX                                              ~17
         14        DO_FCALL                                      0          
   88    15    >   ASSIGN                                                   !1, <array>
   89    16        INIT_METHOD_CALL                                         'getEmptyToken'
         17        DO_FCALL                                      0  $20     
         18        ASSIGN                                                   !2, $20
   90    19        INIT_METHOD_CALL                                         'getDefaultTokenMetadata'
         20        DO_FCALL                                      0  $22     
         21        ASSIGN                                                   !3, $22
   91    22        STRLEN                                           ~24     !0
         23        ASSIGN                                                   !4, ~24
   93    24        ASSIGN                                                   !5, 0
         25      > JMP                                                      ->131
   94    26    >   FETCH_DIM_R                                      ~27     !0, !5
         27        ASSIGN                                                   !6, ~27
   97    28        FETCH_OBJ_IS                                     ~29     'specialChars'
         29        ISSET_ISEMPTY_DIM_OBJ                         0          ~29, !6
         30      > JMPZ                                                     ~30, ->39
   98    31    >   FETCH_OBJ_R                                      ~31     'specialChars'
         32        FETCH_DIM_R                                      ~32     ~31, !6
         33        ASSIGN_DIM                                               !2, ~32
         34        OP_DATA                                                  !6
  100    35        SUB                                              ~34     !4, 1
         36        IS_NOT_IDENTICAL                                         !5, ~34
         37      > JMPZ                                                     ~35, ->39
  101    38    > > JMP                                                      ->130
  104    39    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'end_body'
         40      > JMPZ                                                     ~36, ->53
  105    41    >   ASSIGN_DIM                                               !1
         42        OP_DATA                                                  !2
  106    43        INIT_METHOD_CALL                                         'getEmptyToken'
         44        DO_FCALL                                      0  $38     
         45        ASSIGN                                                   !2, $38
  107    46        INIT_METHOD_CALL                                         'getDefaultTokenMetadata'
         47        DO_FCALL                                      0  $40     
         48        ASSIGN                                                   !3, $40
  109    49        SUB                                              ~42     !4, 1
         50        IS_IDENTICAL                                             !5, ~42
         51      > JMPZ                                                     ~43, ->53
  110    52    > > JMP                                                      ->130
  113    53    >   INIT_FCALL                                               'ctype_space'
         54        SEND_VAR                                                 !6
         55        DO_ICALL                                         $44     
         56        ASSIGN                                                   !7, $44
  115    57        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'start_body'
         58      > JMPZ                                                     ~46, ->99
  117    59    > > JMPZ                                                     !7, ->61
  118    60    > > JMP                                                      ->130
  121    61    >   IS_IDENTICAL                                             !6, '%2C'
         62      > JMPZ                                                     ~47, ->68
  122    63    >   ASSIGN_DIM                                               !3, 'newItem'
         64        OP_DATA                                                  <true>
  123    65        ASSIGN_DIM                                               !3, 'newItemNameResolved'
         66        OP_DATA                                                  <false>
  124    67      > JMP                                                      ->130
  126    68    >   IS_IDENTICAL                                             !6, '%3D'
         69      > JMPZ                                                     ~50, ->73
  127    70    >   ASSIGN_DIM                                               !3, 'newItemNameResolved'
         71        OP_DATA                                                  <true>
  128    72      > JMP                                                      ->130
  131    73    >   FETCH_DIM_R                                      ~52     !3, 'newItem'
         74      > JMPZ                                                     ~52, ->81
  132    75    >   CONCAT                                           ~53     'e_', !6
         76        ASSIGN_DIM                                               !2, ~53
         77        OP_DATA                                                  null
  133    78        ASSIGN_DIM                                               !3, 'newItem'
         79        OP_DATA                                                  <false>
         80      > JMP                                                      ->98
  135    81    >   INIT_FCALL                                               'end'
         82        SEND_REF                                                 !2
         83        DO_ICALL                                                 
  136    84        INIT_FCALL                                               'key'
         85        SEND_VAR                                                 !2
         86        DO_ICALL                                         $57     
         87        ASSIGN                                                   !8, $57
  138    88        FETCH_DIM_R                                      ~59     !3, 'newItemNameResolved'
         89        BOOL_NOT                                         ~60     ~59
         90      > JMPZ                                                     ~60, ->96
  139    91    >   UNSET_DIM                                                !2, !8
  140    92        CONCAT                                           ~61     !8, !6
         93        ASSIGN_DIM                                               !2, ~61
         94        OP_DATA                                                  null
         95      > JMP                                                      ->98
  142    96    >   ASSIGN_DIM_OP                .=               8          !2, !8
         97        OP_DATA                                                  !6
  146    98    > > JMP                                                      ->130
  149    99    >   FETCH_DIM_R                                      ~64     !3, 'typeResolved'
        100        BOOL_NOT                                         ~65     ~64
        101      > JMPZ                                                     ~65, ->115
  150   102    > > JMPZ                                                     !7, ->112
  151   103    >   FETCH_DIM_R                                      ~66     !2, 'type'
        104        STRLEN                                           ~67     ~66
        105        IS_IDENTICAL                                             ~67, 0
        106      > JMPZ                                                     ~68, ->109
  152   107    > > JMP                                                      ->130
        108*       JMP                                                      ->111
  154   109    >   ASSIGN_DIM                                               !3, 'typeResolved'
        110        OP_DATA                                                  <true>
        111      > JMP                                                      ->114
  157   112    >   ASSIGN_DIM_OP                .=               8          !2, 'type'
        113        OP_DATA                                                  !6
        114    > > JMP                                                      ->130
  159   115    >   FETCH_DIM_R                                      ~71     !3, 'nameResolved'
        116        BOOL_NOT                                         ~72     ~71
        117      > JMPZ                                                     ~72, ->130
  160   118    > > JMPZ                                                     !7, ->128
  161   119    >   FETCH_DIM_R                                      ~73     !2, 'name'
        120        STRLEN                                           ~74     ~73
        121        IS_IDENTICAL                                             ~74, 0
        122      > JMPZ                                                     ~75, ->125
  162   123    > > JMP                                                      ->130
        124*       JMP                                                      ->127
  164   125    >   ASSIGN_DIM                                               !3, 'nameResolved'
        126        OP_DATA                                                  <true>
        127      > JMP                                                      ->130
  167   128    >   ASSIGN_DIM_OP                .=               8          !2, 'name'
        129        OP_DATA                                                  !6
   93   130    >   PRE_INC                                                  !5
        131    >   IS_SMALLER                                               !5, !4
        132      > JMPNZ                                                    ~79, ->26
  172   133    > > RETURN                                                   !1
  173   134*     > RETURN                                                   null

End of function tokenize

Function getemptytoken:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  getEmptyToken
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  177     0  E > > RETURN                                                   <array>
  180     1*     > RETURN                                                   null

End of function getemptytoken

Function getdefaulttokenmetadata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  getDefaultTokenMetadata
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  184     0  E > > RETURN                                                   <array>
  189     1*     > RETURN                                                   null

End of function getdefaulttokenmetadata

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSkf7
function name:  __construct
number of ops:  5
compiled vars:  !0 = $errorManager
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  191     0  E >   RECV                                             !0      
  192     1        INIT_STATIC_METHOD_CALL                                  
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
  193     4      > RETURN                                                   null

End of function __construct

End of class Lexer.

Class NameValidator:
Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 19
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 37
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 57
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 19
Branch analysis from position: 60
Branch analysis from position: 19
Branch analysis from position: 57
Branch analysis from position: 37
Branch analysis from position: 28
Branch analysis from position: 15
filename:       /in/QSkf7
function name:  validate
number of ops:  61
compiled vars:  !0 = $name, !1 = $nameLength, !2 = $i, !3 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  199     0  E >   RECV                                             !0      
  200     1        TYPE_CHECK                                   64  ~4      !0
          2        BOOL_NOT                                         ~5      ~4
          3      > JMPZ                                                     ~5, ->15
  201     4    >   INIT_METHOD_CALL                                         'getErrorManager'
          5        DO_FCALL                                      0  $6      
          6        INIT_METHOD_CALL                                         $6, 'ariseFatal'
          7        FETCH_THIS                                       ~7      
          8        GET_CLASS                                        ~8      ~7
          9        CONCAT                                           ~9      ~8, '%3A%3Avalidate+expects+parameter+1+to+be+string.+'
         10        GET_TYPE                                         ~10     !0
         11        CONCAT                                           ~11     ~9, ~10
         12        CONCAT                                           ~12     ~11, '+given.'
         13        SEND_VAL_EX                                              ~12
         14        DO_FCALL                                      0          
  204    15    >   STRLEN                                           ~14     !0
         16        ASSIGN                                                   !1, ~14
  206    17        ASSIGN                                                   !2, 0
         18      > JMP                                                      ->58
  207    19    >   FETCH_DIM_R                                      ~17     !0, !2
         20        ASSIGN                                                   !3, ~17
  209    21        IS_IDENTICAL                                     ~19     !2, 0
         22      > JMPZ_EX                                          ~19     ~19, ->28
         23    >   INIT_FCALL                                               'ctype_alpha'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $20     
         26        BOOL_NOT                                         ~21     $20
         27        BOOL                                             ~19     ~21
         28    > > JMPZ                                                     ~19, ->37
  210    29    >   INIT_METHOD_CALL                                         'getErrorManager'
         30        DO_FCALL                                      0  $22     
         31        INIT_METHOD_CALL                                         $22, 'ariseFatal'
         32        CONCAT                                           ~23     'Name+should+start+with+alphabetic+characters.+Given+name+', !0
         33        CONCAT                                           ~24     ~23, '+starts+with%3A+'
         34        CONCAT                                           ~25     ~24, !3
         35        SEND_VAL_EX          

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.59 ms | 1428 KiB | 23 Q