function [S1,S2] = BR_getANDargs(s)
% BR_getANDargs - returns the arguments to top-level ^ operator in s
% On input:
%     s (string): logical string
% On output:
%     S1 (string): first arg of (S1^S2)
%     S2 (string): second arg of (S1^S2)
% Call:
%     [S1,S2] = BR_getANDargs(s)
% Author:
%     T. Henderson
%     UU
%     Fall 2018
%

LEFT_PAREN = '(';
RIGHT_PAREN = ')';
AND_OP = '^';

S1 = [];
S2 = [];

len_s = length(s);
count = 1;
for c = 2:len_s
    if s(c)==LEFT_PAREN
        count = count + 1;
    elseif s(c)==RIGHT_PAREN
        count = count - 1;
    end
    if count==1&s(c+1)==AND_OP
        S1 = s(2:c);
        S2 = s(c+2:len_s-1);
        return
    end
end
