public function parseExpression()
    {
        $out = '';
        $brackets = array();

        do {

            if ($token = $this->stream->nextIf(T_STRING)) {

                $name = $token->getValue();

                if ($this->stream->test('(') && $this->engine->getFunction($name)) {
                    $out .= sprintf("\$this->callFunction('%s', array%s)", $name, $this->parseExpression());
                } else {
                    $out .= $name;
                }

            } elseif ($token = $this->stream->nextIf(T_VARIABLE)) {

                $out .= $this->parseSubscript($var = $token->getValue());
                $this->variables[ltrim($var, '$')] = null;

            } else {

                $token = $this->stream->next();

                if ($token->test(array('(', '['))) {
                    array_push($brackets, $token);
                } elseif ($token->test(array(')', ']'))) {
                    array_pop($brackets);
                }

                $out .= $token->getValue();
            }

        } while (!empty($brackets));

        return $out;
    }