From 4029344a2b9f6c441576fd723e9b712ed4a3ca05 Mon Sep 17 00:00:00 2001 From: Salvador Abreu Date: Thu, 2 Jul 2015 18:07:47 +0900 Subject: [PATCH] now using free-ended symbol table model. refactor accordingly. --- fzn-parser/semantic.pl | 24 ++++++++++++------------ fzn-parser/stable.pl | 11 +++++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/fzn-parser/semantic.pl b/fzn-parser/semantic.pl index 278f5e8..aed4a30 100644 --- a/fzn-parser/semantic.pl +++ b/fzn-parser/semantic.pl @@ -2,31 +2,31 @@ sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE), fzn(preds(OP), vars(OV), constrs(OC), SOLVE, ST)) :- - sa_n_traverse(IP, OP, [], ST1), % predicates - sa_n_traverse(IV, OV, ST1, ST2), % variables - sa_n_traverse(IC, OC, ST2, ST). % constraints + 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, ST). -sa_n_traverse([N|Ns], [NN|NNs], IST, OST) :- - sa_n(N, NN, IST, MST), - sa_n_traverse(Ns, NNs, MST, OST). +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(AST_N_IN, AST_N_OUT, ST_IN, ST_OUT) +% sa_n(AST_N_IN, AST_N_OUT, ST) -sa_n(var(N,T,I,A), var(N,T), IST, OST) :- - sa_attribs(A, AX, IST, ST1), - st_insert(ST1, N, var(N,T,I,AX), OST). +sa_n(var(N,T,I,A), var(N,T), ST) :- + sa_attribs(A, AX, ST), + st_insert(ST, N, var(N,T,I,AX)). sa_n(constraint(_C)). % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -sa_attribs(A, NA, IST, OST) :- +sa_attribs(A, NA, IST) :- true. % ----------------------------------------------------------------------------- diff --git a/fzn-parser/stable.pl b/fzn-parser/stable.pl index 0f79695..6f2fa30 100644 --- a/fzn-parser/stable.pl +++ b/fzn-parser/stable.pl @@ -1,10 +1,13 @@ % == No, Emacs this is -*-Prolog-*- code, not what you thought... ============= % -- Symbol table ------------------------------------------------------------- +% +% Open-ended model. +st_lookup(ST, _, _) :- var(ST), !, fail. st_lookup([K=V|_], K, V). -st_lookup([_|ST], K, V) :- st_lookup(ST, K, V). +st_lookup([_|ST], K, V) :- st_lookup(ST, K, V). -st_insert([], K, V, [K=V]) :- !. -st_insert([K=_|_], K, _, _) :- !, throw(duplicate(K)). -st_insert([KV0|ST], K, V, [KV0|STx]) :- st_insert(ST, K, V, STx). +st_insert(ST, K, V) :- var(ST), !, ST=[K=V|_]. +st_insert([K=_|_], K, _) :- !, throw(duplicate(K)). +st_insert([_|ST], K, V) :- st_insert(ST, K, V). -- libgit2 0.21.2