|
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tutorial on Type AnalysisDeclaration of Typed Objects
We here consider a variable declaration as an example for
a language construct that defines a typed object.
In our language a variable declaration may define several
variables. An
We use the module Declare.specs[14]== $/Type/Typing.gnrc:inst This macro is attached to a product file.
Types are represented by
The pair of module roles Declare.lido[15]== SYMBOL ObjDecl INHERITS TypedDefinition END; SYMBOL DefIdent INHERITS TypedDefId END; ATTR Type: DefTableKey; RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE ObjDecl.Type = TypeDenoter.Type; END; This macro is attached to a product file.
The module roles
The use of TypeUseIdent.lido[16]== SYMBOL UseIdent INHERITS TypedUseId, ChkTypedUseId END; SYMBOL TypeUseIdent INHERITS TypeDefUseId, ChkTypeDefUseId END; RULE: TypeDenoter ::= TypeUseIdent COMPUTE TypeDenoter.Type = TypeUseIdent.Type; END; This macro is attached to a product file.
In order to report some results of the type analysis
we associate the string valued property
The specification PrtType.pdl[17]==
TypeName: CharPtr [KReset]; "Strings.h"
intType -> TypeName = {"int"};
realType -> TypeName = {"real"};
boolType -> TypeName = {"bool"};
voidType -> TypeName = {"void"};
This macro is attached to a product file. For every used identifier that string is to be printed: PrtType.lido[18]==
SYMBOL UseIdent INHERITS PrtType END;
SYMBOL PrtType COMPUTE
printf ("line %d Type %s\n", LINE,
GetTypeName (THIS.Type, "no type name"));
END;
This macro is attached to a product file.
|