Re: [eclipse-clp-users] Syntax error in source transformation

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Sat, 12 Apr 2008 01:22:50 +0100
Valerio wrote:
 > ...
> Here is the complete for code for a small example. I omitted the
> faulty version of the EFSM, as it would be pretty redundant in this
> case:
> % main for loop
> (for(I,1,T1), param( IN1, IN2, OUT1, OUT2, REG, A, B, C, A_F, B_F,
> C_F, OUT1_F, OUT2_F, REG_F, E1, E2, E3, E4, E5, E6, E7, E1_F, E2_F,
> E3_F, E4_F, E5_F, E6_F, E7_F ) do

In this case you can simply wrap all the params into a structure, e.g.

( for(I,1,T1), param(aux(IN1, IN2, ..., E7_F)) do

or, slightly more efficient in the current implementation:

Params = aux(IN1, IN2, ..., E7_F),
( for(I,1,T1), param(Params) do
     Params = aux(IN1, IN2, ..., E7_F),

 > No, the tool itself is written in C++.

That's of course different.  If the tool were written in ECLiPSe,
it would be a rather straightforward transformation to change it such
that it calls the constraints instead of writing them to a file.

Let me outline the scheme i have in mind.  I assume you are reading your
circuit description from some kind of (non-ECLiPSe) formal description
that tells you how signals are combined.

Let's assume the descriptions tell us to connect named signals like
'a' and 'b' with connectors like 'nand'.  You need to have domain
variables corresponding to the signals, and constraints to represent
the connectors.  I suggest to enter the variables into a hash table
so you can look them up under their symbolic names.  The generic code
would be something like

main(VarTable) :-
	% read the names of the signals from the formal description
	% and call make_bool_var(VarTable, <name>) for each one.
	% read the names of operations and signals from the formal description
	% and call setup_constraint(<opname>,<signames>,VarTable)
	% get all the variables and do search on them
	hash_list(VarTable, _, AllVars),

make_bool_var(Name, VarTable) :-
	X :: 0..1, hash_set(VarTable, Name, X).

setup_constraint(OpName, In1Name, In2Name, OutName, VarTable) :-
	hash_get(VarTable, In1Name, X),  % name->variable
	hash_get(VarTable, In2Name, Y),
	hash_get(VarTable, OutName, Z),
	construct_constraint(OpName, X, Y, Z, Constraint),
construct_constraint(nand, X, Y, Z, (neg(X and Y) #= Z)).

For a concrete circuit description which says that 'c' is the
'nand' of 'a' and 'b', we would end up invoking at runtime:

	make_bool_var(VarTable, 'a')
	make_bool_var(VarTable, 'b')
	make_bool_var(VarTable, 'c')
	setup_constraint('nand', 'a, 'b', 'c', VarTable)
and finally
	labeling([_1, _2, _3])

Note that the actual ECLiPSe problem variables corresponding to 'a', 'b'
and 'c' do not occur in the ECLiPSe source and are therefore anonymous -
that's why we access them via the hash table.  In practice, you would
probably enter whole variable arrays into the hash table, rather than
individual variables.

I hope this hasn't ended up being too confusing!

-- Joachim
Received on Fri Apr 11 2008 - 17:23:08 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 20 2019 - 00:14:49 CEST