private boolean matches(List prefix1, List prefix2) {
        Iterator it1 = prefix1.iterator();
        Iterator it2 = prefix2.iterator();
        while (it1.hasNext()) {
            Token token1 = (Token)it1.next();
            if (token1 == null) return true; //null stands for subtree
            if (it2.hasNext()) {
                Token token2 = (Token)it2.next();
                if (token2 == null) return true;
                if (!token1.matches(token2)) return false;
            }
            else return true;
        }
        return true;
    }