function b = BR_isliteral(s)
% BR_isliteral - determines if s is a literal: (<int>)/(-<int>)
% On input:
%     s (string): logical string
% On output:
%     b (Boolean): true if literal, else false
% Call:
%     b = BR_isliteral(s);
% Author:
%     T. Henderson
%     UU
%     Fall 2018
%

LEFT_PAREN = '(';
RIGHT_PAREN = ')';
MINUS = '-';

trans = [2,5,5,5,5; 5,3,2,4,5; 5,5,3,4,5];
    
b = 0;

state = 1;
if s(1)==LEFT_PAREN
    c = 1;
elseif s(1)==MINUS
    c = 2;
elseif BR_isdigit(s(1))
    c = 3;
elseif s(1)==RIGHT_PAREN
    c = 4;
else
    c = 5;
end

if c~=1
    return
end

index = 1;
state = 2;
while state<4
    index = index + 1;
    if s(index)==LEFT_PAREN
        c = 1;
    elseif s(index)==MINUS
        c = 2;
    elseif BR_isdigit(s(index))
        c = 3;
    elseif s(index)==RIGHT_PAREN
        c = 4;
    else
        c = 5;
    end
    state = trans(state,c);
end
if state==4&index==length(s)
    b = 1;
end
