From f461b0bbc3d28f490f79139af2702b5428b4781b Mon Sep 17 00:00:00 2001 From: Salvador Abreu Date: Thu, 2 Jul 2015 18:58:49 +0900 Subject: [PATCH] first stab at AST traversal for name analysis --- fzn-parser/semantic.pl | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fzn-parser/semantic.pl b/fzn-parser/semantic.pl index aed4a30..0367c60 100644 --- a/fzn-parser/semantic.pl +++ b/fzn-parser/semantic.pl @@ -8,9 +8,11 @@ sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE), % ----------------------------------------------------------------------------- -sa_n_traverse([], [], ST). +sa_n_traverse([], [], _ST). sa_n_traverse([N|Ns], [NN|NNs], ST) :- - sa_n(N, NN, 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). @@ -18,15 +20,23 @@ sa_n_traverse([N|Ns], [NN|NNs], ST) :- % % sa_n(AST_N_IN, AST_N_OUT, ST) -sa_n(var(N,T,I,A), var(N,T), ST) :- +sa_n(var(N,T,I,A), V, ST) :- sa_attribs(A, AX, ST), - st_insert(ST, N, var(N,T,I,AX)). + sa_n(I, NI, ST), % parse initializer + V=var(N,T,NI,AX), % new AST node becomes ST entry value + st_insert(ST, N, V). -sa_n(constraint(_C)). % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -sa_attribs(A, NA, IST) :- - true. +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, _). % ----------------------------------------------------------------------------- -- libgit2 0.21.2