function max_val = BR_max_var_in_s(s)
% BR_max_var_in_s - determines maximum variable value in s
% On input:
%     s (string): fully parenthesized logical sentence
% On output:
%     max_val (int): max value of abs of literals in s
% Call:
%     b = BR_max_var_in_s('((1)v(2))');
% Author:
%     T. Henderson
%     UU
%     Fall 2018
%

if isempty(s)
    max_val = 0;
    return
end

d = isstrprop(s,'digit');

d_len = length(d);

max_val = 0;
k = 0;
while k<d_len
    k = k + 1;
    if d(k)==1
        k1 = k + 1;
        val = str2num(s(k));
        while k1<d_len&d(k1)==1
            val = val*10 + str2num(s(k1));
            k1 = k1 + 1;
        end
        if val>max_val
            max_val = val;
        end
    end
end
