File: type_1.html

package info (click to toggle)
eli-doc 4.4.0-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,256 kB
  • ctags: 4,583
  • sloc: makefile: 42
file content (488 lines) | stat: -rw-r--r-- 20,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.29
     from ../tnf/type.tnf on 12 Febuary 2003 -->

<TITLE>Type analysis tasks - Basic Type Analysis</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000" BACKGROUND="gifs/bg.gif">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0" VALIGN=BOTTOM>
<TR VALIGN=BOTTOM>
<TD WIDTH="160" VALIGN=BOTTOM><IMG SRC="gifs/elilogo.gif" BORDER=0>&nbsp;</TD>
<TD WIDTH="25" VALIGN=BOTTOM><img src="gifs/empty.gif" WIDTH=25 HEIGHT=25></TD>
<TD ALIGN=LEFT WIDTH="600" VALIGN=BOTTOM><IMG SRC="gifs/title.gif"></TD>
</TR>
</TABLE>

<HR size=1 noshade width=785 align=left>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
<TR>
<TD VALIGN=TOP WIDTH="160">
<h4>General Information</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="index.html">Eli: Translator Construction Made Easy</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gindex_toc.html">Global Index</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="faq_toc.html" >Frequently Asked Questions</a> </td></tr>
</table>

<h4>Tutorials</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="EliRefCard_toc.html">Quick Reference Card</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="novice_toc.html">Guide For new Eli Users</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="news_toc.html">Release Notes of Eli</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="nametutorial_toc.html">Tutorial on Name Analysis</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="typetutorial_toc.html">Tutorial on Type Analysis</a></td></tr>
</table>

<h4>Reference Manuals</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ui_toc.html">User Interface</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="pp_toc.html">Eli products and parameters</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lidoref_toc.html">LIDO Reference Manual</a></td></tr>
</table>

<h4>Libraries</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lib_toc.html">Eli library routines</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="modlib_toc.html">Specification Module Library</a></td></tr>
</table>

<h4>Translation Tasks</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lex_toc.html">Lexical analysis specification</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="syntax_toc.html">Syntactic Analysis Manual</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="comptrees_toc.html">Computation in Trees</a></td></tr>
</table>

<h4>Tools</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lcl_toc.html">LIGA Control Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="show_toc.html">Debugging Information for LIDO</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gorto_toc.html">Graphical ORder TOol</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="fw_toc.html">FunnelWeb User's Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ptg_toc.html">Pattern-based Text Generator</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="deftbl_toc.html">Property Definition Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="oil_toc.html">Operator Identification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="tp_toc.html">Tree Grammar Specification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="clp_toc.html">Command Line Processing</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="cola_toc.html">COLA Options Reference Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="idem_toc.html">Generating Unparsing Code</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="mon_toc.html">Monitoring a Processor's Execution</a> </td></tr>
</table>

<h4>Administration</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="sysadmin_toc.html">System Administration Guide</a> </td></tr>
</table>

<HR WIDTH="100%">
<CENTER>&nbsp;<A HREF="mailto:elibugs@cs.colorado.edu"><IMG SRC="gifs/button_mail.gif" NOSAVE BORDER=0 HEIGHT=32 WIDTH=32></A><A HREF="mailto:elibugs@cs.colorado.edu">Questions, Comments, ....</A></CENTER>

</TD>
<TD VALIGN=TOP WIDTH="25"><img src="gifs/empty.gif" WIDTH=25 HEIGHT=25></TD>

<TD VALIGN=TOP WIDTH="600">
<H1>Type analysis tasks</H1>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_2.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
<A NAME="IDX7"></A>
<H1><A NAME="SEC1" HREF="type_toc.html#SEC1">Basic Type Analysis</A></H1>
<P>
This module implements a set of concepts that are basic for
the type analysis task in many statically typed languages:
Definition and use of typed objects, notation of user defined
types, and definition and use of  type identifiers.
<P>
The use of this module is demonstrated in
the following section, which intorduces a running example.
A complete executable specification for an example
is available in <CODE>$/Type/Examples/Type.fw</CODE>.
<P>
This module is instantiated by
<PRE>
   $/Type/Typing.gnrc +referto=|KEY| :inst
