function [nr,operator,value,next] = ParseFilter(pointer,varargin)

args = size(varargin,2);

if pointer > args
    next = -1;
    nr   = 0;
    return
end

if ~isinteger(varargin{pointer})
    nr = -1;
    return
else
    nr = varargin{pointer};
end

next = pointer + 1;
if next > args then
    next = -1;
    return
else
    % 
    
    if ischar(varargin{next})
        if strcmp(upper(varargin{next}),'RELOP')
            next = next + 1;
            if RelationalOperator(varargin{next})
                operator = varargin{next};
                next = next + 1;
            else
                nr = -1;
                return
            end
        elseif strcmp(upper(varargin{next}),'VALUE')
            next = next + 1;
            if isnumeric(varargin{next})
                value = varargin{next};
                next = next + 1;
                if strcmp(upper(varargin{next}),'RELOP')
                    next = next + 1;
                    if RelationalOperator(varargin{next})
                        operator = varargin{next};
                        next = next + 1;
                    else
                        nr = -1;
                        return
                    end
            else
                nr = -1;
                return
            end
        else
            nr = -1;
            return
        end
    elseif isnumeric(varargin{next})
        value = varargin{next};
        next = next + 1;
        if next > args
            next = -1;
            operator = '==';
            return
        elseif isnumeric(varargin{next})
            operator = '==';
            return
        elseif strcmp(upper(varargin{next}),'RELOP')
            next = next + 1
            if RelationalOperator(varargin{next})
                operator = varargin{next};
                next = next + 1;
            else
                nr = -1;
                return
            end
        else
            nr = -1;
            return
        end
    end
end