protected function replaceArgumentExpression($matches) {
		//count available matches
		//this indicates the type of expression to replace
		$total_matches = count($matches);
		$type = $subindex = null;
	
		//%{TYPE|CLASS@1}
		if ($total_matches == 2) {
			//check if there are arguments left
			if ($this->counter >= count($this->args))
				throw new \OutOfBoundsException("No arguments left for expression '{$matches[0]}'");

			return $this->castParameter($this->args[$this->counter++], $matches[1]);
		}
	
		switch ($total_matches) {
			/*
			 * Simple index
			 */
			case 5: //%{NUMBER@2[INDEX]@3?:TYPE@4}
				$type = substr($matches[4], 1);
			case 4: //%{NUMBER@2[INDEX]@3}
				$subindex = empty($matches[3]) ? null : substr($matches[3], 1, -1);
			case 3: //%{NUMBER@2}
				$index = intval($matches[2]);
					
				if (!array_key_exists($index, $this->args))
					throw new \InvalidArgumentException("No value found on index $index");
	
				if ($index == 0 && !is_null($subindex))
					return $this->getIndex($subindex, null, $type);
				
				return $this->getSubIndex($this->args[$index], $subindex, $type);
	
			/*
			 * Interval
			 */
			case 10: //%{NUMBER@5[LEFT@7?..RIGHT@8?]:TYPE@9}
				$type = substr($matches[9], 1);
			case 9: //%{NUMBER@5[LEFT@7?..RIGHT@8?]}
				$index = intval($matches[5]);
					
				if (!array_key_exists($index, $this->args))
					throw new \InvalidArgumentException("No value found on index $index");
					
				return $this->getSubRange($this->args[$index], $matches[7], $matches[8], $type);
		}
	}