예제 #1
0
 /**
  * Parse the code for a variable assignment.
  * Handles scalar types, and various array types (simple, associative,
  * multi-dimentional)
  * @param bool $p_extra_tokens Define how extra tokens should be handled
  *                             - EXTRA_TOKENS_IGNORE silently ignore any
  *                               extra code given after the first token
  *                             - EXTRA_TOKENS_ERROR (default) throws an
  *                               exception if extra code is found
  * @return mixed variable
  * @throws Exception when there are unexpected or extra tokens
  */
 public function parse($p_extra_tokens = self::EXTRA_TOKENS_ERROR)
 {
     switch ($this->tokens->type()) {
         case T_ARRAY:
             $t_result = $this->process_array();
             break;
         case T_CONSTANT_ENCAPSED_STRING:
         case T_STRING:
         case T_LNUMBER:
         case T_DNUMBER:
         case '-':
         case '+':
             $t_result = $this->process_value();
             break;
         default:
             throw new Exception('Unexpected token "' . $this->tokens->value() . '"');
     }
     # Make sure we have processed all tokens
     if ($p_extra_tokens == self::EXTRA_TOKENS_ERROR && !$this->tokens->is_empty()) {
         throw new Exception('Extra tokens found "' . $this->tokens->get_string() . '":');
     }
     return $t_result;
 }