
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) --> "+", digits(C,_).
number(C) --> "-", digits(X,_),{C is -X}.
number(C) -->  digits(C,_).

digits(V,B)  --> digit(X), digits(C,B0),{B is 10*B0, V is X*B +C}.
digits(C,1) --> digit(C).

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

/*

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

Z = 24 ? ;

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

Z = -196 ? ;

no

| ?- listing.

digit(A, B, C) :-
        'C'(B, D, C),
        [48]=<D,
        D=<[57],
        A is D-[48].

digits(A, 1, B, C) :-
        digit(A, B, C).
digits(A, B, C, D) :-
        digit(E, C, F),
        digits(G, H, F, D),
        B is 10*H,
        A is E*B+G.
...
*/
