WAE Evaluator
HW4 - WAE - SUBMISSION INSTRUCTIONS
To accomodate my Prolog program to grade your assignments, please
submit one file named wae.pl
The file should contain code for the following three predicates:
wfe(E)
semCheck(E)
evalWAE(E,V)
wfe(E) returns true if E is a well-formed WAE; false otherwise
semCheck(E) returns true if E is a well-formed WAE and has no
semantic error (duplicate variables in with-list; value unknown;
and divide by zero); false otherwise
evalWAE(E,V) returns value of expression E in variable V.
Here is a sample run:
?- ['wae.pl'].
% wae.pl compiled 0.00 sec, 14,648 bytes
true.
?- wfe(with([[x,3]],with([[y,4]],plus(y,z)))).
true .
?- semCheck(with([[x,3]],with([[y,4]],plus(y,z)))).
false.
?- semCheck(divide(10,minus(7,7))).
false.
?- semCheck(divide(10,minus(7,5))).
true.
?- evalWAE(divide(5,minus(7,7)),V).
false.
?- evalWAE(divide(5,minus(7,5)),V).
V = 2.5 .
?- evalWAE(2,V).
V = 2 .
?- evalWAE(x,V).
false.
?- evalWAE(plus(2,2),V).
V = 4 .
?- evalWAE(plus(x,2),V).
false.
?- evalWAE(divide(4,2),V).
V = 2 .
?- evalWAE(minus(7,5),V).
V = 2 .
?- evalWAE(times(2,times(3,4)),V).
V = 24 .
?- evalWAE(with([[x,3]],with([[y,4]],plus(y,z))),V).
false.
?- evalWAE(with([[x,2],[y,3]],with([[z,plus(x,y)]],plus(x,z))),V).
V = 7 .
?- evalWAE(plus(plus(plus(2,3),plus(4,5)),plus(5,7)),V).
V = 26 .
?- evalWAE(with([[x,with([[y,3]],plus(y,y))]],plus(x,x)),V).
V = 12 .
?- evalWAE(with([[x,with([[x,with([[y,3]],plus(y,y))]],plus(x,x))]],plus(x,2)),V).
V = 14 .
Page Maintained by raj@cs.gsu.edu