</PRE>
The <CODE>referto</CODE> parameter modifies the names
of <CODE>Key</CODE> attributes, and hence, has to be the same as the
<CODE>referto</CODE> parameter used for the module instance that supplies
the key attributes.
<P>
The module uses the following basic concepts for implementation
of type analysis tasks:
<A NAME="IDX8"></A>
<A NAME="IDX9"></A>
<A NAME="IDX10"></A>
<P>
Types are represented by <CODE>DefTableKeys</CODE>.
Such a key is created for each program construct which
denotes a particular type.
The roles of this module associate the property <CODE>IsType</CODE>
(set to 1) to such type keys in order to distinguish them
from keys for other objects.
Further properties may be associated to characterize the particular type.
<CODE>NoKey</CODE> represents the unknown Type.
<A NAME="IDX11"></A>
<A NAME="IDX12"></A>
<P>
The property <CODE>TypeOf</CODE> is associated to typed objects
and states the type of the object.
<P>
Identifiers may be defined to denote types. They may be
introduced by type definitions.
In case of a type definition which simply renames the type given
by a type identifier, it is assumed that both type identifiers
refer to the same type.
<A NAME="IDX13"></A>
<A NAME="IDX14"></A>
<A NAME="IDX15"></A>
<A NAME="IDX16"></A>
<A NAME="IDX17"></A>
<P>
This module uses an instance of the <CODE>Defer</CODE> module
(see  <A HREF="type_4.html#SEC9">Deferred Property Association</A>) to relate keys that represent the same type.
A type identifier key refers indirectly via the <CODE>Defer</CODE> relation
to a type key, where the type properties are associated to.
Let <CODE>k</CODE> be a type identifier; then a call <CODE>TransDefer (k)</CODE>
accesses the type key at the end of the <CODE>Defer</CODE> chain via
arbitrary many steps.
<P>
This module provides the following computational roles:
<A NAME="IDX18"></A>
<P>
<CODE>RootType</CODE>:
is inherited by the grammar root by default.
<A NAME="IDX19"></A>
<P>
<CODE>TypedDefinition</CODE>:
a definition that defines one or several typed objects.
<A NAME="IDX20"></A>
<P>
<CODE>TypedDefId</CODE>:
a defining occurrence of an identifier for a typed object.
<A NAME="IDX21"></A>
<P>
<CODE>TypedUseId</CODE>:
an applied occurrence of an identifier for a typed object.
<A NAME="IDX22"></A>
<P>
<CODE>ChkTypedUseId</CODE>:
checks that the key represents a typed object.
<A NAME="IDX23"></A>
<P>
<CODE>TypeDefDefId</CODE>:
a defining occurrence of a type identifer.
<A NAME="IDX24"></A>
<P>
<CODE>ChkTypeDefDefId</CODE>:
checks that a type identifer is defined acyclic.
<A NAME="IDX25"></A>
<P>
<CODE>TypeDefUseId</CODE>:
an applied occurrence of a type identifer.
<A NAME="IDX26"></A>
<P>
<CODE>ChkTypeDefUseId</CODE>:
checks that the key represents a type.
<A NAME="IDX27"></A>
<P>
<CODE>TypeDenotation</CODE>:
a type denotation.
<P>
At least the roles <CODE>TypedDefinition</CODE>,
<CODE>TypedDefId</CODE>, <CODE>TypedUseId</CODE>,
and <CODE>TypeDefUseId</CODE>
are used. Those are sufficient for languages that have only
predefined types. User defined types require additionally the use of
<CODE>TypeDenotation</CODE>.
For definitions of names that denote types
<CODE>TypeDefDefId</CODE> and <CODE>ChkTypeDefDefId</CODE> are necessary.
<P>
The roles are described as follows:
<A NAME="IDX28"></A>
<A NAME="IDX29"></A>
<P>
<CODE>TypedDefinition</CODE>
is a context where one or several typed objects are defined
in its subtree, using the role <CODE>TypedDefId</CODE>.
They all have the same type which is to be computed as
the attribute <CODE>THIS.Type</CODE>.
<A NAME="IDX30"></A>
<A NAME="IDX31"></A>
<P>
<CODE>TypedDefId</CODE>
is a defining occurrence of an identifier for a typed object.
The <CODE>TypeOf</CODE> property is associated to <CODE>THIS.KEYKey</CODE>.
It is obtained from the attribute <CODE>INH.Type</CODE>.
A default computation for <CODE>INH.Type</CODE> is provided
that takes the type from <CODE>INCLUDING TypedDefinition.Type</CODE>.
Further properties may be associated to the object along
with its type. Then the postcondition of their computation should
be <CODE>INH.GotProp</CODE> which is empty by default. It guarantees that
the property values can be accessed where the typed object is used.
<P>
An attribute <CODE>SYNT.TypeIsSet</CODE> represents the state
where the <CODE>TypeOf</CODE> property of this <CODE>TypedDefId</CODE> has been
set. The default computations of <CODE>TypedDefId</CODE> and <CODE>TypedUseId</CODE>
are set up such that the <CODE>TypeOf</CODE> properties of all
<CODE>TypedDefId</CODE> are set before any <CODE>TypeOf</CODE> property of
a <CODE>TypedUseId</CODE> is accessed. In cases where a different dependency
pattern is needed, it can be obtained by overriding the
computations of <CODE>SYNT.TypeIsSet</CODE> in the two contexts.
An example for a different dependency pattern is a left-to-right
chain which may allow to set the type in a defining occurrence using
applied occurrences that have been set before.
<A NAME="IDX33"></A>
<A NAME="IDX32"></A>
<P>
<CODE>TypedUseId</CODE>
is an applied occurrence of an identifier for a typed object.
The attribute <CODE>SYNT.Type</CODE> is the type associated to the object.
The <CODE>Defer</CODE> chain is already walked down to the type key.
See the explanation of the attribute <CODE>SYNT.TypeIsSet</CODE> 
for the role <CODE>TypedDefId</CODE>.
<P>
<CODE>ChkTypedUseId</CODE>
checks that the key represents a typed object, and issues an error
message otherwise.
<P>
Types are denoted either by a used occurrence of a type identifier,
role <CODE>TypeDefUseId</CODE>, or by some composite <CODE>TypeDenotation</CODE>.
Either role provides a <CODE>Type</CODE> attribute representing the denoted
type.
<P>
<CODE>TypeDefUseId</CODE>
is an applied occurrence of a type identifier.
The <CODE>Type</CODE> attribute is its key which is related to the
type key by the <CODE>Defer</CODE> relation.
<P>
<CODE>ChkTypeDefUseId</CODE>
is usually inherited along with <CODE>TypeDefUseId</CODE>.
It issues an error message if the identifier does not
denote a type.
<P>
<CODE>TypeDenotation</CODE>
characterizes a context that denotes a user defined type,
e.g. an array type.
The attribute <CODE>SYNT.Type</CODE> is a new, unique type key.
If the type rules of the language state that a thus denoted
type is equivalent to any other type, suitable functions
that check for type equivalence have to be used.
<A NAME="IDX34"></A>
<A NAME="IDX35"></A>
<P>
Any property that further describes the type has
to be associated to <CODE>SYNT.Type</CODE> by computations that
establish the postcondition <CODE>SYNT.GotType</CODE>.
(Its default is the empty postcondition.)
It guarantees that the properties
can be accessed when an object having that type is used
(role <CODE>TypedUseId</CODE>).
<P>
<CODE>TypeDefDefId</CODE>
is a defining occurrences of a type identifier.
Its key is related by the <CODE>Defer</CODE> relation to the
attribute <CODE>THIS.Type</CODE>. Its computation has to be provided.
<P>
<CODE>ChkTypeDefDefId</CODE>
checks that its attribute <CODE>THIS.Type</CODE> refers to a type,
and that the type does not refer to itself.
It is usually inherited along with <CODE>TypeDefDefId</CODE>.
<P>
<CODE>RootType</CODE>
is inherited by the grammar root by default.
It ensures that all <CODE>TypeOf</CODE> and <CODE>Defer</CODE> properties
are established when a <CODE>Type</CODE> attribute
is computed. (The same holds for properties that are defined
along with types.)
That condition is provided by the
condition attribute <CODE>SYNT.GotType</CODE>.
Computations that access type properties, e.g.
those which decompose composite types,
have to be specified to depend on <CODE>INCLUDING RootType.GotType</CODE>.
<A NAME="IDX36"></A>
<A NAME="IDX37"></A>
<A NAME="IDX38"></A>
<P>
<H2><A NAME="SEC2" HREF="type_toc.html#SEC2">Example for Basic Type Analysis</A></H2>
<P>
The use of the basic type module is demonstrated by introducing type analysis
to our running example.
A complete executable specification of our running example for the type
analysis task
is available in <CODE>$/Type/Examples/Type.fw</CODE>.
<P>
For the moment we assume the there are only three predefined
types <CODE>int</CODE>, <CODE>float</CODE>, and <CODE>bool</CODE>. They are represented
by the keys <CODE>intType</CODE>, <CODE>realType</CODE>, and <CODE>boolType</CODE>
as introduced in (see  <A HREF="name_3.html#SEC6">Predefined Identifiers of Name analysis according to scope rules</A>).
<A NAME="IDX39"></A>
<P>
We add a <CODE>.pdl</CODE> specification which states that those keys are types
and which defines the types of the constants <CODE>true</CODE> and <CODE>false</CODE>.
A <CODE>voidType</CODE> is introduced here although there is no predefined
identifier to denote it. It enables us to express that in certain
contexts type coercion to <CODE>voidType</CODE> is to be applied.
<PRE>
  intType -&#62; IsType = {1};
  realType -&#62; IsType = {1};
  boolType -&#62; IsType = {1};
  voidType -&#62; IsType = {1};

  trueKey -&#62; TypeOf = {boolType};
  falseKey-&#62; TypeOf = {boolType};

  intKey -&#62; Defer = {intType};
  realKey -&#62; Defer = {realType};
  boolKey -&#62; Defer = {boolType};
