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


Type Checking in Expressions

The type property of simple expressions is just propagated upwards using the attribute Type. How operators are handled is shown later.

ExprType.lido[19]==


RULE: Expression ::= IntNumber COMPUTE
  Expression.Type = intType;
END;

RULE: Expression ::= RealNumber COMPUTE
  Expression.Type = realType;
END;

RULE: Expression ::= Variable COMPUTE
  Expression.Type = Variable.Type;
END;

RULE: Variable ::= UseIdent COMPUTE
  Variable.Type = UseIdent.Type;
END;

This macro is attached to a product file.

Occurrences of Expression in certain contexts require that their type be compatible to a type imposed by the context. Hence, we introduce an inherited attribute ReqType and a check for compatibility. The function CompatibleTypes is defined below.

ExprTypeChk.lido[20]==


SYMBOL Expression: ReqType: DefTableKey;
SYMBOL Expression COMPUTE
  IF (NOT (CompatibleTypes (THIS.ReqType, THIS.Type)),
  message (ERROR, "expression does not have the required type",
           0, COORDREF));
END;

RULE: Statement ::=  Expression ';' COMPUTE
  Expression.ReqType = voidType;
END;

RULE: Statement ::= Variable '=' Expression ';' COMPUTE
  Expression.ReqType = Variable.Type;
END;

This macro is attached to a product file.

Compatibility of two types is specified as follows: A type narrow is compatible to a type wide if narrow and wide are equal types, or if narrow is the int type and wide is the real type, or if wide is the void type and narrow is any type.

Two types are equal if they stem from one occurrence of a type denoter, disregarding any renaming of that type. Further below additional rules for type equality are added.

These rule are specified by the following two functions. The function EqualTypes also takes care of erroneous cases in order to avoid avalanche errors: The unknown type, represented by NoKey is considered to be equal to any type.

Compatible.c[21]==


#include "Compatible.h"
#include "pdl_gen.h"
#include "eliproto.h"
#include "TypeFct.h"

#ifdef PROTO_OK
int EqualTypes (DefTableKey t1, DefTableKey t2)
#else
int EqualTypes (t1, t2) DefTableKey t1, t2;
#endif
{
  t1 = TransDefer (t1); t2 = TransDefer (t2);
  if ((t1==NoKey) || (t2==NoKey) || (t1==t2)) return 1;

/* Insertion precondition:
   t1 and t2 are different type keys, and
   both are different from NoKey.
*/
#include "EqualTypes.h"
/* Insertion postcondition:
   There is no language rule applicable that states
   t1 considered to be equal to t2.
*/

  return 0;
}

#ifdef PROTO_OK
int CompatibleTypes (DefTableKey wide, DefTableKey narrow)
#else
int CompatibleTypes (wide, narrow) DefTableKey wide, narrow;
#endif
{
  if (EqualTypes (wide, narrow)) return 1;
  wide = TransDefer (wide); 
  narrow = TransDefer (narrow);
  if (wide == voidType) return 1;
  if (wide == realType && narrow == intType) return 1;
  return 0;
}

This macro is attached to a product file.

The implementation above includes two files TypeFct.h and EqualTypes.h. They are composed by the phi tool. The contributions to them are specified below, when we add further rules for type equality. The same technique is applied in the header file below.

Compatible.h[22]==


#include "deftbl.h"
#include "eliproto.h"

extern int EqualTypes ELI_ARG((DefTableKey t1, DefTableKey t2));
extern int CompatibleTypes ELI_ARG((DefTableKey wide, DefTableKey narrow));

#include "TypeFctHdr.h"

This macro is attached to a product file.

Compatible.head[23]==


#include "Compatible.h"

This macro is attached to a product file.


Previous Chapter Next Chapter Table of Contents