Personal tricks for Centaur usage

Easy test for Typol specifications

Once you have defined a programming language in Centaur, given syntax, pretty-printing, resources to say where things are and what colors to use, you may want to write semantics. In Centaur, this is best done using Typol. Normally, you put a collection of typol files in a directory called semantics and you add a few resources in your resource files so that Centaur will know where to find the semantics programs. When you want to run you semantics specifications, things get a little more complicated, as the documentation instructs you to write some piece of lisp code that is quite complicated. The purpose of this section is to provide means to test Typol specifications without having to provide that Lisp code. You won't get the fancy integration of semantic tool in the interactive environment that Centaur provides, but you will be able to concentrate on the semantics.

The solution I provide is a lisp file that you have to load in Centaur.

When this file is loaded, a new Eval button is added to the TYPOL menu, a menu that is attached only to Centaur windows containing TYPOL specifications. To run your specification, load it in a window, make sure it is compiled (preferably in debug mode) and saved on disk. Then, you only need to select an export clause in your Typol specification and choose the Eval option. If there is no export clause, then add one, re-compile, and re-save on disk.

example of TYPOL window with Eval button in use

When you trigger the Eval button, my program pops several input windows, one for every input declared in the export clause. When you have put relevant data in each of these window, just press on the Run button provided on any of those windows. This starts your Typol program on this data. The execution normally proceeds in debug mode, so that you can see which inference rules are used. At the end of execution the results are displayed in another set of windows.

Questions

How do I load the lisp file? Save it in some place, say $HOME/contrib/typol-tools/typol-eval.ll. Then type the following line at the question mark prompt of Centaur:

(libloadfile "contrib/typol-tools/typol-eval" t)

Is it possible to have the lisp file loaded automatically in any Centaur session? Yes. Create a file $HOME/.centaur and put the libloadfile line in it.

Using a Typol specification as batch program

Once your semantic tool is fine-tuned and debugged, you may want to use it to process files in a batch mode, that is without the windows of Centaur. This part of using Centaur is a bit shady and has never really been documented.

The solution I provide here is quite simplistic and it assumes that you Typol specification fits in a restricted framework. Nevertheless, it can be used as an inspiration for more general situations.

To make my tool work, you first need to download it. It is composed of two files. The first one is a lisp file, the second is a bash file. For the tool to work, you need to place them both in the same directory.

The bash file, named typol-batch is supposed to be used as follows:

typol-batch -resfile file1.rdb -resfile file2.rdb [...]
  -input-language lang1 [ -output-language lang2 ]
  -typol-function \#:typol-program:fun
  [ -root dir ] -input file1 -output file2

This will run the Typol program designated by an export clause in file typol-program that defines a function fun, taking the input data from file1 and producing output in file. Data in file1 should be in the language lang1 (and your Centaur environment should have a Metal-generated parser for this language) and results will be in the language lang2 (and your Centaur environment should have a std pretty-printer for this language). If lang2 is not given, it is replaced with lang1 by default. You should provide a collection of resource files file1.rdb file2.rdb to instruct Centaur about specifications around lang1 and lang2. This resources files should be given relative to the location dir. If dir is not given, then it is the user's home directory by default.

Example

For instance, if I want to run the interpreter provided in my description of the little language (also available on the web), I have to type the following command:

typol-batch -resfile contrib/little/syntax/little.rdb \
        -resfile contrib/little/pprinters/pprinters.rdb \
        -resfile contrib/little/pprinters/std/std.rdb \
        -input-language little -typol-function \#:dynamics:execute \
        -input even.lil -output even-result

To make usage easier for final users, I suggest to write one's own shell command that will call typol-batch with the right arguments. An alternative is to construct a shell command that calls centaur after having defined a collection of shell variables, taking inspiration from typol-batch.

Bugs and caveats

This tool works less well when one of the languages is a resident language of Centaur. All resources are supposed to be taken from the Home directory of the user, or the directory provided using the -root option. To avoid problems, it may be necessary to fiddle with resources, for instance adding the following resource in one of the resources file given with the -resfile option:

batch.lang*root: app

This will mask a setting performed in my program (Never tested, I hope this works).

Generalizing?

For Typol specifications that involve several input files and several output files, or more than an input and output language, it is necessary to modify the lisp file. In that case, the shell command file can be made much simpler and the lisp file can be completely specialized to the application at hand.

That's all, folks!

Please send me any feedback.


Yves Bertot
Last modified: Tue May 16 12:12:44 MEST 2000