next up previous
Next: Comparison with Related Up: DJ : A Previous: A Brief Introduction

Implementation

A compiler for DJ has been implemented in B-Prolog. For a DJ program, the compiler first parses the program, creates an instance of the main class, and, at the same time, extracts the constraints. Then, it invokes the constraint solver to solve the constraints. Finally, it generates a Java applet and an HTML file.

The compiler is about 11000 lines long including spaces and comments. DJ is an extension of Java. Thus, we had to write a parser for the whole Java. The parser and the Java code generator account for about half of the compiler.

Prolog is an excellent language for language processing including writing compilers. B-Prolog's delay clauses [10] are very useful for implementing constraint propagation procedures for various constraints. It would take an order of magnitude longer time for us to finish the compiler if we chosen C or Java as the implementation language. Also, choosing a language like C cannot significantly improve the compilation efficiency because a large portion of compilation time is spent in doing layout, which is mostly already done in C.

Layouts of components are determined by the constraint solver in B-Prolog. The DJ compiler handles size and position variables in the same way as other domain variables except it uses a different strategy for ordering geometric variables. Variables of different types are given different priorities. The integer 0 indicates the highest priority and -inf indicates the lowest priority. Variables that have higher priorities are instantiated before those that have lower priorities.



next up previous
Next: Comparison with Related Up: DJ : A Previous: A Brief Introduction



www-admin@icot.or.jp