General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tutorial on Name AnalysisObjects Having a Scope TypeThis 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 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 ScopeType.pdl[33]== TypeOf: DefTableKey; This macro is attached to a product file.
The following computational roles specify how the 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,
As we here are only interested in types of variables, we specify
a default unknown type represented by
In the context of applied identifier occurrences, 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 ( 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.
|