CHORD
Plug-in User Manual
Introduction
Eclipse
Plug-in Installation
Using Eclipse
Plug-in
Examples
Compiler Directives
Introduction
CHORD Eclipse plug-in can be
used to add CHR support to an existing Java project. It extends Eclipse
Platform with two main extension points:
- An incremental builder: with
this extension you can create and edit “.chr” files and eclipse IDE will re-compile your
CHR program each time you save it, and CHR Compiler will try to mark each
syntactical error it finds with a default red mark used in eclipse
editors. The compiler will generate a “.java”
file with the same name of original file. This file can be used to run CHR
program as a stand-alone application. Each possible consistent final
constraint store memory state is going to be displayed on the console.
- CHR
support into Java classes: this plug-in is going to add CHORD to
your project CLASSPATH, so you can use CHR Engine as a subcomponent of any
Java application (refer to Examples
section)
Eclipse
Plug-in Installation
- From
the Eclipse Help
menu, select Software
Updates and then Find and install...
- You
will be presented with the following dialog:

Select the Search
for new features to install
radio button.
Press Next.
- You
will next be presented with the following dialog:

- In
the New Update
Site dialog that appears, enter a name for the update site and
the URL http://chord.sourceforge.net/eclipse/update
and press OK.

- The
update site will now be listed in the Install dialog.

Ensure that there is a check next to the CHORD update site, then press Finish.
- You
will next be presented with the following dialog:

Ensure that there is a check next to CHORD. Other
available features can be installed by checking them as well. Press Next.
- The
installation process will next display the license agreement for CHORD.

Select I accept
the terms of the license agreements and press Next.
- The
next dialog that appears displays the possible locations into which you
can install CHORD:

Once you have selected a site, press Finish.
- The
next dialog that appears warns you about the fact that CHORD plug-in has
not been digitally signed, just press Install
All:

Using Eclipse
Plug-in
- Create
a new Java project. From eclipse File
menu select New, Project, the following window is
displayed:

- Press
Next. Fill your project’s
properties and press Finish.

- Now
you have to add CHR support to your Java project. Right-click your project
icon and select “Add/Remove CHR
Support”.

- Your
new project now has CHR support. Just create a new “.chr” file,
Click on your project, File
menu, New, File. Create a file with “.chr” extension and press Finish.

- Each
“.chr”
file is called a Handler,
each handler is compiled into a Java program extending chord.Handler class. Type any
CHR program and save it:

- Now
you can run your CHR program by right-clicking the generated java file and
choosing Run As and Java Application:

- Its
output will be written to eclipse Console view:

Examples
CHR
Examples can be found at examples.zip.
Compiler Directives
A Compiler
directive is a line that adds meta-information to a Handler. This piece of
meta-information can be used by the compiler in order to changer the way it
compiles the CHR program, or this information can be used internally by the
engine in order to optimize program execution. CHR compiler directives are
lines following the pattern below inserted in the first lines of a program:
:- directivename “parameter
string”
Or, just
:- directivename
Actually there are just two official
predefined compiler directives:
·
:- standalone
By default every compiled CHR program shows the state of the user-defined
constraint memory every time it reaches a final state, with this command this
behavior is inhibited, so the program runs as a standalone program.
·
:-
package “package.name”
By default every CHR compiled program is a class in java default package, you
can use this directive in order to generate the class in another package. The referred
package must exist to the program be compiled properly.
·
:- explain
By using this directive when you run the generated java class it will output
the reasoning explanation for the execution of the handler. This directive is
not compatible with “standalone” directive, if both are present in a given handler, “standalone”
directive will be ignored.