![]() |
![]() |
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
![]() |
![]() |
Tutorial on Type AnalysisType Checking in Expressions
The type property of simple expressions is just propagated
upwards using the attribute 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 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 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 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 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.
|