% parser.pl 
% expr(Z,"-2+3*5+1",[]) -> Z=14
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(A, B, C) :-
        term(F, B, G),
        'C'(G, 43, E),
        expr(D, E, C),
        A is F+D.
expr(A, B, C) :-
        term(F, B, G),
        'C'(G, 45, E),
        expr(D, E, C),
        A is F-D.
expr(A, B, C) :-
        term(A, B, C).
 
number(A, B, C) :-
        'C'(B, 43, D),
        number(A, D, C).
number(A, B, C) :-
        'C'(B, 45, E),
        number(D, E, C),
        A is-(D).
number(A, B, C) :-
        'C'(B, D, C),
        [48]=<D,
        D=<[57],
        A is D-[48].
 
library_directory('/opt/net1/sicstus3/bin/library').
 
file_search_path(library, A) :-
        library_directory(A).
 
term(A, B, C) :-
        number(F, B, G),
        'C'(G, 42, E),
        term(D, E, C),
        A is F*D.
term(A, B, C) :-
        number(F, B, G),
        'C'(G, 47, E),
        term(D, E, C),
        A is F/D.
term(A, B, C) :-
        number(A, B, C).
*/
