3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface IErrorManager { public function ariseFatal($message); public function ariseWarning($message); public function ariseNotice($message); } interface ILexer { public function getTokens(); public function tokenize($input); } interface IParser { public function parse($input); } interface IParseResult { public function getDefintion(); public function getName(); public function getConstants(); } interface ICompiler { public function compile($input); } class ErrorManager implements IErrorManager { public function ariseFatal($message) { $this->triggerError($message, E_USER_FATAL); } 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); } } abstract class CompilerElement { private $errorManager; protected function getErrorManager() { return $this->errorManager; } protected function __construct(IErrorManager $errorManager) { $this->errorManager = $errorManager; } } class Lexer extends CompilerElement implements ILexer { private $tokens = array(); public function getTokens() { return $this->tokens; } public function tokenize($input) { if (!is_string($input)) { $this->getErrorManager()->ariseFatal(get_class($this).'::parse expects parameter 1 to be string. '.gettype($input).' given.'); } } public function __construct(IErrorManager $errorManager) { parent::__construct($errorManager); } } class Parser extends CompilerElement implements IParser { private $lexer; public function parse($input) { if (!is_string($input)) { $this->getErrorManager()->ariseFatal(get_class($this).'::parse expects parameter 1 to be string. '.gettype($input).' given.'); } } public function __construct(ILexer $lexer, IErrorManager $errorManager) { parent::__construct($errorManager); $this->lexer = $lexer; } } class ParseResult extends CompilerElement implements IParseResult { private $definition; private $name; private $constants; public function getDefinition() { return $this->definition; } public function getName() { return $this->name; } public function getConstants() { return $this->constants; } public function __construct($definition, $name, array $constants, 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.'); } if (!is_string($name)) { $this->getErrorManager()->ariseFatal(get_class($this).'::__construct expects parameter 2 to be string. '.gettype($name).' given.'); } $this->definition = $definition; $this->name = $name; $this->constants = $constants; } } class Compiler implements ICompiler { private $parser; const INTENDATION_CHAR = "\t"; public function compile($input) { $parseResult = $this->parser->parse($input); $return = $parseResult->getDefinition().' '.$parseResult->getName().' {'.PHP_EOL; foreach ($parseResult->getConstants() as $name => $value) { $return .= Compiler::INTENDATION_CHAR.'const '.$name.' = '.$value.PHP_EOL; } $return .= Compiler::INTENDATION_CHAR.'private function __construct() {}'.PHP_EOL; $return .= '}'; return $return; } public function __construct(IParser $parser) { $this->parser = $parser; } } $enumCode =<<< PHP enum MyEnum { Item1, Item2, Item3 } PHP;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  (null)
number of ops:  7
compiled vars:  !0 = $enumCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   DECLARE_CLASS                                            'errormanager'
   57     1        DECLARE_CLASS                                            'lexer', 'compilerelement'
   75     2        DECLARE_CLASS                                            'parser', 'compilerelement'
   91     3        DECLARE_CLASS                                            'parseresult', 'compilerelement'
  124     4        DECLARE_CLASS                                            'compiler'
  148     5        ASSIGN                                                   !0, '++++enum+MyEnum+%7B%0A++++++++Item1%2C+Item2%2C+Item3%0A++++%7D'
  152     6      > RETURN                                                   1

Class IErrorManager:
Function arisefatal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  ariseFatal
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     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/nS2jf
function name:  ariseWarning
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     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/nS2jf
function name:  ariseNotice
number of ops:  2
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function arisenotice

End of class IErrorManager.

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

End of function gettokens

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

End of function tokenize

End of class ILexer.

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

End of function parse

End of class IParser.

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

End of function getdefintion

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  getName
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     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/nS2jf
function name:  getConstants
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     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/nS2jf
function name:  compile
number of ops:  2
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function compile

End of class ICompiler.

Class ErrorManager:
Function arisefatal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  ariseFatal
number of ops:  7
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_METHOD_CALL                                         'triggerError'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CONSTANT                                   ~1      'E_USER_FATAL'
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0          
   30     6      > 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/nS2jf
function name:  ariseWarning
number of ops:  6
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_METHOD_CALL                                         'triggerError'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              512
          4        DO_FCALL                                      0          
   34     5      > 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/nS2jf
function name:  ariseNotice
number of ops:  6
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        INIT_METHOD_CALL                                         'triggerError'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              1024
          4        DO_FCALL                                      0          
   38     5      > RETURN                                                   null

End of function arisenotice

Function triggererror:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  triggerError
number of ops:  9
compiled vars:  !0 = $message, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        INIT_FCALL                                               'trigger_error'
          3        CAST                                          6  ~2      !0
          4        SEND_VAL                                                 ~2
          5        CAST                                          4  ~3      !1
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                                 
   42     8      > RETURN                                                   null

End of function triggererror

End of class ErrorManager.

Class CompilerElement:
Function geterrormanager:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  getErrorManager
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      'errorManager'
          1      > RETURN                                                   ~0
   50     2*     > RETURN                                                   null

End of function geterrormanager

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  __construct
number of ops:  4
compiled vars:  !0 = $errorManager
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        ASSIGN_OBJ                                               'errorManager'
          2        OP_DATA                                                  !0
   54     3      > RETURN                                                   null

End of function __construct

End of class CompilerElement.

Class Lexer:
Function gettokens:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  getTokens
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'tokens'
          1      > RETURN                                                   ~0
   62     2*     > RETURN                                                   null

End of function gettokens

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 = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/nS2jf
function name:  tokenize
number of ops:  16
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   65     1        TYPE_CHECK                                   64  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->15
   66     4    >   INIT_METHOD_CALL                                         'getErrorManager'
          5        DO_FCALL                                      0  $3      
          6        INIT_METHOD_CALL                                         $3, 'ariseFatal'
          7        FETCH_THIS                                       ~4      
          8        GET_CLASS                                        ~5      ~4
          9        CONCAT                                           ~6      ~5, '%3A%3Aparse+expects+parameter+1+to+be+string.+'
         10        GET_TYPE                                         ~7      !0
         11        CONCAT                                           ~8      ~6, ~7
         12        CONCAT                                           ~9      ~8, '+given.'
         13        SEND_VAL_EX                                              ~9
         14        DO_FCALL                                      0          
   68    15    > > RETURN                                                   null

End of function tokenize

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

End of function __construct

End of class Lexer.

Class Parser:
Function parse:
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 = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/nS2jf
function name:  parse
number of ops:  16
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   79     1        TYPE_CHECK                                   64  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->15
   80     4    >   INIT_METHOD_CALL                                         'getErrorManager'
          5        DO_FCALL                                      0  $3      
          6        INIT_METHOD_CALL                                         $3, 'ariseFatal'
          7        FETCH_THIS                                       ~4      
          8        GET_CLASS                                        ~5      ~4
          9        CONCAT                                           ~6      ~5, '%3A%3Aparse+expects+parameter+1+to+be+string.+'
         10        GET_TYPE                                         ~7      !0
         11        CONCAT                                           ~8      ~6, ~7
         12        CONCAT                                           ~9      ~8, '+given.'
         13        SEND_VAL_EX                                              ~9
         14        DO_FCALL                                      0          
   82    15    > > RETURN                                                   null

End of function parse

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  __construct
number of ops:  8
compiled vars:  !0 = $lexer, !1 = $errorManager
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   85     2        INIT_STATIC_METHOD_CALL                                  
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
   87     5        ASSIGN_OBJ                                               'lexer'
          6        OP_DATA                                                  !0
   88     7      > RETURN                                                   null

End of function __construct

End of class Parser.

Class ParseResult:
Function getdefinition:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  getDefinition
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   FETCH_OBJ_R                                      ~0      'definition'
          1      > RETURN                                                   ~0
   98     2*     > 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/nS2jf
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
  102     2*     > 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/nS2jf
function name:  getConstants
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   FETCH_OBJ_R                                      ~0      'constants'
          1      > RETURN                                                   ~0
  106     2*     > RETURN                                                   null

End of function getconstants

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 21
filename:       /in/nS2jf
function name:  __construct
number of ops:  42
compiled vars:  !0 = $definition, !1 = $name, !2 = $constants, !3 = $errorManager
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
  109     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !3
          6        DO_FCALL                                      0          
  111     7        TYPE_CHECK                                   64  ~5      !0
          8        BOOL_NOT                                         ~6      ~5
          9      > JMPZ                                                     ~6, ->21
  112    10    >   INIT_METHOD_CALL                                         'getErrorManager'
         11        DO_FCALL                                      0  $7      
         12        INIT_METHOD_CALL                                         $7, 'ariseFatal'
         13        FETCH_THIS                                       ~8      
         14        GET_CLASS                                        ~9      ~8
         15        CONCAT                                           ~10     ~9, '%3A%3A__construct+expects+parameter+1+to+be+string.+'
         16        GET_TYPE                                         ~11     !0
         17        CONCAT                                           ~12     ~10, ~11
         18        CONCAT                                           ~13     ~12, '+given.'
         19        SEND_VAL_EX                                              ~13
         20        DO_FCALL                                      0          
  114    21    >   TYPE_CHECK                                   64  ~15     !1
         22        BOOL_NOT                                         ~16     ~15
         23      > JMPZ                                                     ~16, ->35
  115    24    >   INIT_METHOD_CALL                                         'getErrorManager'
         25        DO_FCALL                                      0  $17     
         26        INIT_METHOD_CALL                                         $17, 'ariseFatal'
         27        FETCH_THIS                                       ~18     
         28        GET_CLASS                                        ~19     ~18
         29        CONCAT                                           ~20     ~19, '%3A%3A__construct+expects+parameter+2+to+be+string.+'
         30        GET_TYPE                                         ~21     !1
         31        CONCAT                                           ~22     ~20, ~21
         32        CONCAT                                           ~23     ~22, '+given.'
         33        SEND_VAL_EX                                              ~23
         34        DO_FCALL                                      0          
  118    35    >   ASSIGN_OBJ                                               'definition'
         36        OP_DATA                                                  !0
  119    37        ASSIGN_OBJ                                               'name'
         38        OP_DATA                                                  !1
  120    39        ASSIGN_OBJ                                               'constants'
         40        OP_DATA                                                  !2
  121    41      > RETURN                                                   null

End of function __construct

End of class ParseResult.

Class Compiler:
Function compile:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/nS2jf
function name:  compile
number of ops:  31
compiled vars:  !0 = $input, !1 = $parseResult, !2 = $return, !3 = $value, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     0  E >   RECV                                             !0      
  129     1        FETCH_OBJ_R                                      ~5      'parser'
          2        INIT_METHOD_CALL                                         ~5, 'parse'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !1, $6
  131     6        INIT_METHOD_CALL                                         !1, 'getDefinition'
          7        DO_FCALL                                      0  $8      
          8        CONCAT                                           ~9      $8, '+'
          9        INIT_METHOD_CALL                                         !1, 'getName'
         10        DO_FCALL                                      0  $10     
         11        CONCAT                                           ~11     ~9, $10
         12        CONCAT                                           ~12     ~11, '+%7B'
         13        CONCAT                                           ~13     ~12, '%0A'
         14        ASSIGN                                                   !2, ~13
  133    15        INIT_METHOD_CALL                                         !1, 'getConstants'
         16        DO_FCALL                                      0  $15     
         17      > FE_RESET_R                                       $16     $15, ->26
         18    > > FE_FETCH_R                                       ~17     $16, !3, ->26
         19    >   ASSIGN                                                   !4, ~17
  134    20        CONCAT                                           ~19     '%09const+', !4
         21        CONCAT                                           ~20     ~19, '+%3D+'
         22        CONCAT                                           ~21     ~20, !3
         23        CONCAT                                           ~22     ~21, '%0A'
         24        ASSIGN_OP                                     8          !2, ~22
  133    25      > JMP                                                      ->18
         26    >   FE_FREE                                                  $16
  137    27        ASSIGN_OP                                     8          !2, '%09private+function+__construct%28%29+%7B%7D%0A'
  138    28        ASSIGN_OP                                     8          !2, '%7D'
  140    29      > RETURN                                                   !2
  141    30*     > RETURN                                                   null

End of function compile

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nS2jf
function name:  __construct
number of ops:  4
compiled vars:  !0 = $parser
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  143     0  E >   RECV                                             !0      
  144     1        ASSIGN_OBJ                                               'parser'
          2        OP_DATA                                                  !0
  145     3      > RETURN                                                   null

End of function __construct

End of class Compiler.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.11 ms | 1429 KiB | 15 Q