Commit f461b0bbc3d28f490f79139af2702b5428b4781b
1 parent
4029344a
Exists in
master
first stab at AST traversal for name analysis
Showing
1 changed file
with
17 additions
and
7 deletions
Show diff stats
fzn-parser/semantic.pl
... | ... | @@ -8,9 +8,11 @@ sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE), |
8 | 8 | |
9 | 9 | % ----------------------------------------------------------------------------- |
10 | 10 | |
11 | -sa_n_traverse([], [], ST). | |
11 | +sa_n_traverse([], [], _ST). | |
12 | 12 | sa_n_traverse([N|Ns], [NN|NNs], ST) :- |
13 | - sa_n(N, NN, ST), | |
13 | + sa_n(N, NN, ST), !, | |
14 | + sa_n_traverse(Ns, NNs, ST). | |
15 | +sa_n_traverse([_|Ns], NNs, ST) :- % ignore failing nodes (beware!) | |
14 | 16 | sa_n_traverse(Ns, NNs, ST). |
15 | 17 | |
16 | 18 | |
... | ... | @@ -18,15 +20,23 @@ sa_n_traverse([N|Ns], [NN|NNs], ST) :- |
18 | 20 | % |
19 | 21 | % sa_n(AST_N_IN, AST_N_OUT, ST) |
20 | 22 | |
21 | -sa_n(var(N,T,I,A), var(N,T), ST) :- | |
23 | +sa_n(var(N,T,I,A), V, ST) :- | |
22 | 24 | sa_attribs(A, AX, ST), |
23 | - st_insert(ST, N, var(N,T,I,AX)). | |
25 | + sa_n(I, NI, ST), % parse initializer | |
26 | + V=var(N,T,NI,AX), % new AST node becomes ST entry value | |
27 | + st_insert(ST, N, V). | |
24 | 28 | |
25 | -sa_n(constraint(_C)). | |
26 | 29 | |
27 | 30 | % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
28 | 31 | |
29 | -sa_attribs(A, NA, IST) :- | |
30 | - true. | |
32 | +sa_attribs([A|As], [NA|NAs], ST) :- | |
33 | + sa_attrib(A, NA, ST), !, | |
34 | + sa_attribs(As, NAs, ST). | |
35 | +sa_attribs([_|As], NAs, ST) :- % ignore unknown attributes | |
36 | + sa_attribs(As, NAs, ST). | |
37 | +sa_attribs([], [], _). | |
38 | + | |
39 | + | |
40 | +sa_attrib(id(output_var), output, _). | |
31 | 41 | |
32 | 42 | % ----------------------------------------------------------------------------- | ... | ... |