aboutsummaryrefslogtreecommitdiffstats
path: root/erts/doc/src/absform.xml
blob: 8584898a9d2cab8747f47a81de041113455434d9 (plain) (blame)
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2001</year><year>2015</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>The Abstract Format</title>
    <prepared>Arndt Jonasson</prepared>
    <responsible>Kenneth Lundin</responsible>
    <docno>1</docno>
    <approved>Jultomten</approved>
    <checked></checked>
    <date>00-12-01</date>
    <rev>A</rev>
    <file>absform.xml</file>
  </header>
  <p></p>
  <p>This document describes the standard representation of parse trees for Erlang
    programs as Erlang terms. This representation is known as the <em>abstract format</em>.
    Functions dealing with such parse trees are <c><![CDATA[compile:forms/[1,2]]]></c>
    and functions in the modules
    <c><![CDATA[epp]]></c>,
    <c><![CDATA[erl_eval]]></c>,
    <c><![CDATA[erl_lint]]></c>,
    <c><![CDATA[erl_pp]]></c>,
    <c><![CDATA[erl_parse]]></c>,
    and
    <c><![CDATA[io]]></c>.
    They are also used as input and output for parse transforms (see the module
    <c><![CDATA[compile]]></c>).</p>
  <p>We use the function <c><![CDATA[Rep]]></c> to denote the mapping from an Erlang source
    construct <c><![CDATA[C]]></c> to its abstract format representation <c><![CDATA[R]]></c>, and write
    <c><![CDATA[R = Rep(C)]]></c>.
    </p>
  <p>The word <c><![CDATA[LINE]]></c> below represents an integer, and denotes the
    number of the line in the source file where the construction occurred.
    Several instances of <c><![CDATA[LINE]]></c> in the same construction may denote
    different lines.</p>
  <p>Since operators are not terms in their own right, when operators are
    mentioned below, the representation of an operator should be taken to
    be the atom with a printname consisting of the same characters as the
    operator.
    </p>

  <section>
    <title>Module Declarations and Forms</title>
    <p>A module declaration consists of a sequence of forms that are either
      function declarations or attributes.</p>
    <list type="bulleted">
      <item>If D is a module declaration consisting of the forms
      <c><![CDATA[F_1]]></c>, ..., <c><![CDATA[F_k]]></c>, then
       Rep(D) = <c><![CDATA[[Rep(F_1), ..., Rep(F_k)]]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-module(Mod)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,module,Mod}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-behavior(Behavior)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,behavior,Behavior}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-behaviour(Behaviour)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,behaviour,Behaviour}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-export([Fun_1/A_1, ..., Fun_k/A_k])]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,export,[{Fun_1,A_1}, ..., {Fun_k,A_k}]}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-import(Mod,[Fun_1/A_1, ..., Fun_k/A_k])]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,import,{Mod,[{Fun_1,A_1}, ..., {Fun_k,A_k}]}}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-export_type([Type_1/A_1, ..., Type_k/A_k])]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,export_type,[{Type_1,A_1}, ..., {Type_k,A_k}]}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-compile(Options)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,compile,Options}]]></c>.</item>
      <item>If F is an attribute <c><![CDATA[-file(File,Line)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,file,{File,Line}}]]></c>.</item>
      <item>If F is a record declaration
       <c>-record(Name,{V_1, ..., V_k})</c>, then Rep(F) =
       <c>{attribute,LINE,record,{Name,[Rep(V_1), ..., Rep(V_k)]}}</c>.
       For Rep(V), see below.</item>
      <item>If F is a type declaration
       <c>-Type Name(V_1, ..., V_k) :: T</c>, where
       <c>Type</c> is either the atom <c>type</c> or the atom <c>opaque</c>,
       each <c>V_i</c> is a variable, and <c>T</c> is a type, then Rep(F) =
       <c>{attribute,LINE,Type,{Name,Rep(T),[Rep(V_1), ..., Rep(V_k)]}}</c>.
      </item>
      <item>If F is a function specification
       <c>-Spec Name Ft_1; ...; Ft_k</c>,
       where <c>Spec</c> is either the atom <c>spec</c> or the atom
       <c>callback</c>, and each <c>Ft_i</c> is a possibly constrained
       function type with an argument sequence of the same length
       <c>Arity</c>, then Rep(F) =
       <c>{attribute,Line,Spec,{{Name,Arity},[Rep(Ft_1), ..., Rep(Ft_k)]}}</c>.
      </item>
      <item>If F is a function specification
       <c>-spec Mod:Name Ft_1; ...; Ft_k</c>,
       where each <c>Ft_i</c> is a possibly constrained
       function type with an argument sequence of the same length
       <c>Arity</c>, then Rep(F) =
       <c>{attribute,Line,spec,{{Mod,Name,Arity},[Rep(Ft_1), ..., Rep(Ft_k)]}}</c>.
      </item>
      <item>If F is a wild attribute <c><![CDATA[-A(T)]]></c>, then
       Rep(F) = <c><![CDATA[{attribute,LINE,A,T}]]></c>.
      <br></br></item>
      <item>If F is a function declaration
       <c>Name Fc_1 ; ... ; Name Fc_k</c>,
       where each <c>Fc_i</c> is a function clause with a
       pattern sequence of the same length <c>Arity</c>, then
       Rep(F) = <c>{function,LINE,Name,Arity,[Rep(Fc_1), ...,Rep(Fc_k)]}</c>.
      </item>
    </list>

    <section>
      <title>Record Fields</title>
      <p>Each field in a record declaration may have an optional
        explicit default initializer expression, as well as an
        optional type.</p>
      <list type="bulleted">
        <item>If V is <c><![CDATA[A]]></c>, then
         Rep(V) = <c><![CDATA[{record_field,LINE,Rep(A)}]]></c>.</item>
        <item>If V is <c><![CDATA[A = E]]></c>,
	 where <c>E</c> is an expression, then
         Rep(V) = <c><![CDATA[{record_field,LINE,Rep(A),Rep(E)}]]></c>.</item>
        <item>If V is <c>A :: T</c>, where <c>T</c> is a
          type and it does not contain
          <c>undefined</c> syntactically, then Rep(V) =
          <c>{typed_record_field,{record_field,LINE,Rep(A)},Rep(undefined | T)}</c>.
        </item>
        <item>If V is <c>A :: T</c>, where <c>T</c> is a type, then Rep(V) =
          <c>{typed_record_field,{record_field,LINE,Rep(A)},Rep(T)}</c>.
          </item>
        <item>If V is <c>A = E :: T</c>, where
          <c>E</c> is an expression and <c>T</c> is a type, then Rep(V) =
          <c>{typed_record_field,{record_field,LINE,Rep(A),Rep(E)},Rep(T)}</c>.
        </item>
      </list>
    </section>

    <section>
      <title>Representation of Parse Errors and End-of-file</title>
      <p>In addition to the representations of forms, the list that represents
        a module declaration (as returned by functions in <c>erl_parse</c> and
        <c>epp</c>) may contain tuples <c>{error,E}</c> and
	<c>{warning,W}</c>, denoting syntactically incorrect forms and
	warnings, and <c>{eof,LINE}</c>, denoting an end-of-stream
	encountered before a complete form had been parsed.</p>
    </section>
  </section>

  <section>
    <title>Atomic Literals</title>
    <p>There are five kinds of atomic literals, which are represented in the
      same way in patterns, expressions and guards:</p>
    <list type="bulleted">
      <item>If L is an integer or character literal, then
       Rep(L) = <c><![CDATA[{integer,LINE,L}]]></c>.</item>
      <item>If L is a float literal, then
       Rep(L) = <c><![CDATA[{float,LINE,L}]]></c>.</item>
      <item>If L is a string literal consisting of the characters
      <c><![CDATA[C_1]]></c>, ..., <c><![CDATA[C_k]]></c>, then
       Rep(L) = <c><![CDATA[{string,LINE,[C_1, ..., C_k]}]]></c>.</item>
      <item>If L is an atom literal, then
       Rep(L) = <c><![CDATA[{atom,LINE,L}]]></c>.</item>
    </list>
    <p>Note that negative integer and float literals do not occur as such; they are
      parsed as an application of the unary negation operator.</p>
  </section>

  <section>
    <title>Patterns</title>
    <p>If <c><![CDATA[Ps]]></c> is a sequence of patterns <c><![CDATA[P_1, ..., P_k]]></c>, then
      Rep(Ps) = <c><![CDATA[[Rep(P_1), ..., Rep(P_k)]]]></c>. Such sequences occur as the
      list of arguments to a function or fun.</p>
    <p>Individual patterns are represented as follows:</p>
    <list type="bulleted">
      <item>If P is an atomic literal L, then Rep(P) = Rep(L).</item>
      <item>If P is a compound pattern <c><![CDATA[P_1 = P_2]]></c>, then
       Rep(P) = <c><![CDATA[{match,LINE,Rep(P_1),Rep(P_2)}]]></c>.</item>
      <item>If P is a variable pattern <c><![CDATA[V]]></c>, then
       Rep(P) = <c><![CDATA[{var,LINE,A}]]></c>,
       where A is an atom with a printname consisting of the same characters as
      <c><![CDATA[V]]></c>.</item>
      <item>If P is a universal pattern <c><![CDATA[_]]></c>, then
       Rep(P) = <c><![CDATA[{var,LINE,'_'}]]></c>.</item>
      <item>If P is a tuple pattern <c><![CDATA[{P_1, ..., P_k}]]></c>, then
       Rep(P) = <c><![CDATA[{tuple,LINE,[Rep(P_1), ..., Rep(P_k)]}]]></c>.</item>
      <item>If P is a nil pattern <c><![CDATA[[]]]></c>, then
       Rep(P) = <c><![CDATA[{nil,LINE}]]></c>.</item>
      <item>If P is a cons pattern <c><![CDATA[[P_h | P_t]]]></c>, then
       Rep(P) = <c><![CDATA[{cons,LINE,Rep(P_h),Rep(P_t)}]]></c>.</item>
      <item>If E is a binary pattern <c><![CDATA[<<P_1:Size_1/TSL_1, ..., P_k:Size_k/TSL_k>>]]></c>, then
       Rep(E) = <c><![CDATA[{bin,LINE,[{bin_element,LINE,Rep(P_1),Rep(Size_1),Rep(TSL_1)}, ..., {bin_element,LINE,Rep(P_k),Rep(Size_k),Rep(TSL_k)}]}]]></c>.
       For Rep(TSL), see below.
       An omitted <c><![CDATA[Size]]></c> is represented by <c><![CDATA[default]]></c>. An omitted <c><![CDATA[TSL]]></c>
       (type specifier list) is represented by <c><![CDATA[default]]></c>.</item>
      <item>If P is <c><![CDATA[P_1 Op P_2]]></c>, where <c><![CDATA[Op]]></c> is a binary operator (this
       is either an occurrence of <c><![CDATA[++]]></c> applied to a literal string or character
       list, or an occurrence of an expression that can be evaluated to a number
       at compile time),
       then Rep(P) = <c><![CDATA[{op,LINE,Op,Rep(P_1),Rep(P_2)}]]></c>.</item>
      <item>If P is <c><![CDATA[Op P_0]]></c>, where <c><![CDATA[Op]]></c> is a unary operator (this is an
       occurrence of an expression that can be evaluated to a number at compile
       time), then Rep(P) = <c><![CDATA[{op,LINE,Op,Rep(P_0)}]]></c>.</item>
      <item>If P is a record pattern <c><![CDATA[#Name{Field_1=P_1, ..., Field_k=P_k}]]></c>,
       then Rep(P) =
      <c><![CDATA[{record,LINE,Name,[{record_field,LINE,Rep(Field_1),Rep(P_1)}, ..., {record_field,LINE,Rep(Field_k),Rep(P_k)}]}]]></c>.</item>
      <item>If P is <c><![CDATA[#Name.Field]]></c>, then
       Rep(P) = <c><![CDATA[{record_index,LINE,Name,Rep(Field)}]]></c>.</item>
      <item>If P is <c><![CDATA[( P_0 )]]></c>, then
       Rep(P) = <c><![CDATA[Rep(P_0)]]></c>,
       that is, patterns cannot be distinguished from their bodies.</item>
    </list>
    <p>Note that every pattern has the same source form as some expression, and is
      represented the same way as the corresponding expression.</p>
  </section>

  <section>
    <title>Expressions</title>
    <p>A body B is a sequence of expressions <c><![CDATA[E_1, ..., E_k]]></c>, and
      Rep(B) = <c><![CDATA[[Rep(E_1), ..., Rep(E_k)]]]></c>.</p>
    <p>An expression E is one of the following alternatives:</p>
    <list type="bulleted">
      <item>If P is an atomic literal <c><![CDATA[L]]></c>, then
       Rep(P) = Rep(L).</item>
      <item>If E is <c><![CDATA[P = E_0]]></c>, then
       Rep(E) = <c><![CDATA[{match,LINE,Rep(P),Rep(E_0)}]]></c>.</item>
      <item>If E is a variable <c><![CDATA[V]]></c>, then
       Rep(E) = <c><![CDATA[{var,LINE,A}]]></c>,
       where <c><![CDATA[A]]></c> is an atom with a printname consisting of the same
       characters as <c><![CDATA[V]]></c>.</item>
      <item>If E is a tuple skeleton <c><![CDATA[{E_1, ..., E_k}]]></c>, then
       Rep(E) = <c><![CDATA[{tuple,LINE,[Rep(E_1), ..., Rep(E_k)]}]]></c>.</item>
      <item>If E is <c><![CDATA[[]]]></c>, then
       Rep(E) = <c><![CDATA[{nil,LINE}]]></c>.</item>
      <item>If E is a cons skeleton <c><![CDATA[[E_h | E_t]]]></c>, then
       Rep(E) = <c><![CDATA[{cons,LINE,Rep(E_h),Rep(E_t)}]]></c>.</item>
      <item>If E is a binary constructor <c><![CDATA[<<V_1:Size_1/TSL_1, ..., V_k:Size_k/TSL_k>>]]></c>, then
       Rep(E) = <c><![CDATA[{bin,LINE,[{bin_element,LINE,Rep(V_1),Rep(Size_1),Rep(TSL_1)}, ..., {bin_element,LINE,Rep(V_k),Rep(Size_k),Rep(TSL_k)}]}]]></c>.
       For Rep(TSL), see below.
       An omitted <c><![CDATA[Size]]></c> is represented by <c><![CDATA[default]]></c>. An omitted <c><![CDATA[TSL]]></c>
       (type specifier list) is represented by <c><![CDATA[default]]></c>.</item>
      <item>If E is <c><![CDATA[E_1 Op E_2]]></c>, where <c><![CDATA[Op]]></c> is a binary operator,
       then Rep(E) = <c><![CDATA[{op,LINE,Op,Rep(E_1),Rep(E_2)}]]></c>.</item>
      <item>If E is <c><![CDATA[Op E_0]]></c>, where <c><![CDATA[Op]]></c> is a unary operator, then
       Rep(E) = <c><![CDATA[{op,LINE,Op,Rep(E_0)}]]></c>.</item>
      <item>If E is <c><![CDATA[#Name{Field_1=E_1, ..., Field_k=E_k}]]></c>, then
       Rep(E) =
      <c><![CDATA[{record,LINE,Name,[{record_field,LINE,Rep(Field_1),Rep(E_1)}, ..., {record_field,LINE,Rep(Field_k),Rep(E_k)}]}]]></c>.</item>
      <item>If E is <c><![CDATA[E_0#Name{Field_1=E_1, ..., Field_k=E_k}]]></c>, then
       Rep(E) =
      <c><![CDATA[{record,LINE,Rep(E_0),Name,[{record_field,LINE,Rep(Field_1),Rep(E_1)}, ..., {record_field,LINE,Rep(Field_k),Rep(E_k)}]}]]></c>.</item>
      <item>If E is <c><![CDATA[#Name.Field]]></c>, then
       Rep(E) = <c><![CDATA[{record_index,LINE,Name,Rep(Field)}]]></c>.</item>
      <item>If E is <c><![CDATA[E_0#Name.Field]]></c>, then
       Rep(E) = <c><![CDATA[{record_field,LINE,Rep(E_0),Name,Rep(Field)}]]></c>.</item>
      <item>If E is <c><![CDATA[#{W_1, ..., W_k}]]></c> where each
       <c><![CDATA[W_i]]></c> is a map assoc or exact field, then Rep(E) =
       <c><![CDATA[{map,LINE,[Rep(W_1), ..., Rep(W_k)]}]]></c>. For Rep(W), see
       below.</item>
      <item>If E is <c><![CDATA[E_0#{W_1, ..., W_k}]]></c> where
       <c><![CDATA[W_i]]></c> is a map assoc or exact field, then Rep(E) =
       <c><![CDATA[{map,LINE,Rep(E_0),[Rep(W_1), ..., Rep(W_k)]}]]></c>. For
       Rep(W), see below.</item>
      <item>If E is <c><![CDATA[catch E_0]]></c>, then
       Rep(E) = <c><![CDATA[{'catch',LINE,Rep(E_0)}]]></c>.</item>
      <item>If E is <c><![CDATA[E_0(E_1, ..., E_k)]]></c>, then
       Rep(E) = <c><![CDATA[{call,LINE,Rep(E_0),[Rep(E_1), ..., Rep(E_k)]}]]></c>.</item>
      <item>If E is <c><![CDATA[E_m:E_0(E_1, ..., E_k)]]></c>, then
       Rep(E) =
      <c><![CDATA[{call,LINE,{remote,LINE,Rep(E_m),Rep(E_0)},[Rep(E_1), ...,  Rep(E_k)]}]]></c>.</item>
      <item>If E is a list comprehension <c><![CDATA[[E_0 || W_1, ..., W_k]]]></c>,
       where each <c><![CDATA[W_i]]></c> is a generator or a filter, then
       Rep(E) = <c><![CDATA[{lc,LINE,Rep(E_0),[Rep(W_1), ..., Rep(W_k)]}]]></c>. For Rep(W), see
       below.</item>
      <item>If E is a binary comprehension <c><![CDATA[<<E_0 || W_1, ..., W_k>>]]></c>,
       where each <c><![CDATA[W_i]]></c> is a generator or a filter, then
       Rep(E) = <c><![CDATA[{bc,LINE,Rep(E_0),[Rep(W_1), ..., Rep(W_k)]}]]></c>. For Rep(W), see
       below.</item>
      <item>If E is <c><![CDATA[begin B end]]></c>, where <c><![CDATA[B]]></c> is a body, then
       Rep(E) = <c><![CDATA[{block,LINE,Rep(B)}]]></c>.</item>
      <item>If E is <c><![CDATA[if Ic_1 ; ... ; Ic_k  end]]></c>,
       where each <c><![CDATA[Ic_i]]></c> is an if clause then
       Rep(E) =
      <c><![CDATA[{'if',LINE,[Rep(Ic_1), ..., Rep(Ic_k)]}]]></c>.</item>
      <item>If E is <c><![CDATA[case E_0 of Cc_1 ; ... ; Cc_k end]]></c>,
       where <c><![CDATA[E_0]]></c> is an expression and each <c><![CDATA[Cc_i]]></c> is a
       case clause then
       Rep(E) =
      <c><![CDATA[{'case',LINE,Rep(E_0),[Rep(Cc_1), ..., Rep(Cc_k)]}]]></c>.</item>
      <item>If E is <c><![CDATA[try B catch Tc_1 ; ... ; Tc_k end]]></c>,
       where <c><![CDATA[B]]></c> is a body and each <c><![CDATA[Tc_i]]></c> is a catch clause then 
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[],[Rep(Tc_1), ..., Rep(Tc_k)],[]}]]></c>.</item>
      <item>If E is <c><![CDATA[try B of Cc_1 ; ... ; Cc_k catch Tc_1 ; ... ; Tc_n end]]></c>,
       where <c><![CDATA[B]]></c> is a body, 
       each <c><![CDATA[Cc_i]]></c> is a case clause and 
       each <c><![CDATA[Tc_j]]></c> is a catch clause then 
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[Rep(Cc_1), ..., Rep(Cc_k)],[Rep(Tc_1), ..., Rep(Tc_n)],[]}]]></c>.</item>
      <item>If E is <c><![CDATA[try B after A end]]></c>,
       where <c><![CDATA[B]]></c> and <c><![CDATA[A]]></c> are bodies then
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[],[],Rep(A)}]]></c>.</item>
      <item>If E is <c><![CDATA[try B of Cc_1 ; ... ; Cc_k after A end]]></c>,
       where <c><![CDATA[B]]></c> and <c><![CDATA[A]]></c> are a bodies and
       each <c><![CDATA[Cc_i]]></c> is a case clause then 
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[Rep(Cc_1), ..., Rep(Cc_k)],[],Rep(A)}]]></c>.</item>
      <item>If E is <c><![CDATA[try B catch Tc_1 ; ... ; Tc_k after A end]]></c>,
       where <c><![CDATA[B]]></c> and <c><![CDATA[A]]></c> are bodies and
       each <c><![CDATA[Tc_i]]></c> is a catch clause then 
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[],[Rep(Tc_1), ..., Rep(Tc_k)],Rep(A)}]]></c>.</item>
      <item>If E is <c><![CDATA[try B of Cc_1 ; ... ; Cc_k  catch Tc_1 ; ... ; Tc_n after A end]]></c>,
       where <c><![CDATA[B]]></c> and <c><![CDATA[A]]></c> are a bodies, 
       each <c><![CDATA[Cc_i]]></c> is a case clause and
       each <c><![CDATA[Tc_j]]></c> is a catch clause then 
       Rep(E) =
      <c><![CDATA[{'try',LINE,Rep(B),[Rep(Cc_1), ..., Rep(Cc_k)],[Rep(Tc_1),  ..., Rep(Tc_n)],Rep(A)}]]></c>.</item>
      <item>If E is <c><![CDATA[receive Cc_1 ; ... ; Cc_k end]]></c>,
       where each <c><![CDATA[Cc_i]]></c> is a case clause then
       Rep(E) =
      <c><![CDATA[{'receive',LINE,[Rep(Cc_1), ..., Rep(Cc_k)]}]]></c>.</item>
      <item>If E is <c><![CDATA[receive Cc_1 ; ... ; Cc_k after E_0 -> B_t end]]></c>,
       where each <c><![CDATA[Cc_i]]></c> is a case clause, 
      <c><![CDATA[E_0]]></c> is an expression and <c><![CDATA[B_t]]></c> is a body, then
       Rep(E) =
      <c><![CDATA[{'receive',LINE,[Rep(Cc_1), ..., Rep(Cc_k)],Rep(E_0),Rep(B_t)}]]></c>.</item>
      <item>If E is <c><![CDATA[fun Name / Arity]]></c>, then
       Rep(E) = <c><![CDATA[{'fun',LINE,{function,Name,Arity}}]]></c>.</item>
      <item>If E is <c><![CDATA[fun Module:Name/Arity]]></c>, then
       Rep(E) = <c><![CDATA[{'fun',LINE,{function,Rep(Module),Rep(Name),Rep(Arity)}}]]></c>.
      (Before the R15 release: Rep(E) = <c><![CDATA[{'fun',LINE,{function,Module,Name,Arity}}]]></c>.)</item>
      <item>If E is <c><![CDATA[fun Fc_1 ; ... ; Fc_k end]]></c> 
       where each <c><![CDATA[Fc_i]]></c> is a function clause then Rep(E) =
      <c><![CDATA[{'fun',LINE,{clauses,[Rep(Fc_1), ..., Rep(Fc_k)]}}]]></c>.</item>
      <item>If E is <c><![CDATA[fun Name Fc_1 ; ... ; Name Fc_k end]]></c>
       where <c><![CDATA[Name]]></c> is a variable and each
       <c><![CDATA[Fc_i]]></c> is a function clause then Rep(E) =
       <c><![CDATA[{named_fun,LINE,Name,[Rep(Fc_1), ..., Rep(Fc_k)]}]]></c>.
       </item>
      <item>If E is <c><![CDATA[( E_0 )]]></c>, then
       Rep(E) = <c>Rep(E_0)</c>, that is, parenthesized
       expressions cannot be distinguished from their bodies.</item>
    </list>

    <section>
      <title>Generators and Filters</title>
      <p>When W is a generator or a filter (in the body of a list or binary comprehension), then:</p>
      <list type="bulleted">
        <item>If W is a generator <c><![CDATA[P <- E]]></c>, where <c><![CDATA[P]]></c> is a pattern and <c><![CDATA[E]]></c>
         is an expression, then
         Rep(W) = <c><![CDATA[{generate,LINE,Rep(P),Rep(E)}]]></c>.</item>
        <item>If W is a generator <c><![CDATA[P <= E]]></c>, where <c><![CDATA[P]]></c> is a pattern and <c><![CDATA[E]]></c>
         is an expression, then
         Rep(W) = <c><![CDATA[{b_generate,LINE,Rep(P),Rep(E)}]]></c>.</item>
        <item>If W is a filter <c><![CDATA[E]]></c>, which is an expression, then
         Rep(W) = <c><![CDATA[Rep(E)]]></c>.</item>
      </list>
    </section>

    <section>
      <title>Binary Element Type Specifiers</title>
      <p>A type specifier list TSL for a binary element is a sequence of type
        specifiers <c><![CDATA[TS_1 - ... - TS_k]]></c>.
        Rep(TSL) = <c><![CDATA[[Rep(TS_1), ..., Rep(TS_k)]]]></c>.</p>
      <p>When TS is a type specifier for a binary element, then:</p>
      <list type="bulleted">
        <item>If TS is an atom <c><![CDATA[A]]></c>, then Rep(TS) = <c><![CDATA[A]]></c>.</item>
        <item>If TS is a couple <c><![CDATA[A:Value]]></c> where <c><![CDATA[A]]></c> is an atom and <c><![CDATA[Value]]></c>
         is an integer, then Rep(TS) = <c>{A,Value}</c>.</item>
      </list>
    </section>

    <section>
      <title>Map Assoc and Exact Fields</title>
      <p>When W is an assoc or exact field (in the body of a map), then:</p>
      <list type="bulleted">
        <item>If W is an assoc field <c><![CDATA[K => V]]></c>, where
         <c><![CDATA[K]]></c> and <c><![CDATA[V]]></c> are both expressions,
         then Rep(W) = <c><![CDATA[{map_field_assoc,LINE,Rep(K),Rep(V)}]]></c>.
         </item>
        <item>If W is an exact field <c><![CDATA[K := V]]></c>, where
         <c><![CDATA[K]]></c> and <c><![CDATA[V]]></c> are both expressions,
         then Rep(W) = <c><![CDATA[{map_field_exact,LINE,Rep(K),Rep(V)}]]></c>.
         </item>
      </list>
    </section>
  </section>

  <section>
    <title>Clauses</title>
    <p>There are function clauses, if clauses, case clauses 
      and catch clauses.</p>
    <p>A clause <c><![CDATA[C]]></c> is one of the following alternatives:</p>
    <list type="bulleted">
      <item>If C is a function clause <c><![CDATA[( Ps ) -> B]]></c> 
       where <c><![CDATA[Ps]]></c> is a pattern sequence and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,Rep(Ps),[],Rep(B)}]]></c>.</item>
      <item>If C is a function clause <c><![CDATA[( Ps ) when Gs -> B]]></c> 
       where <c><![CDATA[Ps]]></c> is a pattern sequence, 
      <c><![CDATA[Gs]]></c> is a guard sequence and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,Rep(Ps),Rep(Gs),Rep(B)}]]></c>.</item>
      <item>If C is an if clause <c><![CDATA[Gs -> B]]></c> 
       where <c><![CDATA[Gs]]></c> is a guard sequence and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[],Rep(Gs),Rep(B)}]]></c>.</item>
      <item>If C is a case clause <c><![CDATA[P -> B]]></c> 
       where <c><![CDATA[P]]></c> is a pattern and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep(P)],[],Rep(B)}]]></c>.</item>
      <item>If C is a case clause <c><![CDATA[P when Gs -> B]]></c> 
       where <c><![CDATA[P]]></c> is a pattern, 
      <c><![CDATA[Gs]]></c> is a guard sequence and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep(P)],Rep(Gs),Rep(B)}]]></c>.</item>
      <item>If C is a catch clause <c><![CDATA[P -> B]]></c> 
       where <c><![CDATA[P]]></c> is a pattern and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep({throw,P,_})],[],Rep(B)}]]></c>.</item>
      <item>If C is a catch clause <c><![CDATA[X : P -> B]]></c> 
       where <c><![CDATA[X]]></c> is an atomic literal or a variable pattern, 
      <c><![CDATA[P]]></c> is a pattern and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep({X,P,_})],[],Rep(B)}]]></c>.</item>
      <item>If C is a catch clause <c><![CDATA[P when Gs -> B]]></c> 
       where <c><![CDATA[P]]></c> is a pattern, <c><![CDATA[Gs]]></c> is a guard sequence 
       and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep({throw,P,_})],Rep(Gs),Rep(B)}]]></c>.</item>
      <item>If C is a catch clause <c><![CDATA[X : P when Gs -> B]]></c> 
       where <c><![CDATA[X]]></c> is an atomic literal or a variable pattern, 
      <c><![CDATA[P]]></c> is a pattern, <c><![CDATA[Gs]]></c> is a guard sequence 
       and <c><![CDATA[B]]></c> is a body, then 
       Rep(C) = <c><![CDATA[{clause,LINE,[Rep({X,P,_})],Rep(Gs),Rep(B)}]]></c>.</item>
    </list>
  </section>

  <section>
    <title>Guards</title>
    <p>A guard sequence Gs is a sequence of guards <c><![CDATA[G_1; ...; G_k]]></c>, and
      Rep(Gs) = <c><![CDATA[[Rep(G_1), ..., Rep(G_k)]]]></c>. If the guard sequence is
      empty, Rep(Gs) = <c><![CDATA[[]]]></c>.</p>
    <p>A guard G is a nonempty sequence of guard tests <c><![CDATA[Gt_1, ..., Gt_k]]></c>, and
      Rep(G) = <c><![CDATA[[Rep(Gt_1), ..., Rep(Gt_k)]]]></c>.</p>
    <p>A guard test <c><![CDATA[Gt]]></c> is one of the following alternatives:</p>
    <list type="bulleted">
      <item>If Gt is an atomic literal L, then Rep(Gt) = Rep(L).</item>
      <item>If Gt is a variable pattern <c><![CDATA[V]]></c>, then
       Rep(Gt) = <c><![CDATA[{var,LINE,A}]]></c>,
       where A is an atom with a printname consisting of the same characters as
      <c><![CDATA[V]]></c>.</item>
      <item>If Gt is a tuple skeleton <c><![CDATA[{Gt_1, ..., Gt_k}]]></c>, then
       Rep(Gt) = <c><![CDATA[{tuple,LINE,[Rep(Gt_1), ..., Rep(Gt_k)]}]]></c>.</item>
      <item>If Gt is <c><![CDATA[[]]]></c>, then
       Rep(Gt) = <c><![CDATA[{nil,LINE}]]></c>.</item>
      <item>If Gt is a cons skeleton <c><![CDATA[[Gt_h | Gt_t]]]></c>, then
       Rep(Gt) = <c><![CDATA[{cons,LINE,Rep(Gt_h),Rep(Gt_t)}]]></c>.</item>
      <item>If Gt is a binary constructor <c><![CDATA[<<Gt_1:Size_1/TSL_1, ..., Gt_k:Size_k/TSL_k>>]]></c>, then
       Rep(Gt) = <c><![CDATA[{bin,LINE,[{bin_element,LINE,Rep(Gt_1),Rep(Size_1),Rep(TSL_1)}, ..., {bin_element,LINE,Rep(Gt_k),Rep(Size_k),Rep(TSL_k)}]}]]></c>.
       For Rep(TSL), see above.
       An omitted <c><![CDATA[Size]]></c> is represented by <c><![CDATA[default]]></c>. An omitted <c><![CDATA[TSL]]></c>
       (type specifier list) is represented by <c><![CDATA[default]]></c>.</item>
      <item>If Gt is <c><![CDATA[Gt_1 Op Gt_2]]></c>, where <c><![CDATA[Op]]></c>
       is a binary operator, then Rep(Gt) = <c><![CDATA[{op,LINE,Op,Rep(Gt_1),Rep(Gt_2)}]]></c>.</item>
      <item>If Gt is <c><![CDATA[Op Gt_0]]></c>, where <c><![CDATA[Op]]></c> is a unary operator, then
       Rep(Gt) = <c><![CDATA[{op,LINE,Op,Rep(Gt_0)}]]></c>.</item>
      <item>If Gt is <c><![CDATA[#Name{Field_1=Gt_1, ..., Field_k=Gt_k}]]></c>, then
       Rep(E) =
      <c><![CDATA[{record,LINE,Name,[{record_field,LINE,Rep(Field_1),Rep(Gt_1)}, ..., {record_field,LINE,Rep(Field_k),Rep(Gt_k)}]}]]></c>.</item>
      <item>If Gt is <c><![CDATA[#Name.Field]]></c>, then
       Rep(Gt) = <c><![CDATA[{record_index,LINE,Name,Rep(Field)}]]></c>.</item>
      <item>If Gt is <c><![CDATA[Gt_0#Name.Field]]></c>, then
       Rep(Gt) = <c><![CDATA[{record_field,LINE,Rep(Gt_0),Name,Rep(Field)}]]></c>.</item>
      <item>If Gt is <c><![CDATA[A(Gt_1, ..., Gt_k)]]></c>, where <c><![CDATA[A]]></c> is an atom, then
       Rep(Gt) = <c><![CDATA[{call,LINE,Rep(A),[Rep(Gt_1), ..., Rep(Gt_k)]}]]></c>.</item>
      <item>If Gt is <c><![CDATA[A_m:A(Gt_1, ..., Gt_k)]]></c>, where <c><![CDATA[A_m]]></c> is 
       the atom <c><![CDATA[erlang]]></c> and <c><![CDATA[A]]></c> is an atom or an operator, then
       Rep(Gt) = <c><![CDATA[{call,LINE,{remote,LINE,Rep(A_m),Rep(A)},[Rep(Gt_1), ..., Rep(Gt_k)]}]]></c>.</item>
      <item>If Gt is <c><![CDATA[{A_m,A}(Gt_1, ..., Gt_k)]]></c>, where <c><![CDATA[A_m]]></c> is 
       the atom <c><![CDATA[erlang]]></c> and <c><![CDATA[A]]></c> is an atom or an operator, then
       Rep(Gt) = <c><![CDATA[{call,LINE,Rep({A_m,A}),[Rep(Gt_1), ..., Rep(Gt_k)]}]]></c>.</item>
      <item>If Gt is <c><![CDATA[( Gt_0 )]]></c>, then
       Rep(Gt) = <c><![CDATA[Rep(Gt_0)]]></c>, that is, parenthesized
       guard tests cannot be distinguished from their bodies.</item>
    </list>
    <p>Note that every guard test has the same source form as some expression,
      and is represented the same way as the corresponding expression.</p>
  </section>

  <section>
    <title>Types</title>
    <list type="bulleted">
      <item>If T is an annotated type <c>Anno :: Type</c>,
       where <c>Anno</c> is a variable and
       <c>Type</c> is a type, then Rep(T) =
       <c>{ann_type,LINE,[Rep(Anno),Rep(Type)]}</c>.</item>
      <item>If T is an atom or integer literal L, then Rep(T) = Rep(L).
      </item>
      <item>If T is <c>L Op R</c>,
       where <c>Op</c> is a binary operator and <c>L</c> and <c>R</c>
       are types  (this is an occurrence of an expression that can be
       evaluated to an integer at compile time), then
       Rep(T) = <c>{op,LINE,Op,Rep(L),Rep(R)}</c>.</item>
      <item>If T is <c>Op A</c>, where <c>Op</c> is a
       unary operator and <c>A</c> is a type (this is an occurrence of
       an expression that can be evaluated to an integer at compile time),
       then Rep(T) = <c>{op,LINE,Op,Rep(A)}</c>.</item>
      <item>If T is a bitstring type <c>&lt;&lt;_:M,_:_*N>></c>,
       where <c>M</c> and <c>N</c> are singleton integer types, then Rep(T) =
       <c>{type,LINE,binary,[Rep(M),Rep(N)]}</c>.</item>
      <item>If T is the empty list type <c>[]</c>, then Rep(T) =
       <c>{type,Line,nil,[]}</c>.</item>
      <item>If T is a fun type <c>fun()</c>, then Rep(T) =
       <c>{type,LINE,'fun',[]}</c>.</item>
      <item>If T is a fun type <c>fun((...) -> B)</c>,
       where <c>B</c> is a type, then
       Rep(T) = <c>{type,LINE,'fun',[{type,LINE,any},Rep(B)]}</c>.
       </item>
      <item>If T is a fun type <c>fun(Ft)</c>, where
       <c>Ft</c> is a function type,
       then Rep(T) = <c>Rep(Ft)</c>.</item>
      <item>If T is an integer range type <c>L .. H</c>,
       where <c>L</c> and <c>H</c> are singleton integer types, then
       Rep(T) = <c>{type,LINE,range,[Rep(L),Rep(H)]}</c>.</item>
      <item>If T is a map type <c>map()</c>, then Rep(T) =
       <c>{type,LINE,map,any}</c>.</item>
      <item>If T is a map type <c>#{P_1, ..., P_k}</c>, where each
       <c>P_i</c> is a map pair type, then Rep(T) =
       <c>{type,LINE,map,[Rep(P_1), ..., Rep(P_k)]}</c>.</item>
      <item>If T is a map pair type <c>K => V</c>, where
       <c>K</c> and <c>V</c> are types, then Rep(T) =
       <c>{type,LINE,map_field_assoc,[Rep(K),Rep(V)]}</c>.</item>
      <item>If T is a predefined (or built-in) type <c>N(A_1, ..., A_k)</c>,
       where each <c>A_i</c> is a type, then Rep(T) =
       <c>{type,LINE,N,[Rep(A_1), ..., Rep(A_k)]}</c>.</item>
      <item>If T is a record type <c>#Name{F_1, ..., F_k}</c>,
       where each <c>F_i</c> is a record field type, then Rep(T) =
       <c>{type,LINE,record,[Rep(Name),Rep(F_1), ..., Rep(F_k)]}</c>.
       </item>
      <item>If T is a record field type <c>Name :: Type</c>,
       where <c>Type</c> is a type, then Rep(T) =
       <c>{type,LINE,field_type,[Rep(Name),Rep(Type)]}</c>.</item>
      <item>If T is a remote type <c>M:N(A_1, ..., A_k)</c>, where
       each <c>A_i</c> is a type, then Rep(T) =
       <c>{remote_type,LINE,[Rep(M),Rep(N),[Rep(A_1), ..., Rep(A_k)]]}</c>.
       </item>
      <item>If T is a tuple type <c>tuple()</c>, then Rep(T) =
       <c>{type,LINE,tuple,any}</c>.</item>
      <item>If T is a tuple type <c>{A_1, ..., A_k}</c>, where
       each <c>A_i</c> is a type, then Rep(T) =
       <c>{type,LINE,tuple,[Rep(A_1), ..., Rep(A_k)]}</c>.</item>
      <item>If T is a type union <c>T_1 | ... | T_k</c>,
       where each <c>T_i</c> is a type, then Rep(T) =
       <c>{type,LINE,union,[Rep(T_1), ..., Rep(T_k)]}</c>.</item>
      <item>If T is a type variable <c>V</c>, then Rep(T) =
       <c>{var,LINE,A}</c>, where <c>A</c> is an atom with a printname
       consisting of the same characters as <c>V</c>. A type variable
       is any variable except underscore (<c>_</c>).</item>
      <item>If T is a user-defined type <c>N(A_1, ..., A_k)</c>,
       where each <c>A_i</c> is a type, then Rep(T) =
       <c>{user_type,LINE,N,[Rep(A_1), ..., Rep(A_k)]}</c>.</item>
      <item>If T is <c>( T_0 )</c>, then Rep(T) = <c>Rep(T_0)</c>,
       that is, parenthesized types cannot be distinguished from their
       bodies.</item>
    </list>

    <section>
      <title>Function Types</title>
      <list type="bulleted">
       <item>If Ft is a constrained function type <c>Ft_1 when Fc</c>,
	where <c>Ft_1</c> is a function type and
	<c>Fc</c> is a function constraint, then Rep(T) =
	<c>{type,LINE,bounded_fun,[Rep(Ft_1),Rep(Fc)]}</c>.</item>
       <item>If Ft is a function type <c>(A_1, ..., A_n) -> B</c>,
        where each <c>A_i</c> and <c>B</c> are types, then
	Rep(Ft) = <c>{type,LINE,'fun',[{type,LINE,product,[Rep(A_1),
	..., Rep(A_n)]},Rep(B)]}</c>.</item>
      </list>
    </section>

    <section>
      <title>Function Constraints</title>
      <p>A function constraint Fc is a nonempty sequence of constraints
	<c>C_1, ..., C_k</c>, and
	Rep(Fc) = <c>[Rep(C_1), ..., Rep(C_k)]</c>.</p>
      <list type="bulleted">
       <item>If C is a constraint <c>is_subtype(V, T)</c> or <c>V :: T</c>,
        where <c>V</c> is a type variable and <c>T</c> is a type, then
        Rep(C) = <c>{type,LINE,constraint,[Rep(F),[Rep(V),Rep(T)]]}</c>.
       </item>
      </list>
    </section>
  </section>

  <section>
    <title>The Abstract Format After Preprocessing</title>
    <p>The compilation option <c><![CDATA[debug_info]]></c> can be given to the
      compiler to have the abstract code stored in 
      the <c><![CDATA[abstract_code]]></c> chunk in the BEAM file
      (for debugging purposes).</p>
    <p>In OTP R9C and later, the <c><![CDATA[abstract_code]]></c> chunk will
      contain</p>
    <p><c><![CDATA[{raw_abstract_v1,AbstractCode}]]></c></p>
    <p>where <c><![CDATA[AbstractCode]]></c> is the abstract code as described
      in this document.</p>
    <p>In releases of OTP prior to R9C, the abstract code after some more
      processing was stored in the BEAM file. The first element of the
      tuple would be either <c><![CDATA[abstract_v1]]></c> (R7B) or <c><![CDATA[abstract_v2]]></c>
      (R8B).</p>
  </section>
</chapter>