From f1a115f5a78a4b5fe8000baeb0880c386338141d Mon Sep 17 00:00:00 2001 From: Salvador Abreu Date: Mon, 6 Jul 2015 09:32:58 +0900 Subject: [PATCH] a litte progress on name analysis --- fzn-parser/semantic.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fzn-parser/semantic.pl b/fzn-parser/semantic.pl index e652bb7..13ef5d8 100644 --- a/fzn-parser/semantic.pl +++ b/fzn-parser/semantic.pl @@ -8,17 +8,23 @@ 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_traverse(Ns, NNs, ST). -sa_n_traverse([_|Ns], NNs, ST) :- % ignore failing nodes (beware!) +sa_n_traverse([_|Ns], NNs, ST) :- !, % ignore failing nodes (beware!) sa_n_traverse(Ns, NNs, ST). +sa_n_traverse(N, NN, ST) :- sa_n(N, NN, ST). % non-list case % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - % % sa_n(AST_N_IN, AST_N_OUT, ST) +% +% handle all AST cases: +% var(N,T,I,A) - variable declaration +% lit(V,T) - literal with type +% sa_n(var(N,T,I,A), V, ST) :- sa_attribs(A, AX, ST), @@ -26,6 +32,15 @@ sa_n(var(N,T,I,A), V, ST) :- V=var(N,T,NI,AX), % new AST node becomes ST entry value st_insert(ST, N, V). +sa_n(lit(E,array(T)), lit(NE, array(T)), ST) :- + sa_n_traverse(E, NE, ST). +sa_n(lit(E,int), lit(E,int), _ST). +sa_n(lit(E,float), lit(E,float), _ST). +sa_n(lit(E,string), lit(E,string), _ST). + +sa_n(id(N), V, ST) :- st_lookup(ST, N, V), !. +sa_n(id(N), V, ST) :- V=id(N,_), % type as yet unknown + st_insert(ST, N, V). % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- libgit2 0.21.2