General Information

 o Eli: Translator Construction Made Easy
 o Global Index
 o Frequently Asked Questions

Tutorials

 o Quick Reference Card
 o Guide For new Eli Users
 o Release Notes of Eli
 o Tutorial on Name Analysis
 o Tutorial on Type Analysis

Reference Manuals

 o User Interface
 o Eli products and parameters
 o LIDO Reference Manual

Libraries

 o Eli library routines
 o Specification Module Library

Translation Tasks

 o Lexical analysis specification
 o Syntactic Analysis Manual
 o Computation in Trees

Tools

 o LIGA Control Language
 o Debugging Information for LIDO
 o Graphical ORder TOol

 o FunnelWeb User's Manual

 o Pattern-based Text Generator
 o Property Definition Language
 o Operator Identification Language
 o Tree Grammar Specification Language
 o Command Line Processing
 o COLA Options Reference Manual

 o Generating Unparsing Code

 o Monitoring a Processor's Execution

Administration

 o System Administration Guide

 Questions, Comments, ....

Tutorial on Type Analysis

Previous Chapter Next Chapter Table of Contents


Array Types

We now add arrays to our language in order to show how types are represented by freely chosen properties (in contrast to the scope property of record types). We only have to extend the grammar by notations for array type denoters and by indexed variables:

The following concrete productions are added:

Array.con[43]==


TypeDenoter:    ArrayType.
ArrayType:      TypeDenoter '[' IntNumber ']'.
Variable:       Variable '[' Expression ']'.

This macro is attached to a product file.

Here is an example program that uses arrays, records, and type definitions in combination: ArrayExamp[44]==

begin
  var   int k;
  var   int[5] pi, int[5] pj;
  var   record int i, bool b, real[3] r end [2] rv;
  type  bool[4] bt;
  var   bt vbt, bt wbt;
  var   real[6][7] m;
  pi[1] = k;
  vbt = wbt;
  rv[2].b = true;
  rv[1].r[k] = 3.2;
  m[1][k] = 1.0;
end

This macro is attached to a product file.

Here, an array type is represented by the type and the number of its elements:

Array.pdl[45]==


ElemType:       DefTableKey [KReset];
ElemNo:         int [KReset];

This macro is attached to a product file.

An ArrayType introduces a new type different from any other (role TypeDenotation). Its Type attribute is just passed upward.

With respect to equality of type the same considerations apply as were made above for record types.

The properties that characterize the array type are set in a combined computation establishing the postcondition ArrayType.GotType, which is essential to ensure correct access of these properties.

ArrayType.lido[46]==


SYMBOL ArrayType INHERITS TypeDenotation END;

RULE: TypeDenoter ::= ArrayType COMPUTE
  TypeDenoter.Type = ArrayType.Type;
END;

TERM IntNumber: int;

RULE: ArrayType ::= TypeDenoter '[' IntNumber ']' COMPUTE
  ArrayType.GotType = 
     ResetElemType
       (KResetElemNo
          (KResetTypeName (ArrayType.Type, "array..."),
           IntNumber),
        TypeDenoter.Type);
END;

This macro is attached to a product file.

The type of an indexed variable is the element type of the array variable. The function TransDefer has to be applied for the accessed element type, in order to get the type key rather than a key of a type identifier referring to it.

Array.lido[47]==


RULE: Variable ::= Variable '[' Expression ']' COMPUTE
  Variable[1].Type =
        TransDefer (GetElemType (Variable[2].Type, NoKey));

  Expression.ReqType = intType;

  IF (EQ (Variable[1].Type, NoKey),
  message (ERROR, "index applied to non array", 0, COORDREF));
END;

This macro is attached to a product file.


Previous Chapter Next Chapter Table of Contents