</PRE>
The last group relates the keys of the predefined type identifiers
to the type keys.
It is not recommended to use <CODE>intKey</CODE> etc. themselves
as type keys. In that case it would not be possible to have
different predefined type identifiers that could denote the same types.
<A NAME="IDX40"></A>
<A NAME="IDX41"></A>
<A NAME="IDX42"></A>
<A NAME="IDX43"></A>
<A NAME="IDX44"></A>
<A NAME="IDX45"></A>
<A NAME="IDX46"></A>
<P>
The following association of module roles to grammar symbols 
in our <CODE>.lido</CODE> specification is obvious:
<PRE>
  SYMBOL DefIdent INHERITS TypedDefId END;
  SYMBOL UseIdent INHERITS TypedUseId, ChkTypedUseId END;
  SYMBOL TypeUseIdent INHERITS TypeDefUseId, ChkTypeDefUseId END;
</PRE>
<P>
Our language construct <CODE>ObjDecl</CODE> defines typed objects.
It specifies that the <CODE>Type</CODE> attribute is taken
from the <CODE>TypeDenoter</CODE>. Until now, a <CODE>TypeDenoter</CODE>
can have only one form: <CODE>TypeUseIdent</CODE>.
Its key is taken to represent the denoted type:
<PRE>
  SYMBOL ObjDecl INHERITS TypedDefinition END;
  RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE
    ObjDecl.Type = TypeDenoter.Type;
  END;

  RULE: TypeDenoter ::= TypeUseIdent COMPUTE
    TypeDenoter.Type = TypeUseIdent.Type;
  END;

  ATTR Type: DefTableKey;  
