Commit 4029344a2b9f6c441576fd723e9b712ed4a3ca05

Authored by Salvador Abreu
1 parent 6512088f
Exists in master

now using free-ended symbol table model. refactor accordingly.

Showing 2 changed files with 19 additions and 16 deletions   Show diff stats
fzn-parser/semantic.pl
@@ -2,31 +2,31 @@ @@ -2,31 +2,31 @@
2 2
3 sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE), 3 sa_names(fzn(preds(IP), vars(IV), constrs(IC), SOLVE),
4 fzn(preds(OP), vars(OV), constrs(OC), SOLVE, ST)) :- 4 fzn(preds(OP), vars(OV), constrs(OC), SOLVE, ST)) :-
5 - sa_n_traverse(IP, OP, [], ST1), % predicates  
6 - sa_n_traverse(IV, OV, ST1, ST2), % variables  
7 - sa_n_traverse(IC, OC, ST2, ST). % constraints 5 + sa_n_traverse(IP, OP, ST), % predicates
  6 + sa_n_traverse(IV, OV, ST), % variables
  7 + sa_n_traverse(IC, OC, ST). % constraints
8 8
9 % ----------------------------------------------------------------------------- 9 % -----------------------------------------------------------------------------
10 10
11 -sa_n_traverse([], [], ST, ST).  
12 -sa_n_traverse([N|Ns], [NN|NNs], IST, OST) :-  
13 - sa_n(N, NN, IST, MST),  
14 - sa_n_traverse(Ns, NNs, MST, OST). 11 +sa_n_traverse([], [], ST).
  12 +sa_n_traverse([N|Ns], [NN|NNs], ST) :-
  13 + sa_n(N, NN, ST),
  14 + sa_n_traverse(Ns, NNs, ST).
15 15
16 16
17 % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 17 % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18 % 18 %
19 -% sa_n(AST_N_IN, AST_N_OUT, ST_IN, ST_OUT) 19 +% sa_n(AST_N_IN, AST_N_OUT, ST)
20 20
21 -sa_n(var(N,T,I,A), var(N,T), IST, OST) :-  
22 - sa_attribs(A, AX, IST, ST1),  
23 - st_insert(ST1, N, var(N,T,I,AX), OST). 21 +sa_n(var(N,T,I,A), var(N,T), ST) :-
  22 + sa_attribs(A, AX, ST),
  23 + st_insert(ST, N, var(N,T,I,AX)).
24 24
25 sa_n(constraint(_C)). 25 sa_n(constraint(_C)).
26 26
27 % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 27 % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 28
29 -sa_attribs(A, NA, IST, OST) :- 29 +sa_attribs(A, NA, IST) :-
30 true. 30 true.
31 31
32 % ----------------------------------------------------------------------------- 32 % -----------------------------------------------------------------------------
fzn-parser/stable.pl
1 % == No, Emacs this is -*-Prolog-*- code, not what you thought... ============= 1 % == No, Emacs this is -*-Prolog-*- code, not what you thought... =============
2 2
3 % -- Symbol table ------------------------------------------------------------- 3 % -- Symbol table -------------------------------------------------------------
  4 +%
  5 +% Open-ended model.
4 6
  7 +st_lookup(ST, _, _) :- var(ST), !, fail.
5 st_lookup([K=V|_], K, V). 8 st_lookup([K=V|_], K, V).
6 -st_lookup([_|ST], K, V) :- st_lookup(ST, K, V). 9 +st_lookup([_|ST], K, V) :- st_lookup(ST, K, V).
7 10
8 -st_insert([], K, V, [K=V]) :- !.  
9 -st_insert([K=_|_], K, _, _) :- !, throw(duplicate(K)).  
10 -st_insert([KV0|ST], K, V, [KV0|STx]) :- st_insert(ST, K, V, STx). 11 +st_insert(ST, K, V) :- var(ST), !, ST=[K=V|_].
  12 +st_insert([K=_|_], K, _) :- !, throw(duplicate(K)).
  13 +st_insert([_|ST], K, V) :- st_insert(ST, K, V).