<?php
function getFunction($input, &$results) {
	$input = trim($input);
	
	$result = array();
	$moved = 0;
	
	//echo sprintf('Parsing: "%s"' . "\n", $input);
	
	if(preg_match('/\A\&([a-z]+)\(/', $input, $matches)) {
		$matchlength = strlen($matches[0]);
		
		$remaining = substr($input, $matchlength);
		$moved += $matchlength;
		
		$result['type'] = 'call';
		$result['name'] = $matches[1];
		$result['args'] = array();
		
		//echo sprintf('Function: "%s"' . "\n", $result['name']);
		
		$tmpArgs = array();
		while(!preg_match('/\A\)/', $remaining)) {
			$recMoved = getFunction($remaining, $tmpArgs);
			
			$remaining = substr($remaining, $recMoved);
			$moved += $recMoved;
		}
		
		$remaining = substr($remaining, 1);
		$moved += 1;
		
		foreach($tmpArgs as $arg) {
			if($arg['type'] == 'call') {
				$result['args'][] = $arg;
			} else {
				echo sprintf('Parsing content as args "%s"' . "\n", $arg['content']);
				foreach(explode(',', $arg['content']) as $j) {
					//echo sprintf('Parsing content as args = "%s"' . "\n", $j);
					preg_match('/\A\s*(.*?)\s*\Z/', $j, $matches);
					//echo sprintf('Parsing content as args ... "%s"' . "\n", $matches[1]);
					if($matches[1]) {
						$result['args'][] = array('type' => 'content', 'content' => $matches[1]);
					}
				}
			}
		}
	} else {
		preg_match('/\A[^&\)]+/', $input, $matches);
		$matchlength = strlen($matches[0]);
		
		//echo sprintf('Content: "%s"' . "\n", $matches[0]);
		
		$result['content'] = $matches[0];
		
		$moved += $matchlength;
	}
	
	$results[] = $result;
	
	return $moved;
}

$input = fgets(STDIN);

$result = array();
getFunction($input, $result);

// you can now recursively parse the structure using your own code

var_dump($result);
?>