Jump to content

XL (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 161.114.126.50 (talk) at 15:44, 7 October 2005. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

XL stands for eXtensible Language. It is a computer programming language designed to support concept programming.

XL features programmer-reconfigurable syntax and semantics. Compiler plug-ins can be used to add new features to the language. A base set of plug-ins offer a relatively standard imperative language. Programmers can write their own plug-ins to implement application-specific notations, such as symbolic differentiation, which can then be used similarly to built-in language features.

Language

XL is defined at three different levels:

  • XL0 defines how an input text is transformed into a parse tree.
  • XL1 defines a base language with features comparable to C++
  • XL2 defines the standard library, which includes common data types and operators.

XL has no primitive types nor keywords. All useful operators and data types, like integers or addition, are defined in the standard library (XL2). XL1 is portable between different execution environments. There is no such guarantee for XL2: if a particular CPU does not implement floating-point multiplication, the corresponding operator definition may be missing from the standard library, and using a floating-point multiply may result in a compile-time error.

The Hello World program in XL looks like the following:

 import IO = XL.TEXT_IO
 IO.WriteLn "Hello World"


Syntax

Syntax is defined at the XL0 level. The XL0 phase of the compiler can be configured using a syntax description file, where properties like the text representation and precedence of operators are defined. A basic syntax file defines common mathematical notations, like + for addition, with the usually accepted order of operations.

The parse tree consists of 7 node types, 4 leaf node types (integer, real, text and symbol) and 3 internal node types (infix, prefix and block).

  • integer nodes represent an integer literal, such as 2. The # sign can be used to specify a base other than 10, as in (2#1001). A separating underscore can be used to improve readability, as in 1_000_000.
  • real nodes represent non-integral numbers, such as 2.5. Based-notations and separators can be used, as for integer nodes, for example 16#F.FFF#E-10 is a valid real literal.
  • text nodes represent textual contents. They are normally surrounded by simple or double quotes, like "Hello" or 'a', but the syntax file can be used to add other separators, including for multi-line textual contents.
  • symbol nodes represent names or operators. Names are sequence of alphanumeric characters beginning with a letter, like Hello. XL0 preserves case, but XL1 ignores case and underscores, so that JohnDoe and john_doe are the same name. Symbols are sequence of non-alphanumeric characters, like * or =/=.
  • infix nodes represent two nodes related by an infix symbol, like A+1 or 2 and 3. Infix nodes are in particular used to separate lines, with an infix "new-line" symbol.
  • prefix nodes represent two consecutive nodes, like Write "Hello". It is also used for postfix notations, like 3! or Open?.
  • block nodes represent a node surrounded by grouping symbols, like (A), [Index]. Indentation is internally represented by a block node.

With the default syntax file, the following is valid XL0, irrespective of any semantics.

A = B + "Hello"

It parses as:

infix("=",
      symbol("A"),
      infix("+",
            symbol("B"), text("Hello")))


Semantics

The XL1 phase is defined as a sequence of operations on the XL0 parse tree. These operations are provided by various compiler plug-ins, that are triggered based on the shape of the parse tree.

Special constructs, translate and translation, are provided by a plug-in designed to facilitate the writing of other plug-ins. The quote construct generates a parse tree. Here is how these notation can be used to implement a plug-in called ZeroRemoval that eliminates superfluous additions and multiplications by zero.

translation ZeroRemoval
  when
    'X' + 0
  then
    return X
  when
    'X' * 0
  then
    return quote(0)

The XL1 phase contains a large set of plug-ins, notably XLSemantics, that provide common abstractions like subroutine, data type and variable declaration and definition, as well as basic structured programming statements, like conditionals or loops.


The SourceForge development page