prolog to solve grammar involving braces

Posted by Abhilash Muthuraj on Stack Overflow See other posts from Stack Overflow or by Abhilash Muthuraj
Published on 2011-09-25T01:40:26Z Indexed on 2012/12/03 17:04 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

I'm trying to solve DCG grammar in prolog and succeeded upto a point, i'm stuck in evaluating the expressions involving braces like these.

expr( T, [’(’, 5, +, 4, ’)’, *, 7], []),

expr(Z) --> num(Z).
expr(Z) --> num(X), [+], expr(Y), {Z is X+Y}.
expr(Z) --> num(X), [-], expr(Y), {Z is X-Y}.
expr(Z) --> num(X), [*], expr(Y), {Z is X*Y}.
num(D) --> [D], {number(D)}.


eval(L, V, []) :- expr(V, L, []).

© Stack Overflow or respective owner

Related posts about prolog

Related posts about swi-prolog