Back to index


Overview of Linguist

Linguist is a radical new programming system, written entirely in Java, that builds on Java to provide a highly customizable scripting environment for a wide range of applications or applets. You use it to create your own personalized scripting language, with the full power of Java available at any time. As with Java itself, the scripts are compiled, then interpreted at runtime. But because all the important functionality is written in Java there's little if any noticeable loss of performance compared to a regular Java program.

Summary of features

Why use a scripting language?

Java is without any doubt the environment of choice for creating reliable programs quickly. However, a great deal of planning is needed before coding can start, or the result is likely to be just as difficult to maintain as if it were written in C or Fortran. Scripting offers the ability to code right away, without much of the planning stage, but with less risk of creating bad code.

But the chief reason has to do with division of responsibilities. Imagine you are asked to program a conveyor system in a factory, carrying pallets of some arbitrary product. At the lowest level you have the inputs and outputs; the photo-electric cells that tell you where an item is in the system, the readers that identify which pallet is which, the manual override buttons and so on. The outputs are the solenoid-controlled gates and barriers that allow the pallets to progress.

And at the top level you have the logic of the system, that deals with input events and sequences the outputs according to the rules of the system.

Now the skills needed to deal with these two levels are not the same. You can employ a C programmer to write drivers for the hardware, but (s)he may be unfamiliar with the product that's being carried and the way it must be handled. Your production staff have all the experience of dealing with the product but don't know how to program in a language like C or Java.

When you use Linguist you're separating these two sets of skills and using a different type of person to deal with each. Your system programmer uses Linguist to create a scripting language that is customized to the job in hand, then the production engineer writes scripts to control the system, without ever needing to go near Java. As the programmer you still work entirely in Java, but the benefits to the customer are:

To illustrate how this works, how about an example. At one point on the conveyor, pallets must be stopped until a test has been completed, then allowed to continue. Ask the production person for an overview of how this works and the answer will be something like:

1 Assume the barrier to be initially raised...
2 When the pallet reaches the photocell, start the test.
3 When the test has finished, lower the barrier.
4 Wait for the pallet to pass the photocell.
5 Raise the barrier.

Now it seems to me a criminal waste of time and computer power to have to manually translate that into a language like C or Java. So let's rewrite it using a formal script:

barrier Barrier1
photocell Cell1
test Test1
variable T1
.
.
wait until pallet is at Cell1
run Test1
lower Barrier1
wait T1 ticks
if pallet is at Cell1 go to TimeoutError
raise Barrier1

This shouldn't need much explanation; the four lines at the top declare different types of variable, most of them specific to this language. The rest, which assumes some initialization has been done, manages the progress of the pallet through the test station. [Control engineers will be ready to point out the deficiencies of such a simple procedure, but we have to start somewhere.]

Linguist enables you to build your own scripting language that can compile and execute the above program directly, without the need to expensively create an equivalent Java version that cannot then be read (or checked) by the production engineer whose job is on the line.

Starting with Linguist

Linguist as supplied implements a core scripting language, to which you add your own specialized language keyword handlers. This is much simpler than it sounds. The core language has a small set of variable types - numeric variables and strings - and a collection of assignment statements, values, conditions and control operators. You can use it, without modification, as a command-line tool for doing arithmetic or string processing. It also comes with a fairly substantial - and growing - set of graphics and multimedia functions, including support for the Java Media Framework. This means you can use it to create interactive multimedia products simply by scripting, without any extra Java coding at all.

There are four different kinds of things you may want to add to the language, to make it suitable for your application:

Each of these items is treated slightly differently, but the process is much the same. First, you write a keyword handler (in Java) that parses the new language feature and extracts the important elements of it. Linguist has templates and built-in methods that make this a snap. The output of this stage is an instance of a new object that will encapsulate all the run-time functionality needed by the item. Then you take a standard handler template and write the extra run-time methods it needs to deal with the object type you just created. So you do in fact write the important part of your program in standard Java, and leave Linguist to provide an overall structure.

A full-blown scripting language based on Linguist will have many hundreds to several thousand classes, organized into maybe a dozen or more packages. This may seem daunting, but it reflects the highly modular nature of the system. Each class does a single job, and you'll hardly see a switch statement anywhere. Linguist provides a framework that demands a totally modular approach to program design, but the result is very reliable code. Most of the classes tend to occupy less than two pages of listing. In effect, Linguist trades lots of subroutines for lots of classes. Incidentally, Linguist would be very difficult to create using C++, and even Java 1.0 lacks important features - notably serialization - that make Linguist possible.

The Linguist development environment

Because Linguist is simply Java with knobs on, we don't supply a separate development environment. To develop your own language based on Linguist, the first thing you need is your favorite Java development environment. This can be Java Workshop, Visual Cafe, Visual J++, JBuilder - whatever tool you like best. Create a new project with the Linguist files and supporting classes and you're ready to go.

As you create new keyword and runtime handlers they are placed in predefined packages, where they will instantly be available to unlock their new capabilities. As each new feature is added a simple test script will verify its behavior.

Debugging

Linguist provides you with one of the most advanced debugging tools available anywhere. In part, that's because - as with the language itself - the debugger can be tailored to do just what you need, instead of restricting you to what we could imagine. But the most impressive feature of the debugger is that it's 'live'. In other words, it allows you to examine your script while it's actually running - without the need to stop to look at variables. Click on a line in the script window and the program will stop the next time it reaches that line. Every aspect of the debugger can be customized, so if you want to stop only if some arbitrary condition - unforeseen by us - is met, simply write the appropriate test class and hook it in.

Embedded scripts

Maybe you would like to add a scripting facility to some other Java product. When you start up Linguist you have the option of passing it an arbitrary data Object that can be accessed from the script. You create script handlers that read and write to this object, then as the script runs in its own thread the calling program can see the results. So your product instantly has an internal scripting language without very much coding on your part.


Back to index