Thank you so much. Now it counts, but only the first block works, in my case it is "+". How can I make it jump to the required block depending on the expression?
Code: Select all
implement main
open core, console, string
domains
result_list = integer*.
class predicates
culc : (inputStream) nondeterm.
suM : (integer, integer).
suB : (integer, integer).
muL : (integer, integer).
diVi : (integer, integer).
clauses
suM(F, S) :-
X = F + S,
write(X),
nl.
suB(F, S) :-
X = F - S,
write(X),
nl.
muL(F, S) :-
X = F * S,
write(X),
nl.
diVi(F, S) :-
X = F / S,
write(X),
nl.
culc(In) :-
In:endOfStream(),
In:close(),
!.
culc(In) :-
frontToken(In:readLine(), FirstParam, R),
frontToken(R, Oper, SecondParam),
Oper = "+",
F = tryToTerm(integer, FirstParam),
S = tryToTerm(integer, SecondParam),
suM(F, S),
culc(In),
!.
culc(In) :-
frontToken(In:readLine(), FirstParam, R),
frontToken(R, Oper, SecondParam),
Oper = "-",
F = tryToTerm(integer, FirstParam),
S = tryToTerm(integer, SecondParam),
suB(F, S),
culc(In).
culc(In) :-
frontToken(In:readLine(), FirstParam, R),
frontToken(R, Oper, SecondParam),
Oper = "*",
F = tryToTerm(integer, FirstParam),
S = tryToTerm(integer, SecondParam),
muL(F, S),
culc(In).
culc(In) :-
frontToken(In:readLine(), FirstParam, R),
frontToken(R, Oper, SecondParam),
Oper = "/",
F = tryToTerm(integer, FirstParam),
S = tryToTerm(integer, SecondParam),
diVi(F, S),
culc(In).
clauses
run() :-
init(),
In = inputStream_file::openFile8("sourceIn.txt"),
culc(In),
_ = readChar(),
!
or
_ = readLine().
end implement main
goal
console::run(main::run).