</PRE>
The last line allows us to use <CODE>Type</CODE> attributes without
specifying their type repeatedly.
<P>
The types of literal expressions are then specified by
<PRE>
   RULE: Expression ::= IntNumber COMPUTE
     Expression.Type = intType;
   END;

   RULE: Expression ::= RealNumber COMPUTE
     Expression.Type = realType;
   END;
</PRE>
<P>
Computations like the following propagate type information
upwards through adjacent contexts:
<PRE>
  RULE: Expression ::= Variable COMPUTE
    Expression.Type = Variable.Type;
  END;

  RULE: Variable ::= UseIdent COMPUTE
    Variable.Type = UseIdent.Type;
  END;
</PRE>
<P>
Occurrences of <CODE>Expression</CODE> in certain contexts require
that their type is compatible to a type imposed by the context.
Hence, we introduce an inherited attribute <CODE>ReqType</CODE> and a check
for compatibility.
The two rules demonstrate how such type requirements are imposed:
<PRE>
  SYMBOL Expression: ReqType: DefTableKey;
  SYMBOL Expression COMPUTE
    IF (NOT (Compatible (THIS.ReqType, THIS.Type)),
    message (FATAL, "expression does not have the required type",
             0, COORDREF));
  END;

  RULE: Statement ::=  Expression ';' COMPUTE
    Expression.ReqType = voidKey;
  END;

  RULE: Statement ::= Variable '=' Expression ';' COMPUTE
    Expression.ReqType = Variable.Type;
  END;
</PRE>
<P>
The function <CODE>Compatible</CODE> needs to be
implemented according to the type rules of the particular language.
(An example implementation is shown in <CODE>$/Type/Examples/Type.fw</CODE>).
<A NAME="IDX47"></A>
<A NAME="IDX48"></A>
<A NAME="IDX49"></A>
<P>
We now introduce type definitions to our language.
The concrete production is
<PRE>
   Declaration:    'type' TypeDenoter TypeDefIdent ';'.
   TypeDefIdent:   Ident.
</PRE>
From the view of language design such type definitions only make sense
if there are other than the predefined types that can be given a name.
In (see  <A HREF="type_2.html#SEC3">Properties of Types</A>) it is demonstrated how to introduce
some common types.
<P>
The <CODE>TypeDefIdent</CODE> has the role of a defining type identifier
occurrence that renames the type of the <CODE>TypeDenoter</CODE>:
<PRE>
   SYMBOL TypeDefIdent INHERITS
          IdDefScope, IdentOcc,
          TypeDefDefId, ChkTypeDefDefId
   END;

   RULE: Declaration ::= 'type' TypeDenoter TypeDefIdent ';' COMPUTE
     TypeDefIdent.Type = TypeDenoter.Type;
   END;
</PRE>
<A NAME="IDX50"></A>
<P>
<HR size=1 noshade width=600 align=left>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_2.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
</TD>
</TR>
</TABLE>

</BODY></HTML>