Glisp(ID:1552/gli005)

Alternate syntaxes for Common Lisp 


Generalized LISP. David Canfield Smith, Apple, August 1990

GLISP: Alternate syntaxes for Common Lisp

A coordinated set of high-level syntaxes for Common LISP. Contains Mlisp, Plisp and ordinary LISP, with an extensible framework for adding others.

Written in Plisp.

"Generalized Lisp (or Glisp for short) is a coordinated set of high level syntaxes for Common Lisp.  It is generalized in the sense that the Lisp programmer has a variety of dialects available, not just Lisp notation.  Initially Generalized Lisp consists of three dialects: Mlisp, Plisp and ordinary Lisp, together with an extensible framework for adding others.  Mlisp (Meta-Lisp) is an Algol-like syntax for people who don't like writing parentheses.  Plisp (Pattern Lisp) is a pattern matching rewrite-rule language.  Plisp is a compiler-compiler; its rules are optimized for writing language translators.  Mlisp and Plisp are documented in separate user manuals.  It is expected that the set of dialects will increase over time as users add new ones.  All dialects may be freely intermixed in a file.

The translators for all dialects are written in Plisp, as is the Glisp translator framework itself.  Support routines for the translators are written in Mlisp and/or Lisp.  All dialects are translated to Common Lisp and execute in the standard Common Lisp environment."


Related languages
PLisp => Glisp   Written using

References:
  • Canfield Smith, David "Generalized Lisp Version 1.2 User's Manual" Apple Computer, Inc 1990 view details Extract: What is Generalized Lisp?
    What is Generalized Lisp?
    "Generalized Lisp" (or "Glisp". for short) is a coordinated set of high level syntaxes for Common Lisp.  It is "generalized" in the sense that the Lisp programmer has a variety of dialects available, not just Lisp notation.  Initially Generalized Lisp consists of three dialects: Mlisp, Plisp and ordinary Lisp, together with an extensible framework for adding others.  Mlisp ("Meta-Lisp") is an Algol-like syntax for people who don't like writing parentheses.  Plisp ("Pattern Lisp") is a pattern matching rewrite-rule language.  Plisp is a "compiler-compiler"; its rules are optimized for writing language translators.  Mlisp and Plisp are documented in separate user manuals.  It is expected that the set of dialects will increase over time as users add new ones.  All dialects may be freely intermixed in a file.
    The translators for all dialects are written in Plisp, as is the Glisp translator framework itself.  Support routines for the translators are written in Mlisp and/or Lisp.  All dialects are translated to Common Lisp and execute in the standard Common Lisp environment.
    Per line of code, Glisp is perhaps the world's most powerful programming language.  There are only two functions in the Glisp translator, yet it can handle an arbitrary number of language dialects.  The entire Glisp translator follows:

    glispProgram =
         ~ A Glisp program is a sequence of expressions in any Glisp language.

         [ :p ]*    ->  ( [::p]* );


    glispLanguage =
         ~ A Glisp language is Plisp, Lisp, or a dialect added by someone.

         '- Plisp '-  :p  -> :p,

         '- Lisp  '-  :p   -> :p,

         '- define language :lang '-  ->   nil;
    Extract: The Glisp translator
    The Glisp translator
    These functions are written in Plisp.  The first function, glispProgram, is the main driver function.  It calls the second function, glispLanguage, repeatedly via the repeat [ ]* mechanism.  The value returned from each call is added to the variable p.  By convention, glispLanguage is expected to return a list of translated expressions; p therefore will contain a list of lists.  The repeat loop will terminate when glispLanguage fails, indicating that it was unable to find a legal program in one of the dialects.  The eof function then checks for end-of-file (actually end-of-stream), indicating that all of the input was translated.  If it wasn't, the entire glispProgram fails.  If it was, then the translation of a Glisp program is a single linear list of the translated expressions from all of the dialects involved.
    The second function, glispLanguage, contains the rules for switching dialects in Glisp.  The next section describes this.  It also contains a special rule for defining a new language dialect:      '- define language :lang '-  ->   nil An example would be      -define language Mlisp- The effect of this rule is to (a) define the identifier as the name of a new Glisp dialect, and (b) set it to be the name of the language whose translator is being defined by the current program.  Notice that the right side of this rule has a call to targetLanguage.  targetLanguage is a function defined in the Plisp dialect that sets Plisp's "target language.".  The meaning of "target language" is the following:
    All unquoted literal identifiers on the left sides of rules are declared to be "reserved words" in the target language.
    Reserved words are discussed in the Plisp User's Manual.  The important thing to mention here is that all reserved words are exported from the current package, if the package is different than "USER".  This insures that programs using these reserved words will be translated correctly when they are read from within other packages.
    As an example, consider the following fragment of a program:

    -define language Foo-

    -Plisp-

    conditionalExpression =
         if  :e1  then  :e2  else  :e3  ->
              (cond (:e1 :e2) (t :e3));


    The first line says that the language being defined by this program is named "Foo."  The second line says that the following part of the program is written in the Plisp dialect.  The next three lines define a function in the Foo translator called conditionalExpression.  In its one rule, if, then and else will be reserved words in the Foo language and will be exported from Foo's package, if any.  Note that expression, e1, e2 and e3 are not reserved words, since they are not literals.   is a function call; and :e1, :e2 and :e3 are variable references.  (See the Plisp manual.)

    Resources