
expr(Z) --> term(X), "+", expr(Y), {Z is X + Y}.
expr(Z) --> term(X), "-", expr(Y), {Z is X - Y}.
expr(X) --> term(X).

term(Z) --> number(X), "*", term(Y), {Z is X * Y}.
term(Z) --> number(X), "/", term(Y), {Z is X / Y}.
term(Z) --> number(Z).

number(C) --> "+", number(C).
number(C) --> "-", number(X),{C is -X}.
number(X) --> [C], {"0" =< C, C =< "9", X is C - "0"}.

/*

| ?- expr(Z,"-2+3*5+1",[]).

Z = 14 ? ;

no
| ?- expr(Z,"-2+3*5+11",[]).

no
| ?- expr(Z,"-2+3*5+11","+11").

Z = 13 ? 

yes


*/
