Eli   Documents Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads

General Information

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

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
 o Typical Eli Usage Errors

Reference Manuals

 o User Interface
 o Eli products and parameters
 o LIDO Reference Manual
 o Typical Eli Usage Errors

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

Mail Home

Tutorial on Name Analysis

Previous Chapter Table of Contents


Objects Having a Scope Type

This example demonstrates a typical situation where the tasks of name analysis and type analysis are interleaved. Since type analysis is not the topic of this tutorial, we concentrate on one aspect where it affects name analysis.

We extend our language by class variables. Such a variable is declared by v : c where c is a class identifier. The variable v is a structure that has the components declared for c and for the classes inherited by c.

With this extension class declarations can be considered as declarations of type names which are used as type identifiers in variable declarations.

In order to access the components of a class variable, we introduce a selection construct that is similar to the qualified access construct:

ScopeType.con[32]==

Operand:        UseIdent '.' SelectIdent.
SelectIdent:    Ident.
This macro is attached to a product file.

We here specify a very simple version of type analysis: Types are represented by DefTableKeys. A property TypeOf associates a type with an object key:

ScopeType.pdl[33]==

TypeOf: DefTableKey;
This macro is attached to a product file.

The following computational roles specify how the TypeOf property is set and accessed in proper order:

TypeModule.lido[34]==

ATTR Type: DefTableKey;

CLASS SYMBOL RootType COMPUTE
  SYNT.GotType = CONSTITUENTS SetType.GotType;
END;

CLASS SYMBOL SetType COMPUTE
  SYNT.GotType = ResetTypeOf (THIS.Key, INH.Type);
END;

CLASS SYMBOL GetType COMPUTE
  SYNT.Type = GetTypeOf (THIS.Key, NoKey)
        <- INCLUDING Program.GotType;
END;
This macro is attached to a product file.

Usually the defining occurrences of identifiers, DefIdent in our language, are the contexts where the type of the object is specified. Hence they have the role of SetType.

As we here are only interested in types of variables, we specify a default unknown type represented by NoKey. In variable declarations the type of the declared identifier is specified to be the key of the type identifier.

In the context of applied identifier occurrences, UseIdent, their type may be used for further analysis. They have the role GetType.

ScopeType.lido[35]==

SYMBOL DefIdent INHERITS SetType COMPUTE
  INH.Type = NoKey;
END;

RULE: VarDecl ::= TypeUseIdent DefIdent COMPUTE
  DefIdent.Type = TypeUseIdent.Key;
END;

SYMBOL UseIdent INHERITS GetType END;

SYMBOL Program INHERITS RootType END;
This macro is attached to a product file.

The select construct combines the technique of using a scope property, as introduced for qualified access (QualIdent above), and type analysis: SelectIdent has the QualIdUse role. The identifier is bound in the scope associated with the type of the variable identifier. SelectIdent.ScopeKey is specified to be the key that has the scope property.

SelectType.lido[36]==

SYMBOL SelectIdent INHERITS
        QualIdUse, 
        ChkQualIdUse, IdentOcc
END;

RULE: Expression ::= UseIdent '.' SelectIdent COMPUTE
  SelectIdent.ScopeKey = UseIdent.Type;

  IF (EQ (SelectIdent.Scope, NoEnv),
  message (FATAL, "module variable required for selection",
           0, COORDREF))
  ;
END;
This macro is attached to a product file.

Similar to previous examples we have to check that the type of the variable really allows selection.


Previous Chapter Table of Contents