Multiple Interpreters

Until makes writing applications with multiple interpreters trivial. The normal Until outer interpreter is only about half a page of code. Writing a specialized interpreter for an application is a very powerful capability. The core interpreter can be used as a starting point for other any specialized interpreter.

A typical approach is using the normal Until interpreter for startup to load the application (.APP) file, then invoke the application specific interpreter. The is the approach take for the IFP program in [SMITH2].

#### UPDATE ####

Another successful multi-interpreter application is a document interpreter for Standard Generalized Markup Language (SGML) documents. A document viewer was easily built on top of the SGML interpreter that executes the document as a program to format and display the document's contents. This software is available via anonymous FTP at FTP.IFI.UIO.NO in the directory /pub/SGML/Demo/. The files are sengine.zip for the SGML document interpreter and sviewer.zip for the SGML document viewer.


SEALING AN APPLICATION

The rough equivalent of saving a turnkey application is sealing an Until program. Sealed applications have the code hidden or 'sealed' from the user. Sealing does not save the current state of the system the way most traditional Forths do. The approach taken for Until is to encrypt the source code then load it in the crypted form. The last thing in the file must be the word that executes the application.

Sealing an application is done with the seal word:

  seal until.app
The file UNTIL.BIN is created in this case.

seal is crude, but effective. There appears to be not good way to save the state of the dictionary that is not too complex and portable. There are several enhancements that could be made to seal. These include:

A word, unseal, is included to allow you to view the result of seal. If you are distributing sealed code, you might want to disable unseal.

  unseal until.bin

VOCABULARIES

This section does not detail the Until implementation of vocabularies; rather it simply identifies the words that are affected by vocabulary operations. i.e. If you change anything relating to vocabularies, count on having to change these words too!

Refer to the code in VOCAB.C for implementation details. The Until vocabulary structure is based on the Fig-Forth model rather than Forth-83.


8. C-LEVEL VECTORED I/O

This section describes the C-level I/O vector features in Until. Skip Carter originally supplied these changes. C I/O vector code is activated by defining the symbol VECTORED_C_IO in COMPILER.H. Including this code slows normal processing slightly because some additional function calls are made and there is a level of indirection to all writes to the screen, whether informational messages or Forth console output words such as type or emit also are slower.

Two typical uses of this code are directing output to a file or communicating across a network. Skip original test program set up a socket network interface and ran Until on a remote computer.

The general scheme is to set the vectors using the user_outer_hook() function to set up the vectors. The vectors are stdout_vect, stderr_vect, and stdin_vect.

The Forth words affected by VECTOREC_C_IO are:

Those are the hints; implementation details are left to the reader. (Hopefully, I'll fill in some details in a future update.)


9. S-Engine

S-Engine is a Standard Generalized Markup Language (SGML) document interpreter that embeds Until to form a powerful scripting language for processing SGML documents. SGML is ISO Standard 8879:1986 and is widely used by both government and industry.

SGML is a language for defining document markup languages. Think of a markup language for memos for example. You define tags for <from>, <to>, <subject>, etc. SGML markup languages generally defines document structure rather than document format. There are exceptions. HTML is an SGML defined markup language that defines electronic document format rather than structure.

S-Engine reads the SGML file, extracts tags, then executes them as a word. There is a very structured scheme for using S-Engine. Each SGML element is treated as an event where SGML data is collected or processed. The general scheme is:

Now let's see a simple example. This code can be found in the files SGMLEX.APP and SGMLEX.SGM. There is only one element, element, one attribute, attrib, and one entity, SGML. So, the following variables must be set up:

  4096 string element
  32   string attrib
Now, define the element and entity colon definitions:
  : <element>
     element read_into
     ." Got element..." cr
     ."   attrib is " attrib dup strlen type cr
     ;
  : </element>
     ." The SGML data collected in element is: " cr
     element dup strlen type cr
     ;
  : &SGML;
     " Standard Generalized Markup Language"
     ;
  " sgmlex.sgm" sengine_init
  sengine
This is all there is to it. Assume the input of:
<element attrib="an example">This is an example
&SGML; test file. It is really simple, but
illustrates how an S-Engine program works.
</element>
will produce the following:
Got element...
  attrib is an example
This is an example
Standard Generalized Markup Language test file. It is really simple, but
illustrates how an S-Engine program works.

There is a complete example in the sample files.


10. SAMPLE UNTIL SOURCE FILES

This section identifies and describe the sample Until source files. Some, but not all of these files are described in various places in this manual. I figured the more examples the better, so I included extra files in the distribution.

ADD.APP
A filter program that adds a file of numbers.
ADDR.APP
An S-Engine application to print an address book.
ADDRESS.APP
An S-Engine application to convert the address book into HTML.
APPLIC.APP
A simple default application file.
FILEXAMP.APP
The File Word example code from the Ref Manual.
FILTER.APP
Sample file filter.
HELP.APP
The help file used inside Until.
PCOLON.APP
Sample Until program to print all colon definitions in a source file.
SPLITHTM.APP
Sample Until program that splits up large HTML files.
STOIC.APP
The Stoic String package.
STREXAMP.APP
C String example from the documentation.
UNTIL.APP
Default, minimal startup code. It is sealed into UNTIL.BIN.

Table of Contents
Next Section