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


Different Kinds of Objects

After having introduced variables to our language in the last section, we need to indicate which kinds of program objects exist in the language, and how are they distinguished. So far we have types, variables, and the two predefined boolean constants being program objects. The contexts where a type is required are distinguished from other contexts by using the roles of the Typing module and its IsType property.

Furthermore we have to ensure that on the left-hand side of an assignment there is really a variable, rather than a boolean constant. (An erroneous use of a type is captured by the above mentioned distinction.) That distinction can not be made using the TypeOf property. We need to characterize declared variables by an additional property, and check it in the context of assignments. In our case it is sufficient just to state whether the declared object is a variable. (In more complicated languages we may need several different kinds to be distinguished.)

IsVariable.pdl[24]==


IsVariable: int;

This macro is attached to a product file.

As ObjDecls will be used for declaration of objects other than variables we pass an attribute IsVariable down from the variable declaration context the DefIdents, using a default value for other contexts.

The IsVariable property is set in the DefIdent context. The GotProp attribute is provided by the TypedDefId role in order to set arbitrary properties of defined objects along with the type property. The module ensures that these properties can be accessed when the type property is accessible.

IsVariable.lido[25]==


SYMBOL ObjDecls, DefIdent: IsVariable: int;
SYMBOL ObjDecls COMPUTE INH.IsVariable = 0; END;
SYMBOL DefIdent COMPUTE INH.IsVariable = 0; END;

RULE: Declaration ::= 'var' ObjDecls ';' COMPUTE
  ObjDecls.IsVariable = 1;
END;

RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE
  DefIdent.IsVariable = INCLUDING ObjDecls.IsVariable;
END;

SYMBOL DefIdent COMPUTE
  INH.GotProp = ResetIsVariable (THIS.Key, THIS.IsVariable);
END;

This macro is attached to a product file.

We now need to mark those contexts of the Variable symbol which are required to denote a variable object; i. e. the left-hand side of assignments, and check the IsVariable property there. (Other alternatives of Variable, which will be introduced later, can not yield a constant. Hence, we can apply the default technique for the attribute VariableNeeded.)

ChkVariable.lido[26]==


SYMBOL Variable: VariableNeeded: int;
SYMBOL Variable COMPUTE INH.VariableNeeded = 0; END;

RULE: Statement ::= Variable '=' Expression ';' COMPUTE
  Variable.VariableNeeded = 1;
END;

RULE: Variable ::= UseIdent COMPUTE
  IF (AND (Variable.VariableNeeded,
           NOT (GetIsVariable (UseIdent.Key, 0))),
  message (ERROR, "variable required", 0, COORDREF))
  <- Variable.Type;
END;

This macro is attached to a product file.

The dependency <- Variable.Type above ensures that the property IsVariable is not accessed before the type property of the objects is set, and the IsVariable along with it.

(For our simple language, where only the predefined boolean constants can violate the above condition, we could have specified the check for variables even simpler: Just state that true and false do not have the IsVariable property. But we wanted to demonstrate here how to set other properties along with the type property.)


Previous Chapter Next Chapter Table of Contents