semantic.pl
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
% == No, Emacs this is -*-Prolog-*- code, not what you thought... =============
sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE),
fzn(preds(OP), vars(OV), constrs(OC), SOLVE, ST)) :-
sa_n_traverse(IP, OP, ST), % predicates
sa_n_traverse(IV, OV, ST), % variables
sa_n_traverse(IC, OC, ST). % constraints
% -----------------------------------------------------------------------------
sa_n_traverse([], [], _ST).
sa_n_traverse([N|Ns], [NN|NNs], ST) :-
sa_n(N, NN, ST), !,
sa_n_traverse(Ns, NNs, ST).
sa_n_traverse([_|Ns], NNs, ST) :- % ignore failing nodes (beware!)
sa_n_traverse(Ns, NNs, ST).
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%
% sa_n(AST_N_IN, AST_N_OUT, ST)
sa_n(var(N,T,I,A), V, ST) :-
sa_attribs(A, AX, ST),
sa_n_traverse(I, NI, ST), % parse initializer
V=var(N,T,NI,AX), % new AST node becomes ST entry value
st_insert(ST, N, V).
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sa_attribs([A|As], [NA|NAs], ST) :-
sa_attrib(A, NA, ST), !,
sa_attribs(As, NAs, ST).
sa_attribs([_|As], NAs, ST) :- % ignore unknown attributes
sa_attribs(As, NAs, ST).
sa_attribs([], [], _).
sa_attrib(id(output_var), output, _).
% -----------------------------------------------------------------------------