private function advance()
    {
        $i = $this->currentCharacter;
        $formula_length = strlen($this->formula);
        // eat up white spaces
        if ($i < $formula_length) {
            while ($this->formula[$i] == ' ') {
                ++$i;
            }

            if ($i < ($formula_length - 1)) {
                $this->lookAhead = $this->formula[$i + 1];
            }
            $token = '';
        }

        while ($i < $formula_length) {
            $token .= $this->formula[$i];

            if ($i < ($formula_length - 1)) {
                $this->lookAhead = $this->formula[$i + 1];
            } else {
                $this->lookAhead = '';
            }

            if ($this->match($token) != '') {
                $this->currentCharacter = $i + 1;
                $this->currentToken = $token;

                return 1;
            }

            if ($i < ($formula_length - 2)) {
                $this->lookAhead = $this->formula[$i + 2];
            } else { // if we run out of characters lookAhead becomes empty
                $this->lookAhead = '';
            }
            ++$i;
        }
        //die("Lexical error ".$this->currentCharacter);
    }