Pristine Ack-5.5
[Ack-5.5.git] / doc / pascal / hints.doc
1 .sp 1.5i
2 .nr H1 7
3 .NH
4 Hints to change the standard
5 .nh
6 .sp
7 .LP
8 We encoutered some difficulties when the compiler was developed. In this
9 chapter some hints are presented to change the standard, which would make
10 the implementation of the compiler less difficult. The semantics of Pascal
11 would not be altered by these adaptions.
12 .sp 2
13 .LP
14 \- Some minor changes in the grammar of Pascal from the user's point of view,
15 but which make the writing of an LL(1) parser considerably easier, could be:
16 .in +3m
17 .nf
18 field-list   : [ ( fixed-part [ variant-part ] | variant-part ) ] .
19 fixed-part   : record-section \fB;\fR { record-section \fB;\fR } .
20 variant-part : \fBcase\fR variant-selector \fBof\fR variant \fB;\fR { variant \fB;\fR } .
21
22 case-statement : \fBcase\fR case-index \fBof\fR case-list-element \fB;\fR { case-list-element \fB;\fR } \fBend\fR .
23 .fi
24 .in -3m
25
26
27 .LP
28 \- To ease the semantic checking on sets, the principle of qualified sets could
29 be used, every set-constructor must be preceeded by its type-identifier:
30 .nf
31 .ti +3m
32 set-constructor : type-identifier \fB[\fR [ member-designator { \fB,\fR member-designator } ] \fB]\fR .
33
34 Example:
35         t1 = set of 1..5;
36         t2 = set of integer;
37
38 The type of [3, 5] would be ambiguous, but the type of t1[3, 5] not.
39 .fi
40
41
42 .LP
43 \- Another problem arises from the fact that a function name can appear in
44 three distinct 'use' contexts: function call, assignment of function
45 result and as function parameter.
46 .br
47 Example:
48 .in +5m
49 .nf
50 \fBprogram\fR function_name;
51
52 \fBfunction\fR p(x : integer; function y : integer) : integer;
53 \fBbegin\fR .. \fBend\fR;
54
55 \fBfunction\fR f : integer;
56 \fBbegin\fR
57         f := p(f, f);     (*)
58 \fBend\fR;
59
60 \fBbegin\fR .. \fBend\fR.
61 .fi
62 .in -5m
63
64 A possible solution in case of a call (also a procedure call) would be to
65 make the (possibly empty) actual-parameter-list mandatory. The assignment
66 of the function result could be changed in a \fIreturn\fR statement.
67 Though this would change the semantics of the program slightly.
68 .br
69 The above statement (*) would look like this: return p(f(), f);
70
71
72 .LP
73 \- Another extension to the standard could be the implementation of an
74 \fIotherwise\fR clause in a case-statement. This would behave exactly like
75 the \fIdefault\fR clause in a switch-statement in C.
76 .bp