Parsifal Software


XIDEK
Extensible Interpreter Development Kit


Baseline Languages

Introduction

As a baseline for development, two simple languages were developed. The first, CLL, is a C-like language, which implements the basic expression and statement syntax of C, although it does not implement declarations, subscripts or switch statements. Why C? Many computer languages in fact use an underlying statement syntax which is similar to that of C. Also, because C is so well-known, for most people there is less new material to be learned and less explanation required.

The second language, PLL, is more like Pascal. It was created by stripping CLL of its more esoteric features and syntax and replacing them with simpler, Pascal-like constructs. PLL might well be preferred by a developer whose end users are not professional programmers.

It is particularly important to note that interpreters for both languages use the same support code. Also, the changes required for the example extensions are very nearly identical.

All the interpreters in the kit implement both integer and real arithmetic, as well as limited string capabilities. Apart from the syntactic rules for recognizing constants, these capabilities are implemented as member functions of the Value class. An extension to support complex arithmetic demonstrates the methods for extending these capabilities.

Overview of CLL - a C-Like Language

The CLL language is defined by the syntax specified in cll.syn. The syntax files which parse the CLL language, dxi.syn, dci.syn, and ast.syn, (ast.syn is used by both astxi and astci) are basically cll.syn with reduction procedures added to implement the particular functionality required by the different interpreters.

Detailed reference documentation for the CLL language syntax is provided in the CLL reference.

The CLL syntax supports the basic elements of a script language: recognition of variable names and constants, evaluation of expressions, and execution of conditional and loop statements, all based on the familiar C syntax. These may fairly be regarded as the portions of C that have become more or less standard and are not the subject of any significant controversy. Omitted are declarations, pointers, subscripts, and switch statements. The C features implemented consist of (links are to the CLL reference):

This means, as a practical matter, that if the intended users of an interpreter already know C, documentation requirements are minimal.

The CLL syntax also contains three additional elements. To illustrate changes in expression syntax, Fortran style exponentiation has been added. To aid in debugging scripts and to illustrate how to add new statements to the grammar, dump and print statements have been added.

The following features of C have not been implemented:

  • Declarations, including function definitions.
  • Switch statements
  • Pointer arithmetic
  • Arrays and subscripts
  • Structs and objects
Declaration statements are a fertile source of controversy. If you survey programming languages, you don't find any sign of a consensus. The declaration syntax for C is so complex it is understood in its entirety by very few programmers. Accordingly, it was decided to forego declaration statements.

Some of the missing functionality has been implemented in three extensions to the basic syntax:

All of these extensions are combined in the combine extension.

Since there are many ways to implement these features, all of which have their own benefits and shortcomings, these extensions are provided simply as examples and should be seen simply as suggestions as to how to proceed.


Overview of PLL - a Pascal-Like Language

The CLL language may well be viewed as too "complicated" for some applications. Indeed, many expert C programmers find it difficult to remember the details of the C expression syntax with its many levels of precedence. If the intended class of users of an interpreter is not familiar with C, the advantage of compatibility with C vanishes and it might be desirable to implement a more user-friendly syntax.

To demonstrate how to modify the language to make it "simpler", XIDEK contains an example of an alternate language, PLL, many of whose features are drawn from Pascal. It will be noted that while there are substantial changes to the syntax file, interpreters for both languages can use the same support code. Here is a summary of the changes made to CLL to create PLL. The changes are described in detail in the PLL reference.

  • Case Sensitivity
    Keywords and variable names are not case sensitive.
  • Expression Syntax
    The complex expression syntax of C is replaced with a more Pascal-like syntax. In particular, there are far fewer precedence levels and no opportunity for side effects. Various relational and arithmetic operators have been changed to correspond to Pascal usage. Autoincrement and autodecrement operators have been removed.
  • Assignment Statement Syntax
    An explicit assignment statement has been introduced, using the Pascal := operator to replace the C expression statement.
  • Block Statement Syntax
    Statement blocks are delimited with the begin and end keywords instead of braces.
  • If Statement Syntax
    The if statement is reconfigured to delimit the conditional expression with the keyword then instead of using parentheses.
  • While Statement Syntax
    The while statement is reconfigured to delimit the conditional expression with the keyword do instead of using parentheses.
  • Repeat Until Statement
    The do/while statement is replaced with a repeat/until statement.
  • For Statement Syntax
    The C for statement has been replaced with a Pascal-like for statement. The downto option has not been implemented, but on the other hand, the increment may be either positive or negative.
  • Break and Continue Statements
    These statements have been removed.



Table of Contents | Parsifal Software Home Page


Interpreter Development Kit
Copyright © 1997-2002, Parsifal Software.
All Rights Reserved.